[llvm] 20542b4 - [VectorCombine] scalarizeLoadExtract(): use computeAlignmentAfterScalarization() helper

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 11 02:47:42 PDT 2021


Author: Roman Lebedev
Date: 2021-06-11T12:47:10+03:00
New Revision: 20542b47d6373dde497987abd1da83e84983fe13

URL: https://github.com/llvm/llvm-project/commit/20542b47d6373dde497987abd1da83e84983fe13
DIFF: https://github.com/llvm/llvm-project/commit/20542b47d6373dde497987abd1da83e84983fe13.diff

LOG: [VectorCombine] scalarizeLoadExtract(): use computeAlignmentAfterScalarization() helper

This results in slightly more optimistic alignments in some cases

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/VectorCombine.cpp
    llvm/test/Transforms/VectorCombine/AArch64/load-extractelement-scalarization.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index affe4e82eb576..43a2172267435 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -936,15 +936,10 @@ bool VectorCombine::scalarizeLoadExtract(Instruction &I) {
     auto *NewLoad = cast<LoadInst>(Builder.CreateLoad(
         FixedVT->getElementType(), GEP, EI->getName() + ".scalar"));
 
-    // Set the alignment for the new load. For index 0, we can use the original
-    // alignment. Otherwise choose the common alignment of the load's align and
-    // the alignment for the scalar type.
-    auto *ConstIdx = dyn_cast<ConstantInt>(EI->getOperand(1));
-    if (ConstIdx && ConstIdx->isNullValue())
-      NewLoad->setAlignment(LI->getAlign());
-    else
-      NewLoad->setAlignment(commonAlignment(
-          DL.getABITypeAlign(NewLoad->getType()), LI->getAlign()));
+    Align ScalarOpAlignment = computeAlignmentAfterScalarization(
+        LI->getAlign(), FixedVT->getElementType(), Idx, DL);
+    NewLoad->setAlignment(ScalarOpAlignment);
+
     replaceValue(*EI, *NewLoad);
   }
 

diff  --git a/llvm/test/Transforms/VectorCombine/AArch64/load-extractelement-scalarization.ll b/llvm/test/Transforms/VectorCombine/AArch64/load-extractelement-scalarization.ll
index e603b2070ecd9..35777eec4f8d9 100644
--- a/llvm/test/Transforms/VectorCombine/AArch64/load-extractelement-scalarization.ll
+++ b/llvm/test/Transforms/VectorCombine/AArch64/load-extractelement-scalarization.ll
@@ -41,7 +41,7 @@ define i32 @load_extract_idx_1(<4 x i32>* %x) {
 define i32 @load_extract_idx_2(<4 x i32>* %x) {
 ; CHECK-LABEL: @load_extract_idx_2(
 ; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds <4 x i32>, <4 x i32>* [[X:%.*]], i32 0, i32 2
-; CHECK-NEXT:    [[R:%.*]] = load i32, i32* [[TMP1]], align 4
+; CHECK-NEXT:    [[R:%.*]] = load i32, i32* [[TMP1]], align 8
 ; CHECK-NEXT:    ret i32 [[R]]
 ;
   %lv = load <4 x i32>, <4 x i32>* %x
@@ -252,7 +252,7 @@ define i32 @load_extract_clobber_call_before(<4 x i32>* %x) {
 ; CHECK-LABEL: @load_extract_clobber_call_before(
 ; CHECK-NEXT:    call void @clobber()
 ; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds <4 x i32>, <4 x i32>* [[X:%.*]], i32 0, i32 2
-; CHECK-NEXT:    [[R:%.*]] = load i32, i32* [[TMP1]], align 4
+; CHECK-NEXT:    [[R:%.*]] = load i32, i32* [[TMP1]], align 8
 ; CHECK-NEXT:    ret i32 [[R]]
 ;
   call void @clobber()
@@ -277,7 +277,7 @@ define i32 @load_extract_clobber_call_between(<4 x i32>* %x) {
 define i32 @load_extract_clobber_call_after(<4 x i32>* %x) {
 ; CHECK-LABEL: @load_extract_clobber_call_after(
 ; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds <4 x i32>, <4 x i32>* [[X:%.*]], i32 0, i32 2
-; CHECK-NEXT:    [[R:%.*]] = load i32, i32* [[TMP1]], align 4
+; CHECK-NEXT:    [[R:%.*]] = load i32, i32* [[TMP1]], align 8
 ; CHECK-NEXT:    call void @clobber()
 ; CHECK-NEXT:    ret i32 [[R]]
 ;
@@ -291,7 +291,7 @@ define i32 @load_extract_clobber_store_before(<4 x i32>* %x, i8* %y) {
 ; CHECK-LABEL: @load_extract_clobber_store_before(
 ; CHECK-NEXT:    store i8 0, i8* [[Y:%.*]], align 1
 ; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds <4 x i32>, <4 x i32>* [[X:%.*]], i32 0, i32 2
-; CHECK-NEXT:    [[R:%.*]] = load i32, i32* [[TMP1]], align 4
+; CHECK-NEXT:    [[R:%.*]] = load i32, i32* [[TMP1]], align 8
 ; CHECK-NEXT:    ret i32 [[R]]
 ;
   store i8 0, i8* %y
@@ -358,7 +358,7 @@ define i32 @load_extract_clobber_store_after_limit(<4 x i32>* %x, i8* %y, <8 x i
 ; LIMIT-DEFAULT-NEXT:    [[Z_4:%.*]] = extractelement <8 x i32> [[Z]], i32 4
 ; LIMIT-DEFAULT-NEXT:    [[ADD_3:%.*]] = add i32 [[ADD_2]], [[Z_4]]
 ; LIMIT-DEFAULT-NEXT:    [[TMP1:%.*]] = getelementptr inbounds <4 x i32>, <4 x i32>* [[X:%.*]], i32 0, i32 2
-; LIMIT-DEFAULT-NEXT:    [[R:%.*]] = load i32, i32* [[TMP1]], align 4
+; LIMIT-DEFAULT-NEXT:    [[R:%.*]] = load i32, i32* [[TMP1]], align 8
 ; LIMIT-DEFAULT-NEXT:    store i8 0, i8* [[Y:%.*]], align 1
 ; LIMIT-DEFAULT-NEXT:    [[ADD_4:%.*]] = add i32 [[ADD_3]], [[R]]
 ; LIMIT-DEFAULT-NEXT:    ret i32 [[ADD_4]]
@@ -454,7 +454,7 @@ define i32 @load_multiple_extracts_with_constant_idx_profitable(<8 x i32>* %x) {
 ; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds <8 x i32>, <8 x i32>* [[X:%.*]], i32 0, i32 0
 ; CHECK-NEXT:    [[E_0:%.*]] = load i32, i32* [[TMP1]], align 16
 ; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds <8 x i32>, <8 x i32>* [[X]], i32 0, i32 6
-; CHECK-NEXT:    [[E_1:%.*]] = load i32, i32* [[TMP2]], align 4
+; CHECK-NEXT:    [[E_1:%.*]] = load i32, i32* [[TMP2]], align 8
 ; CHECK-NEXT:    [[RES:%.*]] = add i32 [[E_0]], [[E_1]]
 ; CHECK-NEXT:    ret i32 [[RES]]
 ;


        


More information about the llvm-commits mailing list