Skip to content

[FoldConstantTensors] Set insertion point after last operation to erase#3130

Open
VedantParanjape wants to merge 1 commit into
google:mainfrom
VedantParanjape:patch-1
Open

[FoldConstantTensors] Set insertion point after last operation to erase#3130
VedantParanjape wants to merge 1 commit into
google:mainfrom
VedantParanjape:patch-1

Conversation

@VedantParanjape

Copy link
Copy Markdown
Collaborator

InsertIntoFromElements rewrite pattern emits the new FromElementsOp after the first InsertOp. This creates dominance issues if there are SSA values defined after the first InsertOp. The following snippet depicts the issue with the current implementation. This patch sets an insertion point after the last InsertOp to fix the dominance issue.

%ext0 = tensor.extract %input[idx0]
%ins1 = tensor.insert %ext0 into %zero[...]
%ext2 = tensor.extract %input[idx2]
%ins3 = tensor.insert %ext2 into %ins1[...]
/local/scratch/a/heir/kernel-mm4.mlir:12:12: note: operand defined here (op in the same block)
/local/scratch/a/heir/kernel-mm4.mlir:11:12: error: operand #8 does not dominate this use

InsertIntoFromElements rewrite pattern emits the new FromElementsOp after the first InsertOp. This creates dominance issues if there are SSA values defined after the first InsertOp. The following snippet depicts the issue with the current implementation. This patch sets an insertion point after the last InsertOp to fix the dominance issue.

```
%ext0 = tensor.extract %input[idx0]
%ins1 = tensor.insert %ext0 into %zero[...]
%ext2 = tensor.extract %input[idx2]
%ins3 = tensor.insert %ext2 into %ins1[...]
```

```
/local/scratch/a/heir/kernel-mm4.mlir:12:12: note: operand defined here (op in the same block)
/local/scratch/a/heir/kernel-mm4.mlir:11:12: error: operand google#8 does not dominate this use
```
@VedantParanjape VedantParanjape requested a review from j2kun June 26, 2026 07:12
@j2kun j2kun added the pull_ready Indicates whether a PR is ready to pull. The copybara worker will import for internal testing label Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pull_ready Indicates whether a PR is ready to pull. The copybara worker will import for internal testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants