Like
r15-5063-g6e84a41622f56c, but this is for the `a != 0` case.
After adding vn_valueize to the handle the `a ==/!= 0` case
of insert_predicates_for_cond, it would go into an infinite loop
as the Value number for a could be the same as what it
is for the whole expression. This avoids that recursion so there is
no infinite loop here.
Note lim was introducing `bool_var2 = bool_var1 != 0` originally but
with the gimple testcase in -2, there is no dependency on what passes
before hand will do.
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/117859
gcc/ChangeLog:
* tree-ssa-sccvn.cc (insert_predicates_for_cond): If the
valueization for the new lhs for `lhs != 0`
is the same as the old ones, don't recurse.
gcc/testsuite/ChangeLog:
* gcc.dg/torture/pr117859-1.c: New test.
* gcc.dg/torture/pr117859-2.c: New test.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-ssa-phiopt -fno-expensive-optimizations" } */
+
+/* PR tree-optimization/117859 */
+
+unsigned char a;
+int b, c, d, e, g, h, j, k;
+struct {
+ int f : 1;
+} i;
+char l(int m) { return a > 255 >> m ? 0 : m; }
+int main() {
+ if (i.f)
+ d = b;
+ k = e = 1;
+ for (; e; e--)
+ g = 0;
+ h = g ? 1 << g : 1;
+ c = h || i.f;
+ while (b)
+ j = l(k && i.f);
+ return 0;
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fgimple" } */
+
+/* PR tree-optimization/117859 */
+
+void __GIMPLE (ssa,startwith("pre"))
+m (int p, int b)
+{
+ int _6;
+ _Bool _48;
+ _Bool _50;
+ int _57;
+ _Bool _59;
+
+ __BB(2):
+ _6 = 0; // This needs to be prop'ed to make _48 unconditional
+ if (_6 != 0)
+ goto __BB5;
+ else
+ goto __BB14;
+
+ __BB(14):
+ _48 = p_2(D) != 0;
+ goto __BB7;
+
+ __BB(5):
+ goto __BB7;
+
+ __BB(7):
+ _59 = __PHI (__BB5: _Literal (_Bool) 1, __BB14: _48);
+ if (b_36(D) != 0)
+ goto __BB8;
+ else
+ goto __BB13;
+
+ __BB(8):
+ _50 = _59 != _Literal (_Bool) 0; // Important being != 0
+ _57 = _50 ? 1 : 0; // can be unused but need around for _50 being used
+ goto __BB9;
+
+ __BB(9,loop_header(2)):
+ if (_59 != _Literal (_Bool) 0)
+ goto __BB13;
+ else
+ goto __BB9;
+
+ __BB(13):
+ return;
+
+
+}
edge nf = false_e;
if (code == EQ_EXPR)
std::swap (nt, nf);
- insert_predicates_for_cond (nc, nlhs, nrhs, nt, nf);
+ if (lhs != nlhs)
+ insert_predicates_for_cond (nc, nlhs, nrhs, nt, nf);
}
/* (a | b) == 0 ->
on true edge assert: a == 0 & b == 0. */