Skip to content

fix(mlir): lower vector literals with vector.from_elements - #1562

Closed
godofecht wants to merge 8 commits into
mainfrom
fix/mlir-vector-literal
Closed

godofecht wants to merge 8 commits into
mainfrom
fix/mlir-vector-literal

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

Cause

A vector literal <a, b, c, d> lowered to vector.undef plus one
vector.insertelement per lane, then an alias line %r = %last : T. That
is the retired Python generator's output. vector.undef and
vector.insertelement are gone from MLIR 22, so mlir-opt failed with
"custom op 'vector.undef' is unknown", and the alias line is no valid
MLIR at all. The literal was also typed from its first element (f64 for
1.0) and met a vec4<f32> with no conversion, and mlg_expr_mt called
every vector literal i32. 2 corpus programs failed this way
(tests/simd/test_simple_simd.flow, tests/simd/test_simd_vector.flow).

Fix

  • A vector literal is one vector.from_elements, its lanes cast to the
    type of the first element.
  • mlg_cast converts between vectors of the same length lane by lane
    (arith.extf, truncf, sitofp, fptosi, extsi, trunci on the
    vector type), so the literal meets the declared vecN<T> of a let, a
    return or an argument.
  • In a binary operator, a vector literal takes the other operand's vector
    type, and mlg_expr_mt agrees.

Regression fixture: compiler/fixtures/mlir/vector_literal.flow (an f32
literal returned, literals on either side of *, + and -, and an
i64 vector). On main it fails in mlir-opt with "custom op 'vector.undef'
is unknown".

Counts

mlir_vs_c --only tests/simd/ (4 programs):

same mlir-lower
main 7bbb4b3 2 2
this branch 4 0

Full corpus run (mlir_vs_c --jobs 8): queued behind the machine-wide corpus lock; the before and after counts will be added here.

Gates

  • selftest: flowc: PASS
  • bootstrap_from_c.sh --regen, then --verify: PASS
  • self_host_full, roundtrip: PASS
  • parity_mlir: PASS (25 fixtures, 2721 corpus programs)
  • tests/cgen: 152 passed, 0 failed
  • test-lang: all 309 passed
  • test-scripts: all pass except mlir_math_override, which fails in its
    C-backend half (flow run --backend=c exits 1). This change touches only
    the MLIR emitter, so the C path is the same as on main.

Regenerated state

  • compiler/bootstrap/flowc_stage_a.c and compiler/bootstrap/flowc_stage_a,
    in their own last commit.
  • compiler/fixtures/mlir/vector_literal.mlir and .out, recorded with
    parity_mlir.flow --record.
  • compiler/fixtures/mlir/corpus.txt: the digests of tests/simd/test_simd_vector.flow and tests/simd/test_simple_simd.flow move, since their vector literals are now vector.from_elements. No other digest moved. --record also wanted to add 11 programs this change does not affect (corpus drift on main); those lines are left out.

Risk

Low. Only vector literals and casts between two vector types change; both
produced MLIR that mlir-opt rejected before.

Needs review by a CODEOWNER (touches compiler/).

A vector literal lowered to vector.undef plus vector.insertelement and an
alias line, the retired Python generator's output; MLIR 22 has neither
op, and the alias is no valid MLIR. It is now one vector.from_elements
of lanes cast to the first element's type. mlg_cast converts between
vectors of the same length lane by lane, so the literal meets a declared
vecN<T>, and in an operator a literal takes the other operand's type.

Fixture: compiler/fixtures/mlir/vector_literal.flow.
@godofecht
godofecht added this pull request to the merge queue Oct 14, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 14, 2026
godofecht and others added 2 commits October 20, 2026 12:34
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: godofecht <[email protected]>

Copy link
Copy Markdown
Contributor Author

Resolved conflicts with current main in 4777ce529502256976026364e24e42c5cc81c3fa. Reapplied all three vector-literal Flow compiler hunks, the three corresponding generated C changes and 106 deterministic temporary renamings (offsets +78/+125), plus the three original regression fixtures. Excluded unrelated shared bundle changes. CI qualification still required before merge.

Copy link
Copy Markdown
Contributor Author

CI repair update (2026-11-02, head 082046ea2556ca9860649397bb96b38e8d4dfcb9): synchronized the five LLVM-dependent runner pins with current main in three workflow files (ci.yml: FLOW tier-2, flowc goldens, native tools; bpf.yml; wasm32.yml). Each resulting workflow file was checked byte-for-byte against main; no test steps or gates were removed. Commits: 9211a52a, 7ba19a1d, 082046ea. This addresses the confirmed Ubuntu-latest/LLVM-22 dependency problem in the historical run, not the compiler bootstrap or MLIR golden issues. GitHub currently reports this updated PR as merge-conflicted (mergeable_state=dirty), so no fresh PR CI has started. Next: reconcile the compiler source/bootstrap and vector-literal golden with latest main, regenerate compiler artifacts using repository tooling, then run exact-head Linux/macOS and MLIR qualification. Do not merge while dirty or red.

Copy link
Copy Markdown
Contributor Author

Superseded by #1674 (Jules session 309291271695338674; preferred #1562 migration onto current main 22fb5c2 after merge-main; CI fully green). Closing this historical PR. Part of #1576.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant