Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions llvm/lib/Transforms/Vectorize/VectorCombine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2014,12 +2014,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 *LShr = Builder.CreateLShr(ScalarV, ShiftAmt);
Value *And = Builder.CreateAnd(LShr, Mask);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format this bit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done thanks

U->replaceAllUsesWith(And);
}
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes='vector-combine' -S -mtriple=aarch64-unknown-linux-gnu %s -o - | FileCheck %s --check-prefix=LE
; RUN: opt -passes='vector-combine' -S -mtriple=aarch64_be-unknown-linux-gnu %s -o - | FileCheck %s --check-prefix=BE

define i64 @g(<8 x i8> %v) {
; LE-LABEL: @g(
; LE-NEXT: [[TMP1:%.*]] = freeze <8 x i8> [[V:%.*]]
; LE-NEXT: [[TMP2:%.*]] = bitcast <8 x i8> [[TMP1]] to i64
; LE-NEXT: [[TMP3:%.*]] = lshr i64 [[TMP2]], 56
; LE-NEXT: [[TMP4:%.*]] = and i64 [[TMP2]], 255
; LE-NEXT: [[Z:%.*]] = zext <8 x i8> [[V]] to <8 x i64>
; LE-NEXT: [[E0:%.*]] = extractelement <8 x i64> [[Z]], i32 0
; LE-NEXT: [[E7:%.*]] = extractelement <8 x i64> [[Z]], i32 7
; LE-NEXT: [[SUM:%.*]] = add i64 [[TMP4]], [[TMP3]]
; LE-NEXT: ret i64 [[SUM]]
;
; BE-LABEL: @g(
; BE-NEXT: [[TMP1:%.*]] = freeze <8 x i8> [[V:%.*]]
; BE-NEXT: [[TMP2:%.*]] = bitcast <8 x i8> [[TMP1]] to i64
; BE-NEXT: [[TMP3:%.*]] = and i64 [[TMP2]], 255
; BE-NEXT: [[TMP4:%.*]] = lshr i64 [[TMP2]], 56
; BE-NEXT: [[Z:%.*]] = zext <8 x i8> [[V]] to <8 x i64>
; BE-NEXT: [[E0:%.*]] = extractelement <8 x i64> [[Z]], i32 0
; BE-NEXT: [[E7:%.*]] = extractelement <8 x i64> [[Z]], i32 7
; BE-NEXT: [[SUM:%.*]] = add i64 [[TMP4]], [[TMP3]]
; BE-NEXT: ret i64 [[SUM]]
;
%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
}



2 changes: 2 additions & 0 deletions llvm/test/Transforms/VectorCombine/PowerPC/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
if 'PowerPC' not in config.root.targets:
config.unsupported = True
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes='vector-combine' -S -mtriple=powerpc64-ibm-aix-xcoff %s -o - | FileCheck %s --check-prefix=BE

define i64 @g(<8 x i8> %v) {
; BE-LABEL: @g(
; BE-NEXT: [[TMP1:%.*]] = freeze <8 x i8> [[V:%.*]]
; BE-NEXT: [[TMP2:%.*]] = bitcast <8 x i8> [[TMP1]] to i64
; BE-NEXT: [[TMP3:%.*]] = and i64 [[TMP2]], 255
; BE-NEXT: [[TMP4:%.*]] = lshr i64 [[TMP2]], 56
; BE-NEXT: [[Z:%.*]] = zext <8 x i8> [[V]] to <8 x i64>
; BE-NEXT: [[E0:%.*]] = extractelement <8 x i64> [[Z]], i32 0
; BE-NEXT: [[E7:%.*]] = extractelement <8 x i64> [[Z]], i32 7
; BE-NEXT: [[SUM:%.*]] = add i64 [[TMP4]], [[TMP3]]
; BE-NEXT: ret i64 [[SUM]]
;
%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
}

Loading