File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
test/Transforms/VectorCombine Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -2011,12 +2011,19 @@ bool VectorCombine::scalarizeExtExtract(Instruction &I) {
20112011 IntegerType::get (SrcTy->getContext (), DL->getTypeSizeInBits (SrcTy)));
20122012 uint64_t SrcEltSizeInBits = DL->getTypeSizeInBits (SrcTy->getElementType ());
20132013 uint64_t EltBitMask = (1ull << SrcEltSizeInBits) - 1 ;
2014+ uint64_t TotalBits = DL->getTypeSizeInBits (SrcTy);
2015+ Type *PackedTy = IntegerType::get (SrcTy->getContext (), TotalBits);
2016+ Value *Mask = ConstantInt::get (PackedTy, EltBitMask);
20142017 for (User *U : Ext->users ()) {
20152018 auto *Extract = cast<ExtractElementInst>(U);
20162019 uint64_t Idx =
20172020 cast<ConstantInt>(Extract->getIndexOperand ())->getZExtValue ();
2018- Value *LShr = Builder.CreateLShr (ScalarV, Idx * SrcEltSizeInBits);
2019- Value *And = Builder.CreateAnd (LShr, EltBitMask);
2021+ uint64_t ShiftAmt = DL->isBigEndian ()
2022+ ? (TotalBits - SrcEltSizeInBits - Idx * SrcEltSizeInBits)
2023+ : (Idx * SrcEltSizeInBits);
2024+ Value *ShAmtVal = ConstantInt::get (PackedTy, ShiftAmt);
2025+ Value *LShr = Builder.CreateLShr (ScalarV, ShAmtVal);
2026+ Value *And = Builder.CreateAnd (LShr, Mask);
20202027 U->replaceAllUsesWith (And);
20212028 }
20222029 return true ;
Original file line number Diff line number Diff line change 1+ ; RUN: opt -passes='vector-combine,dce' -S -mtriple=aarch64-unknown-linux-gnu %s -o - | FileCheck %s --check-prefix=LE
2+ ; RUN: opt -passes='vector-combine,dce' -S -mtriple=powerpc64-ibm-aix-xcoff %s -o - | FileCheck %s --check-prefix=BE
3+
4+ define i64 @g (<8 x i8 > %v ) {
5+ %z = zext <8 x i8 > %v to <8 x i64 >
6+ %e0 = extractelement <8 x i64 > %z , i32 0
7+ %e7 = extractelement <8 x i64 > %z , i32 7
8+ %sum = add i64 %e0 , %e7
9+ ret i64 %sum
10+ }
11+
12+ ; LE-LABEL: @g(
13+ ; LE: bitcast <8 x i8> %{{.*}} to i64
14+ ; LE: lshr i64 %{{.*}}, 56
15+ ; LE: and i64 %{{.*}}, 255
16+ ; LE-NOT: extractelement
17+
18+ ; BE-LABEL: @g(
19+ ; BE: bitcast <8 x i8> %{{.*}} to i64
20+ ; BE: and i64 %{{.*}}, 255
21+ ; BE: lshr i64 %{{.*}}, 56
22+ ; BE-NOT: extractelement
23+
You can’t perform that action at this time.
0 commit comments