[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
This commit is contained in:
Krzysztof Drewniak
2022-12-07 21:05:58 +00:00
parent f39b47264e
commit 392cc842c2
2 changed files with 11 additions and 1 deletions

View File

@@ -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);
}];

View File

@@ -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