Skip to content

[ScalarizeShapes] Fold select.int through cat in shape computations#4513

Open
jtuyls wants to merge 1 commit intollvm:mainfrom
jtuyls:shape-gather-to-size-int
Open

[ScalarizeShapes] Fold select.int through cat in shape computations#4513
jtuyls wants to merge 1 commit intollvm:mainfrom
jtuyls:shape-gather-to-size-int

Conversation

@jtuyls
Copy link
Copy Markdown
Contributor

@jtuyls jtuyls commented Mar 24, 2026

Extend getListFromTensor to recurse into aten.cat operands and add a select.int folding pattern. This resolves shape elements from concat-based shape tensors used by onnx.Reshape lowering.

Extend getListFromTensor to recurse into aten.cat operands and add
a select.int folding pattern. This resolves shape elements from
concat-based shape tensors used by onnx.Reshape lowering.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jtuyls jtuyls requested review from rsuderman and zjgarvey March 24, 2026 10:29
Copy link
Copy Markdown
Collaborator

@zjgarvey zjgarvey left a comment

Choose a reason for hiding this comment

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

Sorry for the extremely late review. This somehow got dropped from my queue after I went to look back at the prim op. I just have the one concern about the prim op being expected to return rank 0 sometimes, but otherwise this looks good to me.


auto resultTy = cast<ValueTensorType>(op.getType());
rewriter.replaceOp(
op, PrimNumToTensorScalarOp::create(b, resultTy, materialized.front()));
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.

IIRC, the PrimNumToTensorScalarOp is expected to have a rank zero result in some places (e.g., some folding patterns). I think the abstract interp function is just return []. If we know the output is always shaped like [1] it might be better to use a full op just in case this causes issues anywhere.

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.

2 participants