Hello,

On Thu, 11 Sep 2025, Richard Biener via Gcc wrote:

> > 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.
> 
> Negative shift counts would require the shift amount to be documented as
> signed in general

It would also require large changes in the backends, because all shift 
patterns for targets that don't naturally swap direction for negative 
counts (many of them!) would need runtime tests for unknown shift counts.  

I guess the fact that shift counts are unsigned isn't documented in 
rtl.texi because it once seemed obvious to everyone that signed can't 
"work sensibly" for many targets.

(Of course that doesn't preclude a target knob that specifies that 
behaviour, similar to SHIFT_COUNT_TRUNCATED)


Ciao,
Michael.

Reply via email to