diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -2184,7 +2184,7 @@ return false; // Return the scalar if it is a <1 x Ty> vector. if (CAZ->getNumElements() == 1) - return translate(*CAZ->getElementValue(0u), Reg); + return translateCopy(C, *CAZ->getElementValue(0u), *EntryBuilder.get()); SmallVector Ops; for (unsigned i = 0; i < CAZ->getNumElements(); ++i) { Constant &Elt = *CAZ->getElementValue(i); @@ -2194,7 +2194,8 @@ } else if (auto CV = dyn_cast(&C)) { // Return the scalar if it is a <1 x Ty> vector. if (CV->getNumElements() == 1) - return translate(*CV->getElementAsConstant(0), Reg); + return translateCopy(C, *CV->getElementAsConstant(0), + *EntryBuilder.get()); SmallVector Ops; for (unsigned i = 0; i < CV->getNumElements(); ++i) { Constant &Elt = *CV->getElementAsConstant(i); @@ -2212,7 +2213,7 @@ } } else if (auto CV = dyn_cast(&C)) { if (CV->getNumOperands() == 1) - return translate(*CV->getOperand(0), Reg); + return translateCopy(C, *CV->getOperand(0), *EntryBuilder.get()); SmallVector Ops; for (unsigned i = 0; i < CV->getNumOperands(); ++i) { Ops.push_back(getOrCreateVReg(*CV->getOperand(i))); diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll b/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll --- a/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll +++ b/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll @@ -1614,7 +1614,9 @@ ; CHECK: [[ARG:%[0-9]+]]:_(s32) = COPY $w0 ; CHECK: [[C0:%[0-9]+]]:_(s32) = G_CONSTANT i32 0 ; CHECK-NOT: G_MERGE_VALUES -; CHECK: G_ADD [[ARG]], [[C0]] +; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY [[C0]] +; CHECK-NOT: G_MERGE_VALUES +; CHECK: G_ADD [[ARG]], [[COPY]] %vec = insertelement <1 x i32> undef, i32 %arg, i32 0 %add = add <1 x i32> %vec, zeroinitializer %res = extractelement <1 x i32> %add, i32 0 @@ -1626,7 +1628,9 @@ ; CHECK: [[ARG:%[0-9]+]]:_(s32) = COPY $w0 ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1 ; CHECK-NOT: G_MERGE_VALUES -; CHECK: G_ADD [[ARG]], [[C1]] +; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY [[C0]] +; CHECK-NOT: G_MERGE_VALUES +; CHECK: G_ADD [[ARG]], [[COPY]] %vec = insertelement <1 x i32> undef, i32 %arg, i32 0 %add = add <1 x i32> %vec, %res = extractelement <1 x i32> %add, i32 0 @@ -2388,4 +2392,4 @@ ret {i8, i32} %res } -!0 = !{ i64 0, i64 2 } \ No newline at end of file +!0 = !{ i64 0, i64 2 } diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-constantexpr.ll b/llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-constantexpr.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-constantexpr.ll @@ -0,0 +1,24 @@ +; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py +; RUN: llc -global-isel -mtriple=amdgcn-amd-amdhsa -verify-machineinstrs -stop-after=irtranslator -o - %s | FileCheck %s + +@var = global i32 undef + +define i32 @test() { + ; CHECK-LABEL: name: test + ; CHECK: bb.1 (%ir-block.0): + ; CHECK: liveins: $sgpr30_sgpr31 + ; CHECK: [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31 + ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 -1 + ; CHECK: [[INTTOPTR:%[0-9]+]]:_(p0) = G_INTTOPTR [[C]](s32) + ; CHECK: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @var + ; CHECK: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[INTTOPTR]](p0), [[GV]] + ; CHECK: [[ZEXT:%[0-9]+]]:_(s32) = G_ZEXT [[ICMP]](s1) + ; CHECK: [[COPY1:%[0-9]+]]:_(s32) = COPY [[ZEXT]](s32) + ; CHECK: [[COPY2:%[0-9]+]]:_(s32) = COPY [[COPY1]](s32) + ; CHECK: [[COPY3:%[0-9]+]]:_(s32) = COPY [[COPY2]](s32) + ; CHECK: [[COPY4:%[0-9]+]]:_(s32) = COPY [[COPY3]](s32) + ; CHECK: $vgpr0 = COPY [[COPY4]](s32) + ; CHECK: [[COPY5:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]] + ; CHECK: S_SETPC_B64_return [[COPY5]], implicit $vgpr0 + ret i32 bitcast (<1 x i32> bitcast (i32 zext (i1 icmp eq (i32* @var, i32* inttoptr (i32 -1 to i32*)) to i32) to <1 x i32>), i64 0)> to i32) +}