Skip to content

[CIR] Skip generation of a continue block when flattening TernaryOp #1651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2025

Conversation

mmha
Copy link
Collaborator

@mmha mmha commented May 29, 2025

We used to insert a continue Block at the end of a flattened ternary op that only contained a branch to the remaing operation of the remaining Block. This patch removes that continue block and changes the true/false blocks to directly jump to the remaining ops.

With this patch the CIR now generates exactly the same LLVM IR as the original codegen.

We used to insert a continue Block at the end of a flattened ternary op
that only contained a branch to the remaing operation of the remaining
Block. This patch removes that continue block and changes the true/false
blocks to directly jump to the remaining ops.

With this patch the CIR now generates exactly the same LLVM IR as the
original codegen.
@mmha mmha requested review from lanza and bcardosolopes as code owners May 29, 2025 13:12
Comment on lines 896 to 902
if(auto rt = op.getResultTypes(); rt.size()) {
auto args = remainingOpsBlock->addArguments(rt, op.getLoc());
SmallVector<mlir::Value, 2> values;
llvm::copy(args, std::back_inserter(values));
rewriter.replaceOpUsesWithinBlock(op, values, remainingOpsBlock);
}
rewriter.eraseOp(op);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All of this felt a bit... unergonomic. Is there no better way to replace an op and insert arguments into the block?

Copy link

github-actions bot commented May 29, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Collaborator

@andykaylor andykaylor left a comment

Choose a reason for hiding this comment

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

This looks reasonable to me.

@bcardosolopes bcardosolopes changed the title Skip generation of a continue block when flattening TernaryOp [CIR] Skip generation of a continue block when flattening TernaryOp May 30, 2025
Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@bcardosolopes bcardosolopes merged commit 6e5fa09 into llvm:main May 30, 2025
9 checks passed
mmha added a commit to mmha/llvm-project that referenced this pull request May 30, 2025
We used to insert a continue Block at the end of a flattened ternary op that only contained a branch to the remaing operation of the remaining Block. This patch removes that continue block and changes the true/false blocks to directly jump to the remaining ops.

With this patch the CIR now generates exactly the same LLVM IR as the original codegen.

This upstreams llvm/clangir#1651.
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