aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2023-06-16 08:55:12 +0200
committerRichard Biener <rguenther@suse.de>2023-06-16 10:26:14 +0200
commit827e208fa64771f15fc8e53970a2297e637277b5 (patch)
tree0b21eeff8d82466010cefc5269f280e4a71b1074
parent0f732ff7c4724e3317ce64feb757d5112c6e1f94 (diff)
downloadgcc-827e208fa64771f15fc8e53970a2297e637277b5.zip
gcc-827e208fa64771f15fc8e53970a2297e637277b5.tar.gz
gcc-827e208fa64771f15fc8e53970a2297e637277b5.tar.bz2
tree-optimization/110269 - restore missed condition folding
The following makes sure we optimize x != 0 using range info via tree_expr_nonzero_p via match.pd. PR tree-optimization/110269 * fold-const.cc (fold_binary_loc): Merge x != 0 folding with tree_expr_nonzero_p ... * match.pd (cmp (convert? addr@0) integer_zerop): With this pattern. * gcc.dg/tree-ssa/pr110269.c: New testcase.
-rw-r--r--gcc/fold-const.cc7
-rw-r--r--gcc/match.pd4
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr110269.c34
3 files changed, 36 insertions, 9 deletions
diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 9ea055d..3aa6851 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -12298,13 +12298,6 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
tem, build_int_cst (TREE_TYPE (tem), 0));
}
- if (integer_zerop (arg1)
- && tree_expr_nonzero_p (arg0))
- {
- tree res = constant_boolean_node (code==NE_EXPR, type);
- return omit_one_operand_loc (loc, type, res, arg0);
- }
-
if (TREE_CODE (arg0) == BIT_XOR_EXPR
&& TREE_CODE (arg1) == BIT_XOR_EXPR)
{
diff --git a/gcc/match.pd b/gcc/match.pd
index a17d683..b7baad6 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6120,8 +6120,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(cmp @0 (bit_xor @1 (convert @2)))))
(simplify
- (cmp (convert? addr@0) integer_zerop)
- (if (tree_single_nonzero_warnv_p (@0, NULL))
+ (cmp (nop_convert? @0) integer_zerop)
+ (if (tree_expr_nonzero_p (@0))
{ constant_boolean_node (cmp == NE_EXPR, type); }))
/* (X & C) op (Y & C) into (X ^ Y) & C op 0. */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr110269.c b/gcc/testsuite/gcc.dg/tree-ssa/pr110269.c
new file mode 100644
index 0000000..c68a6f9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr110269.c
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ccp2 -fdump-tree-optimized" } */
+
+void foo(void);
+static int a = 1, c;
+static int *b = &a;
+static int **d = &b;
+static int ***e = &d;
+void __assert_fail() __attribute__((__noreturn__));
+static int f() {
+ if (a) return a;
+ for (; c;) *e = 0;
+ if (b) __assert_fail();
+ return 6;
+}
+int main() {
+ if (f()) {
+ *d = 0;
+ if (b == 0)
+ ;
+ else {
+ __builtin_unreachable();
+ __assert_fail();
+ }
+ }
+ if (b == 0)
+ ;
+ else
+ foo();
+ ;
+}
+
+/* { dg-final { scan-tree-dump-times "Folding predicate" 2 "ccp2" } } */
+/* { dg-final { scan-tree-dump-not "foo" "optimized" } } */