Skip to content

Commit 2f0ea39

Browse files
castiglikeshavvinayak01
authored andcommitted
[LLVMCPU] Fix llvmcpu check before conversion for complex types (iree-org#21644)
This PR fixes `LLVMCPUCheckIRBeforeLLVMConversionPass` . The pass erroneously assumed that the tensor element type is an integer or a float and would therefore fail for complex types. A test was added to cover this case. --------- Signed-off-by: Giacomo Castiglioni <[email protected]> Signed-off-by: keshavvinayak01 <[email protected]>
1 parent 5a40d28 commit 2f0ea39

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

compiler/src/iree/compiler/Codegen/LLVMCPU/LLVMCPUCheckIRBeforeLLVMConversion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ checkStackAllocationSize(mlir::FunctionOpInterface funcOp) {
9393
}
9494
return allocaOp.emitOpError("expected no unbounded stack allocations");
9595
}
96-
allocaSize *= allocaType.getElementType().getIntOrFloatBitWidth();
96+
allocaSize *= IREE::Util::getTypeBitWidth(allocaType.getElementType());
9797
if (allocaOp.getAlignment()) {
9898
int64_t alignmentInBits = *allocaOp.getAlignment() * 8;
9999
allocaSize =

compiler/src/iree/compiler/Codegen/LLVMCPU/test/check_ir_before_llvm_conversion.mlir

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: iree-opt --pass-pipeline="builtin.module(func.func(iree-llvmcpu-check-ir-before-llvm-conversion))" %s --verify-diagnostics -split-input-file
1+
// RUN: iree-opt --pass-pipeline="builtin.module(func.func(iree-llvmcpu-check-ir-before-llvm-conversion))" %s --verify-diagnostics -split-input-file | FileCheck %s
22

33
func.func @dynamic_allocas(%arg0: index) {
44
// expected-error @+1 {{expected no unbounded stack allocations}}
@@ -57,3 +57,11 @@ func.func @nested_op_alloca(%arg0 : index) {
5757
}
5858
return
5959
}
60+
61+
// -----
62+
63+
func.func @complex_alloca() {
64+
%0 = memref.alloca() : memref<128xcomplex<f32>>
65+
return
66+
}
67+
// CHECK-LABEL: func @complex_alloca(

compiler/src/iree/compiler/Codegen/LLVMCPU/test/check_ir_before_llvm_conversion_not_fail_unbound.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: iree-opt --pass-pipeline="builtin.module(func.func(iree-llvmcpu-check-ir-before-llvm-conversion{fail-on-out-of-bounds=false}))" %s -split-input-file
1+
// RUN: iree-opt --pass-pipeline="builtin.module(func.func(iree-llvmcpu-check-ir-before-llvm-conversion{fail-on-out-of-bounds=false}))" %s -split-input-file | FileCheck %s
22

33
func.func @dynamic_allocas(%arg0: index) {
44
%0 = memref.alloca(%arg0) : memref<?xf32>

0 commit comments

Comments
 (0)