On Thu, Sep 11, 2025 at 11:02:26AM +0200, Richard Biener via Gcc wrote:
> > Does the doc need clarification on the semantics of RTL shift
> > operations when the shift amount is out of range?
> 
> The SHIFT_COUNT_TRUNCATED target macro is also relevant in
> this context.  On x86 which is a "mixed" ISA in this regard we make
> sure to recognize shifts with an (and ...) shift operand which is
> what the middle-end will add (the and) when !SHIFT_COUNT_TRUNCATED
> IIRC.

For SHIFT_COUNT_TRUNCATED targets, the shift count is certainly
modulo the bitsize, though it is fuzzy what happens when the bitsize is not
a power of two and the count is negative (whether it is treated as unsigned
modulo or something else (eventhough -27 % 24 is -3 and not 21 (24 - 3)
or 13 (-27U % 24)).
For !SHIFT_COUNT_TRUNCATED, I think we generally consider it UB even on RTL,
although it doesn't mean we can ICE on it etc., we can just punt on trying
to optimize it, but it still needs to be assembled one way or another,
the code might invoke UB but can't be proven to be always executed.

        Jakub

Reply via email to