When trying to fold an operation during operation creation check that
the operation folding succeeds before inserting the op.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
| mlir/include/mlir/Transforms/FoldUtils.h | ||
|---|---|---|
| 91 | I think that is similar to what River mentions above, but this code is fishy: if none of the branch is taken the op just leaks. I'd write it with early exit so that there is a clear handling of the "fallback" path. | |
| mlir/include/mlir/Transforms/FoldUtils.h | ||
|---|---|---|
| 91 | I changed it. I think the logic now maps to what River suggested. Something is off though. Test failing (maybe another issue exposed by this). Looking into those. | |
| mlir/lib/Transforms/Utils/FoldUtils.cpp | ||
|---|---|---|
| 168 | Hmm, this is wrong. You can't assume the insertion point is on a valid operation, the block could be empty. You would need to use the block. | |
| mlir/lib/Transforms/Utils/FoldUtils.cpp | ||
|---|---|---|
| 168 | Passing in the insertion block instead of a builder would clean a bit of this up. | |
| mlir/lib/Transforms/Utils/FoldUtils.cpp | ||
|---|---|---|
| 168 | Good point. CHanged. | |
You will also want to insert in the case of successful fold and getNumResults() == 0. In that case it is treated as an in-place fold of a zero-result operation.