This adds a simple match pattern for this case.
I noticed it a couple of different places.
One while I was looking at code generation of a parser and
also while I was looking at locations where bitwise_inverted_equal_p
should be used more.
Committed as approved after bootstrapped and tested on x86_64-linux-gnu with no regressions.
PR tree-optimization/110937
PR tree-optimization/100798
gcc/ChangeLog:
* match.pd (`a ? ~b : b`): Handle this
case.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/bool-14.c: New test.
* gcc.dg/tree-ssa/bool-15.c: New test.
* gcc.dg/tree-ssa/phi-opt-33.c: New test.
* gcc.dg/tree-ssa/
20030709-2.c: Update testcase
so `a ? -1 : 0` is not used to hit the match
pattern.
(if (cmp == NE_EXPR)
{ constant_boolean_node (true, type); })))))))
+#if GIMPLE
+/* a?~t:t -> (-(a))^t */
+(simplify
+ (cond @0 @1 @2)
+ (if (INTEGRAL_TYPE_P (type)
+ && bitwise_inverted_equal_p (@1, @2))
+ (with {
+ auto prec = TYPE_PRECISION (type);
+ auto unsign = TYPE_UNSIGNED (type);
+ tree inttype = build_nonstandard_integer_type (prec, unsign);
+ }
+ (convert (bit_xor (negate (convert:inttype @0)) (convert:inttype @2))))))
+#endif
+
/* Simplify pointer equality compares using PTA. */
(for neeq (ne eq)
(simplify
};
int make_decl_rtl (tree, int);
void *
-get_alias_set (t)
+get_alias_set (t, t1)
tree t;
+ void *t1;
{
long set;
if (t->decl.rtl)
return (t->decl.rtl->fld[1].rtmem
? 0
: (((t->decl.rtl ? t->decl.rtl: (make_decl_rtl (t, 0), t->decl.rtl)))->fld[1]).rtmem);
- return (void*)-1;
+ return t1;
}
/* There should be precisely one load of ->decl.rtl. If there is
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized-raw" } */
+/* PR tree-optimization/110937 */
+
+_Bool f2(_Bool a, _Bool b)
+{
+ if (a)
+ return !b;
+ return b;
+}
+
+/* We should be able to remove the conditional and convert it to an xor. */
+/* { dg-final { scan-tree-dump-not "gimple_cond " "optimized" } } */
+/* { dg-final { scan-tree-dump-not "gimple_phi " "optimized" } } */
+/* { dg-final { scan-tree-dump-times "bit_xor_expr, " 1 "optimized" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized-raw" } */
+/* PR tree-optimization/110937 */
+
+_Bool f2(int x, int y, int w, int z)
+{
+ _Bool a = x == y;
+ _Bool b = w == z;
+ if (a)
+ return !b;
+ return b;
+}
+
+/* We should be able to remove the conditional and convert it to an xor. */
+/* { dg-final { scan-tree-dump-not "gimple_cond " "optimized" } } */
+/* { dg-final { scan-tree-dump-not "gimple_phi " "optimized" } } */
+/* { dg-final { scan-tree-dump-not "ne_expr, " "optimized" } } */
+/* { dg-final { scan-tree-dump-times "bit_xor_expr, " 1 "optimized" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized-raw" } */
+/* PR tree-optimization/100798 */
+
+int f(int a, int t)
+{
+ return (a=='s' ? ~t : t);
+}
+
+/* This should be convert into t^-(a=='s'). */
+/* { dg-final { scan-tree-dump-times "bit_xor_expr, " 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "negate_expr, " 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-not "bit_not_expr, " "optimized" } } */