[Mlir-commits] [mlir] [MLIR] Fix: `alloca` promotion for `AllocationOpInterface` (PR #97672)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Jul 3 20:50:01 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-bufferization
Author: Nikhil Kalra (nikalra)
<details>
<summary>Changes</summary>
The std::optional returned by buildPromotedAlloc was directly dereferenced and assumed to be non-null, even though the documentation for AllocationOpInterface indicates that std::nullopt is a legal value if buffer stack promotion is not supported (and is the default value supplied by the TableGen interface file). This patch removes the direct dereference so that the optional can be null-checked prior to use.
---
Full diff: https://github.com/llvm/llvm-project/pull/97672.diff
1 Files Affected:
- (modified) mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp (+3-3)
``````````diff
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp b/mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp
index d7056f35cbc8d..93c1f9a4f2b55 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp
@@ -397,12 +397,12 @@ class BufferPlacementPromotion : BufferPlacementTransformationBase {
OpBuilder builder(startOperation);
Operation *allocOp = alloc.getDefiningOp();
if (auto allocInterface = dyn_cast<AllocationOpInterface>(allocOp)) {
- Operation *alloca =
- allocInterface.buildPromotedAlloc(builder, alloc).value();
+ std::optional<Operation *> alloca =
+ allocInterface.buildPromotedAlloc(builder, alloc);
if (!alloca)
continue;
// Replace the original alloc by a newly created alloca.
- allocOp->replaceAllUsesWith(alloca);
+ allocOp->replaceAllUsesWith(alloca.value());
allocOp->erase();
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/97672
More information about the Mlir-commits
mailing list