-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
[MLIR] Conversion from cf to llvm dialect fails for basic blocks with index arguments #55301
Comments
@llvm/issue-subscribers-mlir |
@llvm/issue-subscribers-mlir-llvm |
For anyone who faces the same challenge, I’ve written a simple pass that can resolve the issue: |
Previously cf.br cf.cond_br and cf.switch always lowered to their LLVM equivalents. These ops are all ops that take in some values of given types and jump to other blocks with argument lists of the same types. If the types are not the same, a verification failure will later occur. This led to confusions, as everything works when func->llvm and cf->llvm lowering both occur because func->llvm updates the blocks and argument lists while cf->llvm updates the branching ops. Without func->llvm though, there will potentially be a type mismatch. This change now only lowers the CF ops if they will later pass verification. This is possible because the parent op and its blocks will be updated before the contained branching ops, so they can test their new operand types against the types of the blocks they jump to. Another plan was to have func->llvm only update the entry block signature and to allow cf->llvm to update all other blocks, but this had 2 problems: 1. This would create a FuncOp lowering in cf->llvm lowering which is awkward 2. This new pattern would only be applied if the containing FuncOp is marked invalid. This is infeasible with the shared LLVM type conversion/target infrastructure. See previous discussions at https://discourse.llvm.org/t/lowering-cf-to-llvm/63863 and #55301 Differential Revision: https://reviews.llvm.org/D130971
This situation is hopefully improved with: 448adfe Note, that this would not make your original example succeed, but it should provide insights into the reason when running with |
The pass
cf-to-llvm
fails for IR containing basic blocks with index arguments. The error occurs upon the invocation of the legalizer after the generation ofcf.br
ops during dialect conversion inOneToOneLLVMTerminatorLowering<cf::BranchOp, LLVM::BrOp>::matchAndRewrite()
here. The cause seems to be an unrealized conversion cast that was generated as an unrealized target materialization.The following example IR filling a single
memref<2xi64>
with the value1
:triggers the error when running
mlir-opt --convert-cf-to-llvm fill-memref.cf.mlir
:The last IR dump right before exiting with an error is:
Tested with commit a65afce.
The text was updated successfully, but these errors were encountered: