[PATCH] Fix A < 0 ? C : 0 optimization (PR tree-optimization/78720)

Marc Glisse marc.glisse@inria.fr
Fri Dec 9 23:04:00 GMT 2016


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.

-- 
Marc Glisse



More information about the Gcc-patches mailing list