Skip to content

Commit 947374c

Browse files
authored
[IRTranslator] Simplify fixed vector ConstantAggregateZero handling. NFC (#108667)
We don't need to loop through the elements, they're all the same zero. We can get the first element and create a splat build_vector.
1 parent 82266d3 commit 947374c

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3532,14 +3532,11 @@ bool IRTranslator::translate(const Constant &C, Register Reg) {
35323532
return false;
35333533
// Return the scalar if it is a <1 x Ty> vector.
35343534
unsigned NumElts = CAZ->getElementCount().getFixedValue();
3535+
Constant &Elt = *CAZ->getElementValue(0u);
35353536
if (NumElts == 1)
3536-
return translateCopy(C, *CAZ->getElementValue(0u), *EntryBuilder);
3537-
SmallVector<Register, 4> Ops;
3538-
for (unsigned I = 0; I < NumElts; ++I) {
3539-
Constant &Elt = *CAZ->getElementValue(I);
3540-
Ops.push_back(getOrCreateVReg(Elt));
3541-
}
3542-
EntryBuilder->buildBuildVector(Reg, Ops);
3537+
return translateCopy(C, Elt, *EntryBuilder);
3538+
// All elements are zero so we can just use the first one.
3539+
EntryBuilder->buildSplatBuildVector(Reg, getOrCreateVReg(Elt));
35433540
} else if (auto CV = dyn_cast<ConstantDataVector>(&C)) {
35443541
// Return the scalar if it is a <1 x Ty> vector.
35453542
if (CV->getNumElements() == 1)

0 commit comments

Comments
 (0)