You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When casting from an unsigned type to a signed type (e.g. col[0] as i32 where col[0] is u8), the MLIR generator correctly uses zero-extend (arith.extui) but incorrectly marks the result SSA value as unsigned. This propagates through all downstream operations, making >> use arith.shrui (logical shift) instead of arith.shrsi (arithmetic shift).
Reproduction
let col: ptr<u8> = ...
let topdelta: i32 = col[0] as i32
let topscreen: i32 = -2071019
let yl: i32 = (topscreen + 65536 - 1) >> 16
# yl should be -31 (ashr) but MLIR produces 65505 (lshr)
Generated LLVM IR:
%29 = lshri32%27, %28; should be ashr
Root cause
In _emit_cast(), the integer widening path adds the result SSA to _ssa_unsigned whenever the source is unsigned, regardless of whether the target type is signed:
ifunsigned:
self._ssa_unsigned.add(cast_name) # wrong when to_type is signed
Fix
Only propagate unsigned-ness when the target type itself is unsigned:
The same fix applies to the truncation path below it.
Impact
Any code that casts a u8 to i32 and then right-shifts a negative value gets the wrong result. In doom-flow this caused sprite column y-coordinates to be off by ~65536 pixels, producing transient rendering mismatches during AI gameplay.
Activity