-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[VectorCombine] Fix scalarizeExtExtract for big-endian #157962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
1e1ef6c
8f8e444
75d1625
d4a1421
97ebb99
fd77ffb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2011,12 +2011,19 @@ bool VectorCombine::scalarizeExtExtract(Instruction &I) { | |
IntegerType::get(SrcTy->getContext(), DL->getTypeSizeInBits(SrcTy))); | ||
uint64_t SrcEltSizeInBits = DL->getTypeSizeInBits(SrcTy->getElementType()); | ||
uint64_t EltBitMask = (1ull << SrcEltSizeInBits) - 1; | ||
uint64_t TotalBits = DL->getTypeSizeInBits(SrcTy); | ||
Type *PackedTy = IntegerType::get(SrcTy->getContext(), TotalBits); | ||
Value *Mask = ConstantInt::get(PackedTy, EltBitMask); | ||
for (User *U : Ext->users()) { | ||
auto *Extract = cast<ExtractElementInst>(U); | ||
uint64_t Idx = | ||
cast<ConstantInt>(Extract->getIndexOperand())->getZExtValue(); | ||
Value *LShr = Builder.CreateLShr(ScalarV, Idx * SrcEltSizeInBits); | ||
Value *And = Builder.CreateAnd(LShr, EltBitMask); | ||
uint64_t ShiftAmt = DL->isBigEndian() | ||
? (TotalBits - SrcEltSizeInBits - Idx * SrcEltSizeInBits) | ||
: (Idx * SrcEltSizeInBits); | ||
Value *ShAmtVal = ConstantInt::get(PackedTy, ShiftAmt); | ||
Value *LShr = Builder.CreateLShr(ScalarV, ShAmtVal); | ||
Value *And = Builder.CreateAnd(LShr, Mask); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-format this bit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done thanks |
||
U->replaceAllUsesWith(And); | ||
} | ||
return true; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
; RUN: opt -passes='vector-combine,dce' -S -mtriple=aarch64-unknown-linux-gnu %s -o - | FileCheck %s --check-prefix=LE | ||
|
||
; RUN: opt -passes='vector-combine,dce' -S -mtriple=powerpc64-ibm-aix-xcoff %s -o - | FileCheck %s --check-prefix=BE | ||
|
||
define i64 @g(<8 x i8> %v) { | ||
%z = zext <8 x i8> %v to <8 x i64> | ||
%e0 = extractelement <8 x i64> %z, i32 0 | ||
%e7 = extractelement <8 x i64> %z, i32 7 | ||
%sum = add i64 %e0, %e7 | ||
ret i64 %sum | ||
} | ||
|
||
; LE-LABEL: @g( | ||
; LE: bitcast <8 x i8> %{{.*}} to i64 | ||
; LE: lshr i64 %{{.*}}, 56 | ||
; LE: and i64 %{{.*}}, 255 | ||
; LE-NOT: extractelement | ||
|
||
; BE-LABEL: @g( | ||
; BE: bitcast <8 x i8> %{{.*}} to i64 | ||
; BE: and i64 %{{.*}}, 255 | ||
; BE: lshr i64 %{{.*}}, 56 | ||
; BE-NOT: extractelement | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we use
CreateLShr(ScalarV, ShiftAmt)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I've updated the branch to use this instead