On Thu, Jul 27, 2023 at 12:00:56PM +0000, Richard Biener wrote: > The following fixes the lack of simplification of a vector shift > by an out-of-bounds shift value. For scalars this is done both > by CCP and VRP but vectors are not handled there. This results > in PR91838 differences in outcome dependent on whether a vector > shift ISA is available and thus vector lowering does or does not > expose scalar shifts here. > > The following adds a match.pd pattern to catch uniform out-of-bound > shifts, simplifying them to zero when not sanitizing shift amounts. > > Bootstrapped and tested on x86_64-unknown-linux-gnu. > > OK? > > Thanks, > Richard. > > PR tree-optimization/91838 > * match.pd (([rl]shift @0 out-of-bounds) -> zero): New pattern.
The !(flag_sanitize & SANITIZE_SHIFT_EXPONENT) should be !sanitize_flags_p (SANITIZE_SHIFT_EXPONENT) or maybe even GIMPLE || !sanitize_flags_p (SANITIZE_SHIFT_EXPONENT) because the shift ubsan instrumentation is done on GENERIC, so it can be optimized on GIMPLE even with ubsan. Otherwise LGTM. Jakub