diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-05-08 09:35:41 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2020-05-08 09:35:41 +0200 |
commit | a0d732eea2e152fc51f7c5249abaa9ef56fc5121 (patch) | |
tree | 7d2fb107ac7cbf4d72a6934db371dc075494caf5 /gcc/testsuite/gcc.dg | |
parent | df569f7da567af4996821dc0a1871eec79957d04 (diff) | |
download | gcc-a0d732eea2e152fc51f7c5249abaa9ef56fc5121.zip gcc-a0d732eea2e152fc51f7c5249abaa9ef56fc5121.tar.gz gcc-a0d732eea2e152fc51f7c5249abaa9ef56fc5121.tar.bz2 |
match.pd: Canonicalize (X + (X >> (prec - 1))) ^ (X >> (prec - 1)) to abs (X) [PR94783]
The following patch canonicalizes M = X >> (prec - 1); (X + M) ^ M
for signed integral types into ABS_EXPR (X). For X == min it is already
UB because M is -1 and min + -1 is UB, so we can use ABS_EXPR rather than
say ABSU_EXPR + cast.
The backend might then emit the abs code back using the shift and addition
and xor if it is the best sequence for the target, but could do something
different that is better.
2020-05-08 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/94783
* match.pd ((X + (X >> (prec - 1))) ^ (X >> (prec - 1)) to abs (X)):
New simplification.
* gcc.dg/tree-ssa/pr94783.c: New test.
Diffstat (limited to 'gcc/testsuite/gcc.dg')
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/pr94783.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr94783.c b/gcc/testsuite/gcc.dg/tree-ssa/pr94783.c new file mode 100644 index 0000000..c52f657 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr94783.c @@ -0,0 +1,12 @@ +/* PR tree-optimization/94783 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* { dg-final { scan-tree-dump "ABS_EXPR" "optimized" } } */ +/* { dg-final { scan-tree-dump-not " >> 31" "optimized" } } */ + +int +foo (int v) +{ + int mask = v >> (__SIZEOF_INT__ * __CHAR_BIT__ - 1); + return (v + mask) ^ mask; +} |