mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-29 07:04:09 +08:00
Integer arithmetic with an int32 result range materialized its number with `sitofp i64`, which LLVM does not know to be exact, so it could not fold the conversion back for the next integer use or through the phis of loop-carried locals: a counter written `i = (i + 1) | 0` converted to a double and back on every iteration. With int32 operands and result, `+`, `-` and `*` now emit `add/sub/mul nsw i32` and convert with `sitofp i32`; other int32-range numbers convert from the low half of their i64, and an int32-range read of a number uses `fptosi ... to i32`. The nsw flag stays on the 32-bit operation (a truncated 64-bit result would lose it), so IndVars can still widen such counters into 64-bit address arithmetic.