feat(dataflow): sparse constant propagation analysis - #660
Draft
axelcool1234 wants to merge 3 commits into
Draft
Conversation
axelcool1234
force-pushed
the
constant-propagation
branch
3 times, most recently
from
May 29, 2026 01:30
99491a7 to
7e01138
Compare
axelcool1234
marked this pull request as draft
May 29, 2026 01:51
axelcool1234
force-pushed
the
constant-propagation
branch
8 times, most recently
from
June 4, 2026 01:47
316cd2b to
b9f3206
Compare
axelcool1234
force-pushed
the
constant-propagation
branch
12 times, most recently
from
June 12, 2026 06:57
306d05a to
f25dfcb
Compare
axelcool1234
force-pushed
the
constant-propagation
branch
4 times, most recently
from
June 13, 2026 00:31
856253d to
3827eb6
Compare
axelcool1234
force-pushed
the
constant-propagation
branch
2 times, most recently
from
June 14, 2026 00:06
322071d to
3a9c43d
Compare
axelcool1234
force-pushed
the
constant-propagation
branch
from
July 15, 2026 22:19
3a9c43d to
cb599c4
Compare
axelcool1234
commented
Jul 15, 2026
Comment on lines
+127
to
+192
| -- TODO: Mirror MLIR's generic `op->fold` path once Veir has an operation | ||
| -- folder and fold-result representation. For now we manually handle the | ||
| -- arithmetic ops. | ||
| match (op.get! irCtx).opType with | ||
| | .arith .constant => | ||
| if h : results.size > 0 then | ||
| -- Read the `arith.constant` and convert it into the lattice domain. | ||
| let intAttr := (op.getProperties! irCtx (.arith .constant)).value | ||
| let constant : AbstractConstant := | ||
| .constant ⟨intAttr.type.bitwidth, Data.LLVM.Int.constant intAttr.type.bitwidth intAttr.value⟩ | ||
| propagateConstant (results[0]'h) constant dfCtx irCtx | ||
| else | ||
| dfCtx | ||
| | .arith .addi => | ||
| let flags := op.getProperties! irCtx (.arith .addi) | ||
| match foldBinaryOp? op dfCtx irCtx (fun lhs rhs => | ||
| match Data.LLVM.Int.add lhs rhs flags.attr.nsw flags.attr.nuw with | ||
| | .val v => some (.val v) | ||
| | .poison => none) with | ||
| | some constant => | ||
| if h : results.size > 0 then | ||
| propagateConstant (results[0]'h) constant dfCtx irCtx | ||
| else | ||
| dfCtx | ||
| | none => | ||
| setAllToUnknownConstants results dfCtx irCtx | ||
| | .arith .muli => | ||
| let flags := op.getProperties! irCtx (.arith .muli) | ||
| match foldBinaryOp? op dfCtx irCtx (fun lhs rhs => | ||
| match Data.LLVM.Int.mul lhs rhs flags.attr.nsw flags.attr.nuw with | ||
| | .val v => some (.val v) | ||
| | .poison => none) with | ||
| | some constant => | ||
| if h : results.size > 0 then | ||
| propagateConstant (results[0]'h) constant dfCtx irCtx | ||
| else | ||
| dfCtx | ||
| | none => | ||
| setAllToUnknownConstants results dfCtx irCtx | ||
| | .arith .andi => | ||
| match foldBinaryOp? op dfCtx irCtx (fun lhs rhs => | ||
| match lhs, rhs with | ||
| | .val lhs', .val rhs' => some (.val (BitVec.and lhs' rhs')) | ||
| | _, _ => none) with | ||
| | some constant => | ||
| if h : results.size > 0 then | ||
| propagateConstant (results[0]'h) constant dfCtx irCtx | ||
| else | ||
| dfCtx | ||
| | none => | ||
| setAllToUnknownConstants results dfCtx irCtx | ||
| | .arith .subi => | ||
| let flags := op.getProperties! irCtx (.arith .subi) | ||
| match foldBinaryOp? op dfCtx irCtx (fun lhs rhs => | ||
| match Data.LLVM.Int.sub lhs rhs flags.attr.nsw flags.attr.nuw with | ||
| | .val v => some (.val v) | ||
| | .poison => none) with | ||
| | some constant => | ||
| if h : results.size > 0 then | ||
| propagateConstant (results[0]'h) constant dfCtx irCtx | ||
| else | ||
| dfCtx | ||
| | none => | ||
| setAllToUnknownConstants results dfCtx irCtx | ||
| | _ => | ||
| setAllToUnknownConstants results dfCtx irCtx |
axelcool1234
force-pushed
the
constant-propagation
branch
2 times, most recently
from
July 16, 2026 00:20
1a87252 to
070b44b
Compare
axelcool1234
force-pushed
the
constant-propagation
branch
9 times, most recently
from
July 28, 2026 02:13
057beae to
4a0b24f
Compare
axelcool1234
force-pushed
the
constant-propagation
branch
2 times, most recently
from
August 14, 2026 04:35
b4cbe00 to
1c10e1e
Compare
axelcool1234
force-pushed
the
constant-propagation
branch
from
August 14, 2026 19:56
1c10e1e to
f90f1b1
Compare
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.
No description provided.