Repository navigation
Conversation
`a as u64` for an i64 a needs no instruction, so mlirgen returned a's own SSA value and marked it unsigned. When a is a parameter or a local, that mark stuck: later comparisons on a were unsigned. In compiler/src/dynamic_invariants.flow, `a < 0` after `a as u64` became an ult against 0, always false, so tests/lang/test_dynamic_invariants exited 24 where C exits 0. When the signedness changes and the operand is a parameter or a local's current value, the cast now yields a new value (an arith.bitcast to the same type, which folds away) that carries the new signedness. Other operands are marked in place as before. compiler/fixtures/mlir/cast_signedness.flow is the distance case; the old backend printed 18446744073709551609 for |(-3) - 4| and exited 1. Corpus digests moved for the programs that cast a variable this way.
…ts (#1593) Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: godofecht <[email protected]>
Contributor
Author
|
Closing this stale conflicting signedness-cast implementation as superseded by current-main PR #1640, which fixes the same shared-SSA signedness mutation by creating a distinct value. I linked the older distance/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cause
a as u64for an i64aneeds no instruction, somlg_emit_cast_exprreturneda's own SSA value and set its unsigned flag. Whenais a parameter or a local, the flag stayed on the variable: every later comparison onawas unsigned.In
compiler/src/dynamic_invariants.flow,flowc_dyn_i64_distancecastsa as u64in its first branch, so the nexta < 0becamearith.cmpi ult, %arg0, 0, always false.tests/lang/test_dynamic_invariants.flowexited 24 under MLIR and 0 under C.Fix
When a same-width integer cast changes signedness and its operand is a parameter or a local's current value, the cast yields a new value,
arith.bitcast %v : T to T(it folds away), that carries the new signedness. A temporary operand is still marked in place, so programs without such a cast emit the same MLIR as before.Regression test
compiler/fixtures/mlir/cast_signedness.flowis the distance case plus ani32local cast tou32. The old backend printed18446744073709551609for |(-3) - 4| and exited 1; the recorded run is1 4294967291 7 7, exit 0, as C prints.Counts (mlir_vs_c, full corpus, --jobs 8, macOS arm64, LLVM 22.1.7)
Now same:
tests/lang/test_dynamic_invariants.flowand the new fixture. Four programs that were same were not in this run, and I checked each:examples/concurrency/http_tls.flow(run-stdout) andtests/stdlib/test_gpu_model.flow(run-exit 28): same when re-run with--onlyon this branch's compiler. test_gpu_model also flaked on another branch (exit 133).tests/stdlib/audio/test_bus_graph.flow(mlir-slow): clang takes most of the 300 s build limit on this program's IR when the machine is loaded. A build with main's compiler took 9 min 23 s wall (146 s CPU) during the same period, and the emit itself takes about a second on both compilers.examples/concurrency/work_steal.flow(nondet): scheduler output, flaky on every branch.Gates
bootstrap_from_c.sh --regen, then--verify: PASSmlir_math_override, in its C backend half. It fails the same way with a flowc built from main's bootstrap C.Regenerated state
compiler/bootstrap/flowc_stage_a.candflowc_stage_a, in their own last commit.cast_signedness.mlirand.out.compiler/fixtures/mlir/corpus.txt: digests move for the 92 programs that cast a variable to the other signedness at the same width (mostly the dynamics DSL fixtures and the stdlib modules they import: ga, procgen, planet, automata, gif, checked_arith). The 11 programs main never recorded are left out.The floor in
compiler/mlir_vs_c/floor.txtis not changed.Risk
Medium-low. The change touches many programs' MLIR, but only by inserting a no-op bitcast where a variable's signedness used to be overwritten. Any of those programs that compared the variable after such a cast was computing the wrong comparison before.