aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAndrew Pinski <apinski@marvell.com>2023-05-04 23:37:51 +0000
committerAndrew Pinski <apinski@marvell.com>2023-05-05 05:22:23 +0000
commit6fe385eac6ff8ecddb6cbdff2c706b27b5137006 (patch)
tree8253c1d99b449b61b273c06ef9a08733074aacb1 /gcc
parent6f18f344338b370031e75924eed2bdd1ce5c8dba (diff)
downloadgcc-6fe385eac6ff8ecddb6cbdff2c706b27b5137006.zip
gcc-6fe385eac6ff8ecddb6cbdff2c706b27b5137006.tar.gz
gcc-6fe385eac6ff8ecddb6cbdff2c706b27b5137006.tar.bz2
MATCH: Add ABSU<a> == 0 to a == 0 simplification
There is already an `ABS<a> == 0` to `a == 0` pattern, this just extends that to ABSU too. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/109722 gcc/ChangeLog: * match.pd: Extend the `ABS<a> == 0` pattern to cover `ABSU<a> == 0` too. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/abs-1.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/match.pd11
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/abs-1.c12
2 files changed, 18 insertions, 5 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index 08a4f8e..ceae1c3 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -5807,11 +5807,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(if (tem && !TREE_OVERFLOW (tem))
(scmp @0 { tem; }))))))
-/* Convert ABS_EXPR<x> == 0 or ABS_EXPR<x> != 0 to x == 0 or x != 0. */
-(for op (eq ne)
- (simplify
- (op (abs @0) zerop@1)
- (op @0 @1)))
+/* Convert ABS[U]_EXPR<x> == 0 or ABS[U]_EXPR<x> != 0 to x == 0 or x != 0. */
+(for op (abs absu)
+ (for eqne (eq ne)
+ (simplify
+ (eqne (op @0) zerop@1)
+ (eqne @0 { build_zero_cst (TREE_TYPE (@0)); }))))
/* From fold_sign_changed_comparison and fold_widened_comparison.
FIXME: the lack of symmetry is disturbing. */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/abs-1.c b/gcc/testsuite/gcc.dg/tree-ssa/abs-1.c
new file mode 100644
index 0000000..ce40411
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/abs-1.c
@@ -0,0 +1,12 @@
+/* PR tree-optimization/109722 */
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-gimple -fdump-tree-optimized" } */
+
+int g(signed char x){
+ x = x < 0 ? -x : x;
+ return x == 0;
+}
+
+/* This should work even if int is 16bits. */
+/* { dg-final { scan-tree-dump "ABSU_EXPR" "gimple"} } */
+/* { dg-final { scan-tree-dump-not "ABSU_EXPR" "optimized"} } */