aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-pass.h
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2025-01-09 08:30:12 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2025-01-09 08:30:12 +0100
commit2cbd4409bcfaba2bd4200412090fd06db1948369 (patch)
treef82deebf61348a86dd5ceb72e29485f7b2f1b8f8 /gcc/tree-pass.h
parentc5e71d22d632889860ef079d4b0bff21eef8a660 (diff)
downloadgcc-2cbd4409bcfaba2bd4200412090fd06db1948369.zip
gcc-2cbd4409bcfaba2bd4200412090fd06db1948369.tar.gz
gcc-2cbd4409bcfaba2bd4200412090fd06db1948369.tar.bz2
match.pd: Avoid introducing UB in the a r<< (32-b) -> a r>> b optimization [PR117927]
As mentioned in the PR, the a r<< (bitsize-b) to a r>> b and similar match.pd optimization which has been introduced in GCC 15 can introduce UB which wasn't there before, in particular if b is equal at runtime to bitsize, then a r<< 0 is turned into a r>> bitsize. The following patch fixes it by optimizing it early only if VRP tells us the count isn't equal to the bitsize, and late into a r>> (b & (bitsize - 1)) if bitsize is power of two and the subtraction has single use, on various targets the masking then goes away because its rotate instructions do masking already. The latter can't be done too early though, because then the expr_not_equal_to case is basically useless and we introduce the masking always and can't find out anymore that there was originally no masking. Even cfun->after_inlining check would be too early, there is forwprop before vrp, so the patch introduces a new PROP for the start of the last forwprop pass. 2025-01-09 Jakub Jelinek <jakub@redhat.com> Andrew Pinski <quic_apinski@quicinc.com> PR tree-optimization/117927 * tree-pass.h (PROP_last_full_fold): Define. * passes.def: Add last= parameters to pass_forwprop. * tree-ssa-forwprop.cc (pass_forwprop): Add last_p non-static data member and initialize it in the ctor. (pass_forwprop::set_pass_param): New method. (pass_forwprop::execute): Set PROP_last_full_fold in curr_properties at the start if last_p. * match.pd (a rrotate (32-b) -> a lrotate b): Only optimize either if @2 is known not to be equal to prec or if during/after last forwprop the subtraction has single use and prec is power of two; in that case transform it into orotate by masked count. * gcc.dg/tree-ssa/pr117927.c: New test.
Diffstat (limited to 'gcc/tree-pass.h')
-rw-r--r--gcc/tree-pass.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h
index e764dc9..d46a6b1 100644
--- a/gcc/tree-pass.h
+++ b/gcc/tree-pass.h
@@ -230,6 +230,7 @@ protected:
#define PROP_assumptions_done (1 << 19) /* Assume function kept
around. */
#define PROP_gimple_lbitint (1 << 20) /* lowered large _BitInt */
+#define PROP_last_full_fold (1 << 21) /* Start of last forwprop. */
#define PROP_gimple \
(PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh | PROP_gimple_lomp)