diff --git a/gcc/testsuite/gcc.c-torture/compile/pr108783.c b/gcc/testsuite/gcc.c-torture/compile/pr108783.c new file mode 100644 index 00000000000..eae87db36d7 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr108783.c @@ -0,0 +1,42 @@ +/* PR tree-optimization/108783 */ + +__attribute__((returns_twice)) int baz (int, int); + +int +bar (int x) +{ + return x; +} + +int +foo (int x, int y) +{ + int a; + + a = bar (x); + baz (x, y); + + return y && a && a; +} + +int +qux (int x, int y) +{ + int a; + + a = bar (x); + baz (x, y); + + return y && a != 42 && a >= 42; +} + +int +corge (int x, int y) +{ + int a; + + a = bar (x); + baz (x, y); + + return y || a == 42 || a > 42; +} diff --git a/gcc/tree-ssa-reassoc.cc b/gcc/tree-ssa-reassoc.cc index 5522a3ada8e..f163612f140 100644 --- a/gcc/tree-ssa-reassoc.cc +++ b/gcc/tree-ssa-reassoc.cc @@ -2272,6 +2272,15 @@ eliminate_redundant_comparison (enum tree_code opcode, STRIP_USELESS_TYPE_CONVERSION (newop2); if (!is_gimple_val (newop1) || !is_gimple_val (newop2)) continue; + if (lcode == TREE_CODE (t) + && operand_equal_p (op1, newop1, 0) + && operand_equal_p (op2, newop2, 0)) + t = curr->op; + else if ((TREE_CODE (newop1) == SSA_NAME + && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (newop1)) + || (TREE_CODE (newop2) == SSA_NAME + && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (newop2))) + continue; } if (dump_file && (dump_flags & TDF_DETAILS))