-
Notifications
You must be signed in to change notification settings - Fork 150
[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
[CIR] Skip generation of a continue block when flattening TernaryOp #1651
Conversation
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.
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); |
There was a problem hiding this comment.
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?
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks!
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.
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.