Skip to content

Commit

Permalink
[mlir][LLVMIR target] Fix llvm.freeze builder to prevent crashes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
krzysz00 committed Dec 12, 2022
1 parent f39b472 commit 392cc84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
Expand Up @@ -732,7 +732,7 @@ def LLVM_FreezeOp : LLVM_Op<"freeze", [SameOperandsAndResultType]> {
let builders = [LLVM_OneResultOpBuilder];
let assemblyFormat = "$val attr-dict `:` type($val)";
string llvmInstName = "Freeze";
string llvmBuilder = "builder.CreateFreeze($val);";
string llvmBuilder = "$res = builder.CreateFreeze($val);";
string mlirBuilder = [{
$res = $_builder.create<LLVM::FreezeOp>($_location, $val);
}];
Expand Down
10 changes: 10 additions & 0 deletions mlir/test/Target/LLVMIR/llvmir.mlir
Expand Up @@ -1501,6 +1501,16 @@ llvm.func @callFreezeOp(%x : i32) {
llvm.return
}

// CHECK-LABEL: @freezeUsed
llvm.func @freezeUsed(%x : i32) -> i64 {
// CHECK: %[[frozen:.*]] = freeze i32
%frozen = llvm.freeze %x : i32
// CHECK: %[[ext:.*]] = sext i32 %[[frozen]] to i64
%ext = llvm.sext %frozen : i32 to i64
// CHECK: ret i64 %[[ext]]
llvm.return %ext : i64
}

// CHECK-LABEL: @boolConstArg
llvm.func @boolConstArg() -> i1 {
// CHECK: ret i1 false
Expand Down

0 comments on commit 392cc84

Please sign in to comment.