diff options
author | Feng Xue <fxue@os.amperecomputing.com> | 2020-06-01 11:57:35 +0800 |
---|---|---|
committer | Feng Xue <fxue@os.amperecomputing.com> | 2020-08-19 22:29:45 +0800 |
commit | 459f6f68a75fe88e7c8309ca8ad3244a532b0d8e (patch) | |
tree | fc36d4822d9d4058a653fa7eeea7f1af3148e9b8 | |
parent | 1e235788bbfc41f3eec1bb665d8e4bb2c63a1982 (diff) | |
download | gcc-459f6f68a75fe88e7c8309ca8ad3244a532b0d8e.zip gcc-459f6f68a75fe88e7c8309ca8ad3244a532b0d8e.tar.gz gcc-459f6f68a75fe88e7c8309ca8ad3244a532b0d8e.tar.bz2 |
tree-optimization/94234 - add pattern for ptr-diff on addresses with same offset
2020-08-19 Feng Xue <fxue@os.amperecomputing.com>
gcc/
PR tree-optimization/94234
* match.pd ((PTR_A + OFF) - (PTR_B + OFF)) -> (PTR_A - PTR_B): New
simplification.
gcc/testsuite/
PR tree-optimization/94234
* gcc.dg/pr94234-1.c: New test.
-rw-r--r-- | gcc/match.pd | 3 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr94234-1.c | 15 |
2 files changed, 18 insertions, 0 deletions
diff --git a/gcc/match.pd b/gcc/match.pd index c3b8816..2cffcae 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2550,6 +2550,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && tree_int_cst_sign_bit (@2) == 0)) (minus (convert @1) (convert @2))))) (simplify + (pointer_diff (pointer_plus @0 @2) (pointer_plus @1 @2)) + (pointer_diff @0 @1)) + (simplify (pointer_diff (pointer_plus @@0 @1) (pointer_plus @0 @2)) /* The second argument of pointer_plus must be interpreted as signed, and thus sign-extended if necessary. */ diff --git a/gcc/testsuite/gcc.dg/pr94234-1.c b/gcc/testsuite/gcc.dg/pr94234-1.c new file mode 100644 index 0000000..d85563b --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr94234-1.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-forwprop1" } */ + +typedef __INTPTR_TYPE__ ssize_t; +typedef __PTRDIFF_TYPE__ ptrdiff_t; + +ptrdiff_t foo (char *a, ssize_t n, ssize_t m) +{ + char *b1 = a + 8 * n; + char *b2 = a + 8 * (n + 1); + + return (b1 + m) - (b2 + m); +} + +/* { dg-final { scan-tree-dump-times "return -8;" 1 "forwprop1" } } */ |