Treatment of boolean values in Cmm is quite ad-hoc
When looking at the Cmm produced by !1327 (closed) I noticed the following code produced with optimisation:
if ((5 >= I64[_s1pC::P64 + 16]) & 1 == 0) (likely: True) goto c1pP; else goto c1pQ;
Notice the & 1
here; this &
is intended to be a logical-and, which in principle should be constant-folded away. However, Cmm only has bitwise operations and consequently we are unable to do so.
This suggests that introducing a new one-bit-width type in Cmm might be useful. Distinguishing boolean values in CmmType
would also put the ad-hoc condition check implemented by CmmLint (https://gitlab.haskell.org/ghc/ghc/-/blob/d6177cb5dac357ff15ae048556f03039dd6987d2/compiler/GHC/Cmm/Lint.hs#L252) on a more solid footing.