On Thu, Jul 14, 2016 at 6:49 PM, Jeff Law <l...@redhat.com> wrote: > On 07/14/2016 10:12 AM, Bin Cheng wrote: >> >> Hi, >> This is a simple patch fixing ICE in tree-if-conv.c. Existing code does >> not setup a variable (cond) when predicate of basic block is true and it >> asserts on the variable. Interesting thing is dead code is not cleaned up >> before ifcvt, but that's another story. >> Bootstrap and test on x86_64. Is it OK? >> >> Thanks, >> bin >> >> 2016-07-13 Bin Cheng <bin.ch...@arm.com> >> >> PR tree-optimization/71503 >> PR tree-optimization/71683 >> * tree-if-conv.c (gen_phi_arg_condition): Set cond when predicate >> is true. > > Maybe I'm missing something, but in the case where we COND is already set > and we encounter a true predicate later, shouldn't that make the result true > as well? > > I don't think the code will though -- we just throw away the true condition. > ISTM that the right thing to do is > > if (is_true_predicate (c)) > { > cond = c; > continue; > } > > Can you see if you can trigger a case where we have an existing cond, then > later find a true condition to verify the right thing happens? Hi, Attachment is the updated patch, it breaks the loop once TRUE predicate is found. I also built spec2k6/spec2k and your case is not found. Is it OK?
Thanks, bin
diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c index e5a3372..4253d19 100644 --- a/gcc/tree-if-conv.c +++ b/gcc/tree-if-conv.c @@ -1687,7 +1687,10 @@ gen_phi_arg_condition (gphi *phi, vec<int> *occur, e = gimple_phi_arg_edge (phi, (*occur)[i]); c = bb_predicate (e->src); if (is_true_predicate (c)) - continue; + { + cond = c; + break; + } c = force_gimple_operand_gsi_1 (gsi, unshare_expr (c), is_gimple_condexpr, NULL_TREE, true, GSI_SAME_STMT); diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ifc-pr71503.c b/gcc/testsuite/gcc.dg/tree-ssa/ifc-pr71503.c new file mode 100644 index 0000000..5a90abf --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ifc-pr71503.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-Ofast" { target *-*-* } } */ + +int a, b; +unsigned long d; +void fn1() { + unsigned long *h = &d; +line1 : { + int i = 4; + for (; b; i++) { + d = ((d + 6 ?: *h) ? a : 7) && (i &= 0 >= b); + b += a; + } +} + h = 0; + for (; *h;) + goto line1; +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ifc-pr71683.c b/gcc/testsuite/gcc.dg/tree-ssa/ifc-pr71683.c new file mode 100644 index 0000000..851be37 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ifc-pr71683.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-options "-Ofast" { target *-*-* } } */ + +short unsigned int ve; + +void +u1 (void) +{ + int oq = 0; + + while (ve != 0) + { + int j4, w7 = oq; + + oq = 0 / oq; + ve %= oq; + j4 = ve ^ 1; + ve ^= oq; + if (j4 != 0 ? j4 : ve) + oq = ve; + else + if (w7 != 0) + oq = ve; + } +}