Skip to content

Commit 386bb29

Browse files
committed
Explicitly handle ConstantAggregateZero
1 parent 1145582 commit 386bb29

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3998,20 +3998,28 @@ ConstantFoldStructCall(StringRef Name, Intrinsic::ID IntrinsicID,
39983998
if (!Vec)
39993999
return nullptr;
40004000

4001-
unsigned NumElements =
4002-
cast<VectorType>(Vec->getType())->getElementCount().getKnownMinValue() /
4003-
2;
4001+
auto VecTy = cast<VectorType>(Vec->getType());
4002+
unsigned NumElements = VecTy->getElementCount().getKnownMinValue() / 2;
4003+
40044004
SmallVector<Constant *, 4> Res0(NumElements), Res1(NumElements);
4005-
for (unsigned I = 0; I < NumElements; ++I) {
4006-
Constant *Elt0 = Vec->getAggregateElement(2 * I);
4007-
Constant *Elt1 = Vec->getAggregateElement(2 * I + 1);
4008-
if (!Elt0 || !Elt1)
4009-
return nullptr;
4010-
Res0[I] = Elt0;
4011-
Res1[I] = Elt1;
4005+
if (isa<ConstantAggregateZero>(Vec)) {
4006+
auto *HalfVecTy = VectorType::getHalfElementsVectorType(VecTy);
4007+
return ConstantStruct::get(StTy, ConstantAggregateZero::get(HalfVecTy),
4008+
ConstantAggregateZero::get(HalfVecTy));
40124009
}
4013-
return ConstantStruct::get(StTy, ConstantVector::get(Res0),
4014-
ConstantVector::get(Res1));
4010+
if (isa<FixedVectorType>(Vec->getType())) {
4011+
for (unsigned I = 0; I < NumElements; ++I) {
4012+
Constant *Elt0 = Vec->getAggregateElement(2 * I);
4013+
Constant *Elt1 = Vec->getAggregateElement(2 * I + 1);
4014+
if (!Elt0 || !Elt1)
4015+
return nullptr;
4016+
Res0[I] = Elt0;
4017+
Res1[I] = Elt1;
4018+
}
4019+
return ConstantStruct::get(StTy, ConstantVector::get(Res0),
4020+
ConstantVector::get(Res1));
4021+
}
4022+
return nullptr;
40154023
}
40164024
default:
40174025
// TODO: Constant folding of vector intrinsics that fall through here does

0 commit comments

Comments
 (0)