re PR middle-end/30433 (no longer folding __complex__(0.0, 1.0) == __complex__(1...
authorAndrew Pinski <andrew_pinski@playstation.sony.com>
Fri, 16 Feb 2007 01:27:42 +0000 (01:27 +0000)
committerAndrew Pinski <pinskia@gcc.gnu.org>
Fri, 16 Feb 2007 01:27:42 +0000 (17:27 -0800)
2007-02-15  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR middle-end/30433
        * fold-const.c (fold_comparison): Add back the
        folding of constant complex comparisions.
2007-02-15  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR middle-end/30433
        * gcc.c-torture/compile/pr30433.c: New testcase to check
        that complex constants comparisions are foldded.

From-SVN: r122029

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr30433.c [new file with mode: 0644]

index 152407b26c53bf50a6810db6e4e76eba2e59c34a..aac9a3e3610ddbe9f5b31d642a59d0446801f2fe 100644 (file)
@@ -1,3 +1,9 @@
+2007-02-15  Andrew Pinski  <andrew_pinski@playstation.sony.com>
+
+       PR middle-end/30433
+       * fold-const.c (fold_comparison): Add back the
+       folding of constant complex comparisions.
+
 2007-02-15  Andrew Pinski  <andrew_pinski@playstation.sony.com>
 
        PR middle-end/30729
index 0aca93c386afd0f5240662baaf790aa1201391c0..3c8636e8fc3a6e35003577dcd67a8d0bfd29143b 100644 (file)
@@ -8852,6 +8852,29 @@ fold_comparison (enum tree_code code, tree type, tree op0, tree op1)
        }
     }
 
+  /* If this is a comparison of complex values and both sides
+     are COMPLEX_CST, do the comparision by parts to fold the
+     comparision.  */
+  if ((code == EQ_EXPR || code == NE_EXPR)
+      && TREE_CODE (TREE_TYPE (arg0)) == COMPLEX_TYPE
+      && TREE_CODE (arg0) == COMPLEX_CST
+      && TREE_CODE (arg1) == COMPLEX_CST)
+    {
+      tree real0, imag0, real1, imag1;
+      enum tree_code outercode;
+
+      real0 = TREE_REALPART (arg0);
+      imag0 = TREE_IMAGPART (arg0);
+      real1 = TREE_REALPART (arg1);
+      imag1 = TREE_IMAGPART (arg1);
+      outercode = code == EQ_EXPR ? TRUTH_ANDIF_EXPR : TRUTH_ORIF_EXPR;
+
+      return fold_build2 (outercode, type,
+                         fold_build2 (code, type, real0, real1),
+                         fold_build2 (code, type, imag0, imag1));
+    }
+
+
   /* Fold a comparison of the address of COMPONENT_REFs with the same
      type and component to a comparison of the address of the base
      object.  In short, &x->a OP &y->a to x OP y and
index c0fc66a9f32ba4541de846bcd0032b1fa12779a9..e05d167bfe9184b860f504868604bdcaa88e87e0 100644 (file)
@@ -1,3 +1,9 @@
+2007-02-15  Andrew Pinski  <andrew_pinski@playstation.sony.com>
+
+       PR middle-end/30433
+       * gcc.c-torture/compile/pr30433.c: New testcase to check
+       that complex constants comparisions are foldded.
+
 2007-02-15  Andrew Pinski  <andrew_pinski@playstation.sony.com>
 
        PR C++/30158
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr30433.c b/gcc/testsuite/gcc.c-torture/compile/pr30433.c
new file mode 100644 (file)
index 0000000..1f0edd0
--- /dev/null
@@ -0,0 +1,2 @@
+int f = (_Complex float)(0.5) == 0.5;
+