Index: mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp =================================================================== --- mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp +++ mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp @@ -478,15 +478,14 @@ if (!type) return nullptr; if (auto symbolRef = attr.dyn_cast()) - return instMap[c] = bEntry.create(unknownLoc, type, - symbolRef.getValue()); - return instMap[c] = bEntry.create(unknownLoc, type, attr); + return bEntry.create(unknownLoc, type, symbolRef.getValue()); + return bEntry.create(unknownLoc, type, attr); } if (auto *cn = dyn_cast(c)) { Type type = processType(cn->getType()); if (!type) return nullptr; - return instMap[c] = bEntry.create(unknownLoc, type); + return bEntry.create(unknownLoc, type); } if (auto *gv = dyn_cast(c)) return bEntry.create(UnknownLoc::get(context), @@ -510,13 +509,13 @@ // falsely believe that the new Instruction has been processed before // and raised an assertion error. cleanupValues.insert(i); - return instMap[c] = instMap[i]; + return instMap[i]; } if (auto *ue = dyn_cast(c)) { Type type = processType(ue->getType()); if (!type) return nullptr; - return instMap[c] = bEntry.create(UnknownLoc::get(context), type); + return bEntry.create(UnknownLoc::get(context), type); } if (isa(c) || isa(c)) { Index: mlir/test/Target/LLVMIR/Import/incorrect-constant-caching.ll =================================================================== --- /dev/null +++ mlir/test/Target/LLVMIR/Import/incorrect-constant-caching.ll @@ -0,0 +1,27 @@ +; RUN: mlir-translate --import-llvm %s | FileCheck %s + +%my_struct = type {i32, i8*} +; CHECK: llvm.mlir.constant(0 : i32) : i32 +; CHECK: llvm.mlir.constant(0 : i32) : i32 +; CHECK: llvm.mlir.addressof @str1 : !llvm.ptr> +; CHECK: llvm.getelementptr +; CHECK: llvm.mlir.constant(7 : i32) : i32 +; CHECK: llvm.mlir.undef : !llvm.struct<"my_struct", (i32, ptr)> +; CHECK: llvm.insertvalue +; CHECK: llvm.insertvalue +; CHECK: llvm.mlir.constant(0 : i32) : i32 +; CHECK: llvm.mlir.constant(0 : i32) : i32 +; CHECK: llvm.mlir.addressof @str0 : !llvm.ptr> +; CHECK: llvm.getelementptr +; CHECK: llvm.mlir.constant(8 : i32) : i32 +; CHECK: llvm.mlir.undef : !llvm.struct<"my_struct", (i32, ptr)> +; CHECK: llvm.insertvalue +; CHECK: llvm.insertvalue +; CHECK: llvm.mlir.undef : !llvm.array<2 x struct<"my_struct", (i32, ptr)>> +; CHECK: llvm.insertvalue +; CHECK: llvm.insertvalue +; CHECK: llvm.return +@str0 = private unnamed_addr constant [5 x i8] c"aaaa\00" +@str1 = private unnamed_addr constant [5 x i8] c"bbbb\00" +@g = global [2 x %my_struct] [%my_struct {i32 8, i8* getelementptr ([5 x i8], [5 x i8]* @str0, i32 0, i32 0)}, %my_struct {i32 7, i8* getelementptr ([5 x i8], [5 x i8]* @str1, i32 0, i32 0)}] +