Skip to content

Commit 9143867

Browse files
committed
solve regression
1 parent 19033e9 commit 9143867

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5230,12 +5230,28 @@ AllocaInst *SROA::rewritePartition(AllocaInst &AI, AllocaSlices &AS,
52305230
SliceTy = ArrayType::get(Type::getInt8Ty(*C), P.size());
52315231
assert(DL.getTypeAllocSize(SliceTy).getFixedValue() >= P.size());
52325232

5233-
bool IsIntegerPromotable = isIntegerWideningViable(P, SliceTy, DL);
5234-
5235-
VectorType *VecTy =
5236-
IsIntegerPromotable ? nullptr : isVectorPromotionViable(P, DL, VScale);
5237-
if (VecTy)
5238-
SliceTy = VecTy;
5233+
// Prefer vector promotion over integer widening for floating-point vectors
5234+
// because it is more likely the user is just accessing whole vector elements
5235+
// and not doing bitsise arithmetic.
5236+
bool PreferVectorPromotion = false;
5237+
if (auto *FixedVecSliceTy = dyn_cast<FixedVectorType>(SliceTy))
5238+
PreferVectorPromotion = FixedVecSliceTy->getElementType()->isFloatingPointTy();
5239+
5240+
bool IsIntegerPromotable = false;
5241+
VectorType *VecTy = nullptr;
5242+
5243+
if (PreferVectorPromotion) {
5244+
// For float vectors, try vector promotion first
5245+
VecTy = isVectorPromotionViable(P, DL, VScale);
5246+
if (!VecTy)
5247+
IsIntegerPromotable = isIntegerWideningViable(P, SliceTy, DL);
5248+
} else {
5249+
// For integer vectors (especially small integers like i8), try integer
5250+
// widening first as InstCombine can optimize the resulting operations
5251+
IsIntegerPromotable = isIntegerWideningViable(P, SliceTy, DL);
5252+
if (!IsIntegerPromotable)
5253+
VecTy = isVectorPromotionViable(P, DL, VScale);
5254+
}
52395255

52405256
// Check for the case where we're going to rewrite to a new alloca of the
52415257
// exact same type as the original, and with the same access offsets. In that

0 commit comments

Comments
 (0)