Why does cranelift use i8
for booleans instead of i1
like llvm does?
Good question! We had a dedicated bool type before, but we had persistent confusion about what the register-level value for true
should be (1 or -1) and bugs related to that, and bools were always special, so we shifted to integers instead for any value that needs to be truthy. i1
would have some of the same weirdness -- can't store to memory, etc -- so we stuck with existing integer types. The ops that consume a truthy value, like select or brif, actually should accept any integer width (and test val != 0); icmp
produces i8 because on x86 SETcc only sets the lower 8 bits of a register (ugh).
(we've talked about making icmp
produce an i32
instead -- one could always narrow it back down if a one-byte value were needed -- as it aligns better with what Wasm expects hence reduces IR size out of the Wasm frontend -- but no recent progress on that)
If the boolean type was i1
, then the truthy value would be both 1
and -1
;)
That's certainly true!
Last updated: Dec 23 2024 at 12:05 UTC