Skip to content

Commit 392cc84

Browse files
committed
[mlir][LLVMIR target] Fix llvm.freeze builder to prevent crashes
The freeze builder did not assign the result of creating the freeze operation to $res, which meant that when subsequent translations (such as a sext) tried to use that result or query its type, mlir-translate would crash. This fixes the issue and adds a test for it. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D139574
1 parent f39b472 commit 392cc84

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ def LLVM_FreezeOp : LLVM_Op<"freeze", [SameOperandsAndResultType]> {
732732
let builders = [LLVM_OneResultOpBuilder];
733733
let assemblyFormat = "$val attr-dict `:` type($val)";
734734
string llvmInstName = "Freeze";
735-
string llvmBuilder = "builder.CreateFreeze($val);";
735+
string llvmBuilder = "$res = builder.CreateFreeze($val);";
736736
string mlirBuilder = [{
737737
$res = $_builder.create<LLVM::FreezeOp>($_location, $val);
738738
}];

mlir/test/Target/LLVMIR/llvmir.mlir

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,16 @@ llvm.func @callFreezeOp(%x : i32) {
15011501
llvm.return
15021502
}
15031503

1504+
// CHECK-LABEL: @freezeUsed
1505+
llvm.func @freezeUsed(%x : i32) -> i64 {
1506+
// CHECK: %[[frozen:.*]] = freeze i32
1507+
%frozen = llvm.freeze %x : i32
1508+
// CHECK: %[[ext:.*]] = sext i32 %[[frozen]] to i64
1509+
%ext = llvm.sext %frozen : i32 to i64
1510+
// CHECK: ret i64 %[[ext]]
1511+
llvm.return %ext : i64
1512+
}
1513+
15041514
// CHECK-LABEL: @boolConstArg
15051515
llvm.func @boolConstArg() -> i1 {
15061516
// CHECK: ret i1 false

0 commit comments

Comments
 (0)