[PATCH] D79230: [MLIR][crashfix] Fall back to malloc when alignment is 0 for align-alloc
Kern Handa via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 1 00:43:34 PDT 2020
kernhanda updated this revision to Diff 261437.
kernhanda added a comment.
clang-format
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79230/new/
https://reviews.llvm.org/D79230
Files:
mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
mlir/test/Conversion/StandardToLLVM/convert-dynamic-memref-ops.mlir
Index: mlir/test/Conversion/StandardToLLVM/convert-dynamic-memref-ops.mlir
===================================================================
--- mlir/test/Conversion/StandardToLLVM/convert-dynamic-memref-ops.mlir
+++ mlir/test/Conversion/StandardToLLVM/convert-dynamic-memref-ops.mlir
@@ -182,6 +182,13 @@
// ALIGNED-ALLOC: %[[c128:.*]] = llvm.mlir.constant(128 : i64) : !llvm.i64
// ALIGNED-ALLOC: llvm.call @aligned_alloc(%[[c128]]
%6 = alloc(%N) : memref<?xvector<18xf32>>
+ // When alignment is 0, revert to malloc behavior
+ // ALIGNED-ALLOC: %[[c64:.*]] = llvm.mlir.constant(64 : index) : !llvm.i64
+ // ALIGNED-ALLOC: llvm.mul %[[c64]]
+ // ALIGNED-ALLOC: llvm.add
+ // ALIGNED-ALLOC-NEXT: %[[ZERO_ALIGNED:.*]] = llvm.sub
+ // ALIGNED-ALLOC-NEXT: llvm.call @malloc(%[[ZERO_ALIGNED]])
+ %7 = alloc() {alignment = 0} : memref<64xf32>
return %0 : memref<32x18xf32>
}
Index: mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
===================================================================
--- mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
+++ mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
@@ -1521,7 +1521,7 @@
Optional<int64_t> allocationAlignment = getAllocationAlignment(allocOp);
// Whether to use std lib function aligned_alloc that supports alignment.
- bool useAlignedAlloc = allocationAlignment.hasValue();
+ bool useAlignedAlloc = allocationAlignment && *allocationAlignment != 0;
// Insert the malloc/aligned_alloc declaration if it is not already present.
auto allocFuncName = useAlignedAlloc ? "aligned_alloc" : "malloc";
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79230.261437.patch
Type: text/x-patch
Size: 1622 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200501/228c8587/attachment.bin>
More information about the llvm-commits
mailing list