On Sat, Dec 10, 2016 at 12:04:25AM +0100, Marc Glisse wrote: > On Fri, 9 Dec 2016, Jakub Jelinek wrote: > > >This patch fixes the recently added A < 0 ? C : 0 for power of 2 C > >optimization. The if (!TYPE_UNSIGNED (TREE_TYPE (@0))) part is just > >for safety, I'd hope that unsigned < 0 is folded into 0 earlier, but just > >in case this is handled first. > > > >The issue which breaks the testcase is that the patch actually assumed > >that C has type narrower or as wide as A, which generally doesn't have to be > >the case. If the type of C is narrower or as wide as A's type, then the > >shift count is necessarily non-negative, but if A is narrower than C, we > >might need a left shift instead of right shift (and in that case have to > >convert A to C's type first, then left shift so that the MSB of A is moved > >to the right position and finally and it. > > Do you ever actually need a left shift? The conversion is a sign extension > in that case (you require that A is signed), so it already has the > appropriate 1 or 0 in the right place.
That is true. In the end for backends that have costly sign extension or perform sign extension by shifting up and down again the left shift after zero extension might be faster, but that is too early to guess at this point, probably it should be something optimized in simplify-rtx.c or backends if needed. So yeah, is the patch ok with the left shift removed instead? I'll regtest it again tomorrow^H^H^H^H^H^H^H^Hlater today. Jakub