This fixes PR60849 by properly rejecting non-boolean typed
comparisons from valid_gimple_rhs_p so they go through the
gimplification paths.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2014-04-16  Richard Biener  <rguent...@suse.de>

        PR middle-end/60849
        * tree-ssa-propagate.c (valid_gimple_rhs_p): Only allow effective
        boolean results for comparisons.

        * g++.dg/opt/pr60849.C: New testcase.

Index: gcc/tree-ssa-propagate.c
===================================================================
--- gcc/tree-ssa-propagate.c    (revision 209423)
+++ gcc/tree-ssa-propagate.c    (working copy)
@@ -571,8 +571,14 @@ valid_gimple_rhs_p (tree expr)
       /* All constants are ok.  */
       break;
 
-    case tcc_binary:
     case tcc_comparison:
+      if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
+         || (TREE_CODE (TREE_TYPE (expr)) != BOOLEAN_TYPE
+             && TYPE_PRECISION (TREE_TYPE (expr)) != 1))
+       return false;
+
+      /* Fallthru.  */
+    case tcc_binary:
       if (!is_gimple_val (TREE_OPERAND (expr, 0))
          || !is_gimple_val (TREE_OPERAND (expr, 1)))
        return false;
Index: gcc/testsuite/g++.dg/opt/pr60849.C
===================================================================
--- gcc/testsuite/g++.dg/opt/pr60849.C  (revision 0)
+++ gcc/testsuite/g++.dg/opt/pr60849.C  (working copy)
@@ -0,0 +1,13 @@
+// { dg-do compile }
+// { dg-options "-O2" }
+
+int g;
+
+extern "C" int isnan ();
+
+void foo(float a) {
+  int (*xx)(...);
+  xx = isnan;
+  if (xx(a))
+    g++;
+}

Reply via email to