[llvm] 529eafd - [SROA] `isVectorPromotionViable()`: integer-ify non-pointer non-common types

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 22 13:23:35 PST 2022


Author: Roman Lebedev
Date: 2022-11-23T00:23:00+03:00
New Revision: 529eafd9beff233ba8debfc73e0b5c04cac36835

URL: https://github.com/llvm/llvm-project/commit/529eafd9beff233ba8debfc73e0b5c04cac36835
DIFF: https://github.com/llvm/llvm-project/commit/529eafd9beff233ba8debfc73e0b5c04cac36835.diff

LOG: [SROA] `isVectorPromotionViable()`: integer-ify non-pointer non-common types

This rectifies a FIXME that dates all the way back
to 2014 about not doing so due to the backend issues.

Presumably sufficient amount of time has passes
and all the known issues have been addressed,
or at least we will find out of there are some left...

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/SROA.cpp
    llvm/test/Transforms/SROA/vector-promotion.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index 74bdfda3434b..0d045656661a 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -1953,17 +1953,12 @@ static VectorType *isVectorPromotionViable(Partition &P, const DataLayout &DL) {
     CandidateTys.clear();
     CandidateTys.push_back(CommonVecPtrTy);
   } else if (!HaveCommonEltTy && !HaveVecPtrTy) {
-    // Remove non-integer vector types if we had multiple common element types.
-    // FIXME: It'd be nice to replace them with integer vector types, but we
-    // can't do that until all the backends are known to produce good code for
-    // all integer vector types.
-    llvm::erase_if(CandidateTys, [](VectorType *VTy) {
-      return !VTy->getElementType()->isIntegerTy();
-    });
-
-    // If there were no integer vector types, give up.
-    if (CandidateTys.empty())
-      return nullptr;
+    // Integer-ify vector types.
+    for (VectorType *&VTy : CandidateTys) {
+      if (!VTy->getElementType()->isIntegerTy())
+        VTy = cast<VectorType>(VTy->getWithNewType(IntegerType::getIntNTy(
+            VTy->getContext(), VTy->getScalarSizeInBits())));
+    }
 
     // Rank the remaining candidate vector types. This is easy because we know
     // they're all integer vectors. We sort by ascending number of elements.

diff  --git a/llvm/test/Transforms/SROA/vector-promotion.ll b/llvm/test/Transforms/SROA/vector-promotion.ll
index aed0d50e0fcc..1447bedb92d0 100644
--- a/llvm/test/Transforms/SROA/vector-promotion.ll
+++ b/llvm/test/Transforms/SROA/vector-promotion.ll
@@ -534,10 +534,9 @@ define <2 x float> @test11(<4 x i16> %x, i32 %y) {
 ; heuristic for making a deterministic decision.
 ; CHECK-LABEL: @test11(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:    [[TMP0:%.*]] = bitcast i32 [[Y:%.*]] to <2 x i16>
-; CHECK-NEXT:    [[A_SROA_0_4_VEC_EXPAND:%.*]] = shufflevector <2 x i16> [[TMP0]], <2 x i16> poison, <4 x i32> <i32 undef, i32 undef, i32 0, i32 1>
-; CHECK-NEXT:    [[A_SROA_0_4_VECBLEND:%.*]] = select <4 x i1> <i1 false, i1 false, i1 true, i1 true>, <4 x i16> [[A_SROA_0_4_VEC_EXPAND]], <4 x i16> [[X:%.*]]
-; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <4 x i16> [[A_SROA_0_4_VECBLEND]] to <2 x float>
+; CHECK-NEXT:    [[TMP0:%.*]] = bitcast <4 x i16> [[X:%.*]] to <2 x i32>
+; CHECK-NEXT:    [[A_SROA_0_4_VEC_INSERT:%.*]] = insertelement <2 x i32> [[TMP0]], i32 [[Y:%.*]], i32 1
+; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <2 x i32> [[A_SROA_0_4_VEC_INSERT]] to <2 x float>
 ; CHECK-NEXT:    ret <2 x float> [[TMP1]]
 ;
 entry:


        


More information about the llvm-commits mailing list