AnyDSL / MimIR

MimIR is my Intermediate Representation
https://anydsl.github.io/MimIR/
MIT License
46 stars 9 forks source link

`%core.wrap.sub nuw (a, 1:(.Idx n))` incorrectly normalizes to `%core.wrap.add nuw (a, n - 1)` #253

Closed fodinabor closed 10 months ago

fodinabor commented 11 months ago

Having %core.wrap.sub %core.mode.nuw (offset, %core.conv.u size 1:%core.I64); in the code, Thorin normalizes this to an addition with the value size - 1. E.g. with size being 1024, this is normalized to %core.wrap.add 1024 2 (1023:(.Idx 1024), offset_123465);. Since this makes explicit use of wrapping, this contradicts the wrap mode of no unsigned wrap -> LLVM interprets the generated instruction as a no-op and plain removes it: %_123431 = add nuw i10 1023, %offset_123426

-> don't do this normalization if the wrap mode is not 0