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