================
@@ -5191,47 +5192,95 @@ bool SROA::presplitLoadsAndStores(AllocaInst &AI,
AllocaSlices &AS) {
/// promoted.
AllocaInst *SROA::rewritePartition(AllocaInst &AI, AllocaSlices &AS,
Partition &P) {
+ const DataLayout &DL = AI.getDataLayout();
// Try to compute a friendly type for this partition of the alloca. This
// won't always succeed, in which case we fall back to a legal integer type
// or an i8 array of an appropriate size.
- Type *SliceTy = nullptr;
- const DataLayout &DL = AI.getDataLayout();
- unsigned VScale = AI.getFunction()->getVScaleValue();
-
- std::pair<Type *, IntegerType *> CommonUseTy =
- findCommonType(P.begin(), P.end(), P.endOffset());
- // Do all uses operate on the same type?
- if (CommonUseTy.first) {
- TypeSize CommonUseSize = DL.getTypeAllocSize(CommonUseTy.first);
- if (CommonUseSize.isFixed() && CommonUseSize.getFixedValue() >= P.size())
- SliceTy = CommonUseTy.first;
- }
- // If not, can we find an appropriate subtype in the original allocated type?
- if (!SliceTy)
+ //
+ // Returns a tuple with the following elements:
+ // - PartitionType: The computed type for this partition.
+ // - IsIntegerWideningViable: True if integer widening promotion is used.
+ // - VectorType: The vector type if vector promotion is used, otherwise
+ // nullptr.
+ auto SelectPartitionTy = [&]() -> std::tuple<Type *, bool, VectorType *> {
+ // First check if the partition is viable for vetor promotion.
+ //
+ // We prefer vector promotion over integer widening promotion when:
+ // - The vector element type is a floating-point type.
+ // - All the loads/stores to the alloca are vector loads/stores to the
+ // entire alloca.
+ //
+ // Otherwise when there is a integer vector with mixed
+ // loads/stores we prefer integer widening promotion because it's more
+ // likely the user is doing bitwise arithmetic and we generate better code.
+ VectorType *VecTy =
+ isVectorPromotionViable(P, DL, AI.getFunction()->getVScaleValue());
+ // If the vector element type is a floating-point type, we prefer vector
+ // promotion. If the vector has one element, let the below code select
+ // whether we promote with the vector or scalar.
+ if (VecTy && VecTy->getElementType()->isFloatingPointTy() &&
+ VecTy->getElementCount().getFixedValue() > 1)
+ return {VecTy, false, VecTy};
+
+ // Check if there is a common type that all slices of the partition use
that
+ // spans the partition.
+ auto [CommonUseTy, LargestIntTy] =
+ findCommonType(P.begin(), P.end(), P.endOffset());
+ if (CommonUseTy) {
+ TypeSize CommonUseSize = DL.getTypeAllocSize(CommonUseTy);
+ if (CommonUseSize.isFixed() &&
+ CommonUseSize.getFixedValue() >= P.size()) {
+ // We prefer vector promotion here because if vector promotion is
viable
+ // and there is a common type used, then it implies the second listed
+ // condition for prefering vector promotion is true.
----------------
nikic wrote:
```suggestion
// condition for preferring vector promotion is true.
```
https://github.com/llvm/llvm-project/pull/167771
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits