public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/110838 - less aggressively fold out-of-bound shifts
@ 2023-08-04 10:15 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-08-04 10:15 UTC (permalink / raw)
  To: gcc-patches

The following adjusts the shift simplification patterns to avoid
touching out-of-bound shift value arithmetic right shifts of
possibly negative values.  While simplifying those to zero isn't
wrong it's violating the principle of least surprise.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/110838
	* match.pd (([rl]shift @0 out-of-bounds) -> zero): Restrict
	the arithmetic right-shift case to non-negative operands.
---
 gcc/match.pd | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index 53e622bf28f..a1a82a5f954 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1064,6 +1064,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (simplify
   (shift @0 uniform_integer_cst_p@1)
   (if ((GIMPLE || !sanitize_flags_p (SANITIZE_SHIFT_EXPONENT))
+       /* Leave arithmetic right shifts of possibly negative values alone.  */
+       && (TYPE_UNSIGNED (type)
+           || shift == LSHIFT_EXPR
+	   || tree_expr_nonnegative_p (@0))
        /* Use a signed compare to leave negative shift counts alone.  */
        && wi::ges_p (wi::to_wide (uniform_integer_cst_p (@1)),
 		     element_precision (type)))
-- 
2.35.3

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-04 10:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-04 10:15 [PATCH] tree-optimization/110838 - less aggressively fold out-of-bound shifts Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).