Skip to content

feat(Rewriter): introduce eraseOp!/replaceValue! and clear remaining pass sorries#968

Open
tobiasgrosser wants to merge 6 commits into
mainfrom
tobias/eraseOpReplaceValueBang
Open

feat(Rewriter): introduce eraseOp!/replaceValue! and clear remaining pass sorries#968
tobiasgrosser wants to merge 6 commits into
mainfrom
tobias/eraseOpReplaceValueBang

Conversation

@tobiasgrosser

@tobiasgrosser tobiasgrosser commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator
  • Adds PatternRewriter.eraseOp! and .replaceValue!, mechanical panicking wrappers over the existing WfRewriter.eraseOp!/replaceValue!.
  • Uses them (alongside the earlier createOp!/replaceOp!) to clear the remaining sorries in InstCombine, ModArithToArith, MIRCombinesVeir, CastsReconciliation, DCE, RISCVCombines/Combine, and CSE (which calls WfRewriter directly).
  • RISCV64Branches.lean is intentionally left untouched: its let some x := ... | return c fallbacks around these calls are a genuine graceful-skip path rather than an always-true proof obligation, so converting to ! would silently turn skips into panics.

Converts the directly-convertible createOp/replaceOp call sites in
Common.lean, RISCV64Sdag.lean, InstCombine.lean, Canonicalize.lean,
ModArithToArith.lean, and MIRCombinesVeir.lean to the panicking `!`
variants, dropping their sorry-filled proof obligations. Common.lean,
RISCV64Sdag.lean, and Canonicalize.lean are now fully sorry-free;
the other three still carry sorries from replaceValue/eraseOp, which
don't have `!` variants yet.
…pass sorries

Adds PatternRewriter.eraseOp! and .replaceValue!, mechanical panicking
wrappers over the existing WfRewriter.eraseOp!/replaceValue!. Uses them
(plus the earlier createOp!/replaceOp!) to clear the remaining sorries
in InstCombine, ModArithToArith, MIRCombinesVeir, CastsReconciliation,
DCE, RISCVCombines/Combine, and CSE (which calls WfRewriter directly).

RISCV64Branches.lean is intentionally left untouched: its let-else
fallbacks around these calls are a genuine graceful-skip path rather
than an always-true proof obligation, so converting to `!` would
silently turn skips into panics.
Rename unused opInBounds/cast/lhs bindings to _ across the passes
touched by the createOp!/replaceOp!/eraseOp!/replaceValue! conversion.
The whole project now builds with zero warnings.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VeIR Benchmarks

Details
Benchmark suite Current: 1c5ca1e Previous: b8265aa Ratio
add-fold-worklist/create 2138000 ns (± 28190) 2434000 ns (± 160814) 0.88
add-fold-worklist/rewrite 3358000 ns (± 22165) 3947500 ns (± 56105) 0.85
add-fold-worklist-local/create 2146000 ns (± 106347) 2386000 ns (± 117421) 0.90
add-fold-worklist-local/rewrite 2901000 ns (± 146305) 3322500 ns (± 19159) 0.87
add-zero-worklist/create 2129000 ns (± 16799) 2406000 ns (± 109136) 0.88
add-zero-worklist/rewrite 2242000 ns (± 13145) 2501000 ns (± 29385) 0.90
add-zero-reuse-worklist/create 1754000 ns (± 46382) 2069000 ns (± 69158) 0.85
add-zero-reuse-worklist/rewrite 1888000 ns (± 55911) 2093000 ns (± 17355) 0.90
mul-two-worklist/create 2134000 ns (± 18055) 2233000 ns (± 45758) 0.96
mul-two-worklist/rewrite 4879000 ns (± 25401) 5578000 ns (± 83143) 0.87
add-fold-forwards/create 2143000 ns (± 37785) 2254000 ns (± 34802) 0.95
add-fold-forwards/rewrite 2649000 ns (± 31124) 2977000 ns (± 15110) 0.89
add-zero-forwards/create 2121500 ns (± 119864) 2289000 ns (± 70319) 0.93
add-zero-forwards/rewrite 1771000 ns (± 112162) 1951000 ns (± 10968) 0.91
add-zero-reuse-forwards/create 1764000 ns (± 31228) 1916000 ns (± 120621) 0.92
add-zero-reuse-forwards/rewrite 1431000 ns (± 15540) 1551000 ns (± 35552) 0.92
mul-two-forwards/create 2151500 ns (± 108004) 2356000 ns (± 73814) 0.91
mul-two-forwards/rewrite 3193500 ns (± 144348) 3575000 ns (± 63979) 0.89
add-zero-reuse-first/create 1728000 ns (± 23884) 1906500 ns (± 78414) 0.91
add-zero-reuse-first/rewrite 10000 ns (± 1832) 8000 ns (± 2040) 1.25
add-zero-lots-of-reuse-first/create 1740000 ns (± 44831) 1819000 ns (± 82223) 0.96
add-zero-lots-of-reuse-first/rewrite 768000 ns (± 14188) 783000 ns (± 27096) 0.98

This comment was automatically generated by workflow using github-action-benchmark.

@regehr regehr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!

@math-fehr

Copy link
Copy Markdown
Collaborator

RISCV64Branches.lean is intentionally left untouched: its let some x := ... | return c fallbacks around these calls are a genuine graceful-skip path rather than an always-true proof obligation, so converting to ! would silently turn skips into panics.

I disagree with this, we should also convert the ones in RISCV64Branches.lean. I believe the LLM thought the return c was different for some reasons, but it should panic in this case.

Base automatically changed from tobias/cleanRemainingPasses to main July 3, 2026 15:12
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.

3 participants