diff --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp --- a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp +++ b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp @@ -689,7 +689,7 @@ while (!workList.empty()) { llvm::Constant *current = workList.pop_back_val(); // Skip constants that have been converted before and store all other ones. - if (valueMapping.count(constant)) + if (valueMapping.count(current)) continue; orderedList.push_back(current); // Add the current constant's dependencies to the work list. Only add diff --git a/mlir/test/Target/LLVMIR/Import/constant.ll b/mlir/test/Target/LLVMIR/Import/constant.ll --- a/mlir/test/Target/LLVMIR/Import/constant.ll +++ b/mlir/test/Target/LLVMIR/Import/constant.ll @@ -208,3 +208,21 @@ ; CHECK: %[[CHAIN1:.+]] = llvm.insertelement %[[NULL]], %[[CHAIN0]][%[[P1]] : i32] : !llvm.vec<2 x ptr>> ; CHECK: llvm.return %[[CHAIN1]] : !llvm.vec<2 x ptr>> @vector_agg = global <2 x %simple_agg_type*> <%simple_agg_type* null, %simple_agg_type* null> + +; // ----- + +; Verfiy the import of subsequent constant expressions with duplicates. + +@global = external global i32, align 8 + +; CHECK-LABEL: @const_exprs_with_duplicate +define i64 @const_exprs_with_duplicate() { + ; CHECK: %[[ADDR:.+]] = llvm.mlir.addressof @global : !llvm.ptr + ; CHECK: llvm.getelementptr %[[ADDR]][%{{.*}}] : (!llvm.ptr, i32) -> !llvm.ptr + %1 = add i64 1, ptrtoint (i32* getelementptr (i32, i32* @global, i32 7) to i64) + + ; Verify the address value is reused. + ; CHECK: llvm.getelementptr %[[ADDR]][%{{.*}}] : (!llvm.ptr, i32) -> !llvm.ptr + %2 = add i64 %1, ptrtoint (i32* getelementptr (i32, i32* @global, i32 42) to i64) + ret i64 %2 +}