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.
(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. */
(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;
}
--- /dev/null
+/* 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;
+}