]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR middle-end/84834 (ICE: tree check: expected integer_cst, have complex...
authorJakub Jelinek <jakub@redhat.com>
Fri, 22 Jun 2018 20:38:25 +0000 (22:38 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 22 Jun 2018 20:38:25 +0000 (22:38 +0200)
Backported from mainline
2018-03-13  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/84834
* match.pd ((A & C) != 0 ? D : 0): Use INTEGER_CST@2 instead of
integer_pow2p@2 and test integer_pow2p in condition.
(A < 0 ? C : 0): Similarly for @1.

* gcc.dg/pr84834.c: New test.

From-SVN: r261921

gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr84834.c [new file with mode: 0644]

index f8789d2668313a989bf01f9edb06a159f084067c..841815df05acacda50c6391681bd2f241aa0f9da 100644 (file)
@@ -3,6 +3,11 @@
        Backported from mainline
        2018-03-13  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/84834
+       * match.pd ((A & C) != 0 ? D : 0): Use INTEGER_CST@2 instead of
+       integer_pow2p@2 and test integer_pow2p in condition.
+       (A < 0 ? C : 0): Similarly for @1.
+
        PR target/84827
        * config/i386/i386.md (round<mode>2): For 387 fancy math, disable
        pattern if -ftrapping-math -fno-fp-int-builtin-inexact.
index 100e188ea2c9ca6ede73a2cfc5c1718ad976baa8..3a44ea7f628abeebcdda15dd605b21eff125f210 100644 (file)
@@ -2789,15 +2789,17 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 (simplify
  (cond
   (ne (bit_and @0 integer_pow2p@1) integer_zerop)
-  integer_pow2p@2 integer_zerop)
- (with {
-    int shift = wi::exact_log2 (@2) - wi::exact_log2 (@1);
-  }
-  (if (shift > 0)
-   (bit_and
-    (lshift (convert @0) { build_int_cst (integer_type_node, shift); }) @2)
-   (bit_and
-    (convert (rshift @0 { build_int_cst (integer_type_node, -shift); })) @2))))
+  INTEGER_CST@2 integer_zerop)
+ (if (integer_pow2p (@2))
+  (with {
+     int shift = wi::exact_log2 (@2) - wi::exact_log2 (@1);
+   }
+   (if (shift > 0)
+    (bit_and
+     (lshift (convert @0) { build_int_cst (integer_type_node, shift); }) @2)
+    (bit_and
+     (convert (rshift @0 { build_int_cst (integer_type_node, -shift); }))
+     @2)))))
 
 /* If we have (A & C) != 0 where C is the sign bit of A, convert
    this into A < 0.  Similarly for (A & C) == 0 into A >= 0.  */
@@ -2818,8 +2820,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 (simplify
  (cond
   (lt @0 integer_zerop)
-  integer_pow2p@1 integer_zerop)
- (if (!TYPE_UNSIGNED (TREE_TYPE (@0)))
+  INTEGER_CST@1 integer_zerop)
+ (if (integer_pow2p (@1)
+      && !TYPE_UNSIGNED (TREE_TYPE (@0)))
   (with {
     int shift = element_precision (@0) - wi::exact_log2 (@1) - 1;
    }
index b4e4fec70fb43d20af4cba9353fc1cd3e5308658..98fa2654761f07fd063e7467f08d3bf9abacc88f 100644 (file)
@@ -3,6 +3,9 @@
        Backported from mainline
        2018-03-13  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/84834
+       * gcc.dg/pr84834.c: New test.
+
        PR target/84827
        * gcc.target/i386/pr84827.c: New test.
 
diff --git a/gcc/testsuite/gcc.dg/pr84834.c b/gcc/testsuite/gcc.dg/pr84834.c
new file mode 100644 (file)
index 0000000..38c056b
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR middle-end/84834 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+_Complex int
+foo (int a)
+{
+  return a < 0;
+}
+
+_Complex int
+bar (int a)
+{
+  return (a & 8) ? (_Complex int) 16 : (_Complex int) 0;
+}