On Mon, Feb 17, 2020 at 09:01:13AM +0100, Richard Biener wrote: > On Mon, 17 Feb 2020, Li Jia He wrote: > > This patch wants to fix PR66552 on gimple and optimizes (x shift (n mod C)) > > to (x shift (n bit_and (C - 1))) when C is a constant and power of two as > > discussed in PR66552. > > > > The regression testing for the patch was done on GCC mainline on > > > > powerpc64le-unknown-linux-gnu (Power 9 LE) > > > > with no regressions. Is it OK for GCC11 ? > > I fail to see the connection with a shift operation, can you explain?
As mentioned in the PR, the reason why we can only optimize unsigned mod C into bit_and C-1 (where C is pow2p) is that signed modulo can be negative for negative values (is non-positive). For shifts negative values would be UB and so we can assume it will not be negative (i.e. x will be either positive or a negative multiple of C) and can use bit_and then. Jakub