diff options
author | Richard Biener <rguenther@suse.de> | 2023-05-11 14:28:11 +0200 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2023-05-12 13:48:13 +0200 |
commit | 560a3e35fe01c499bd5b1e95ddc4c3e958cf5abd (patch) | |
tree | 470ea9e8ec14c1ab1267afe5685a2ab1739fb114 | |
parent | f52bf590e3336979ee47658d74a8478e3234da9b (diff) | |
download | gcc-560a3e35fe01c499bd5b1e95ddc4c3e958cf5abd.zip gcc-560a3e35fe01c499bd5b1e95ddc4c3e958cf5abd.tar.gz gcc-560a3e35fe01c499bd5b1e95ddc4c3e958cf5abd.tar.bz2 |
tree-optimization/109791 - simplify (unsigned)&foo - (unsigned)(&foo + o)
The following adds another variant of address difference simplification.
The utility ptr_difference_const only handles constant differences
(we also cannot code generate anything else), so exposing a possible
POINTER_PLUS_EXPR in the match and computing the difference on the
base only makes it possible to handle one case of a variable offset.
This simplifies
(unsigned long) &MEM <char[3]> [(void *)&str + 2B] - (unsigned long) (&str + (_69 + 1))
down to (1 - (unsigned long) _69) during niter analysis, allowing
ranger to eliminate a condition later and avoiding a bogus
-Wstringop-overflow diagnostic for the testcase in the PR.
PR tree-optimization/109791
* match.pd (minus (convert ADDR_EXPR@0) (convert (pointer_plus @1 @2))):
New pattern.
(minus (convert (pointer_plus @1 @2)) (convert ADDR_EXPR@0)):
Likewise.
-rw-r--r-- | gcc/match.pd | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/gcc/match.pd b/gcc/match.pd index b7f28ab..2e46e07 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2573,6 +2573,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* Try folding difference of addresses. */ (simplify + (minus (convert ADDR_EXPR@0) (convert (pointer_plus @1 @2))) + (if (tree_nop_conversion_p (type, TREE_TYPE (@0))) + (with { poly_int64 diff; } + (if (ptr_difference_const (@0, @1, &diff)) + (minus { build_int_cst_type (type, diff); } (convert @2)))))) +(simplify + (minus (convert (pointer_plus @0 @2)) (convert ADDR_EXPR@1)) + (if (tree_nop_conversion_p (type, TREE_TYPE (@0))) + (with { poly_int64 diff; } + (if (ptr_difference_const (@0, @1, &diff)) + (plus (convert @2) { build_int_cst_type (type, diff); }))))) +(simplify (minus (convert ADDR_EXPR@0) (convert @1)) (if (tree_nop_conversion_p (type, TREE_TYPE (@0))) (with { poly_int64 diff; } |