Skip to content

Commit bceb357

Browse files
author
Leon Clark
committed
Remove redundant code and update tests.
1 parent 204d4bf commit bceb357

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3767,29 +3767,21 @@ bool VectorCombine::shrinkLoadForShuffles(Instruction &I) {
37673767

37683768
using UseEntry = std::pair<ShuffleVectorInst *, std::vector<int>>;
37693769
SmallVector<UseEntry, 4u> NewUses;
3770-
unsigned const SizeDiff = OldNumElements - NewNumElements;
37713770

37723771
for (llvm::Use &Use : I.uses()) {
37733772
auto *Shuffle = cast<ShuffleVectorInst>(Use.getUser());
37743773
ArrayRef<int> OldMask = Shuffle->getShuffleMask();
37753774

37763775
// Create entry for new use.
3777-
NewUses.push_back({Shuffle, {}});
3778-
std::vector<int> &NewMask = NewUses.back().second;
3779-
for (int Index : OldMask) {
3780-
assert(Index <= Indices->second);
3781-
NewMask.push_back(Index >= static_cast<int>(OldNumElements)
3782-
? Index - SizeDiff
3783-
: Index);
3784-
}
3776+
NewUses.push_back({Shuffle, OldMask});
37853777

37863778
// Update costs.
37873779
OldCost +=
37883780
TTI.getShuffleCost(TTI::SK_PermuteSingleSrc, Shuffle->getType(),
37893781
OldLoadTy, OldMask, CostKind);
37903782
NewCost +=
37913783
TTI.getShuffleCost(TTI::SK_PermuteSingleSrc, Shuffle->getType(),
3792-
NewLoadTy, NewMask, CostKind);
3784+
NewLoadTy, OldMask, CostKind);
37933785
}
37943786

37953787
LLVM_DEBUG(

llvm/test/Transforms/VectorCombine/load-shufflevector.ll

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,36 @@ finally:
357357
%val3 = phi <8 x i32> [ %val1, %then ], [ %val2, %else ]
358358
ret <8 x i32> %val3
359359
}
360+
361+
define <8 x i32> @shuffle_v4_v8i32_cond_r1_4(ptr addrspace(1) nocapture readonly %arg0, i1 %cond) local_unnamed_addr {
362+
; CHECK-LABEL: define <8 x i32> @shuffle_v4_v8i32_cond_r1_4(
363+
; CHECK-SAME: ptr addrspace(1) readonly captures(none) [[ARG0:%.*]], i1 [[COND:%.*]]) local_unnamed_addr {
364+
; CHECK-NEXT: [[ENTRY:.*:]]
365+
; CHECK-NEXT: [[VAL0:%.*]] = load <4 x i32>, ptr addrspace(1) [[ARG0]], align 32
366+
; CHECK-NEXT: br i1 [[COND]], label %[[THEN:.*]], label %[[ELSE:.*]]
367+
; CHECK: [[THEN]]:
368+
; CHECK-NEXT: [[VAL1:%.*]] = shufflevector <4 x i32> [[VAL0]], <4 x i32> poison, <8 x i32> <i32 1, i32 1, i32 1, i32 1, i32 2, i32 2, i32 2, i32 2>
369+
; CHECK-NEXT: br label %[[FINALLY:.*]]
370+
; CHECK: [[ELSE]]:
371+
; CHECK-NEXT: [[VAL2:%.*]] = shufflevector <4 x i32> [[VAL0]], <4 x i32> poison, <8 x i32> <i32 3, i32 3, i32 3, i32 3, i32 4, i32 4, i32 4, i32 4>
372+
; CHECK-NEXT: br label %[[FINALLY]]
373+
; CHECK: [[FINALLY]]:
374+
; CHECK-NEXT: [[VAL3:%.*]] = phi <8 x i32> [ [[VAL1]], %[[THEN]] ], [ [[VAL2]], %[[ELSE]] ]
375+
; CHECK-NEXT: ret <8 x i32> [[VAL3]]
376+
;
377+
entry:
378+
%val0 = load <4 x i32>, ptr addrspace(1) %arg0, align 32
379+
br i1 %cond, label %then, label %else
380+
381+
then:
382+
%val1 = shufflevector <4 x i32> %val0, <4 x i32> poison, <8 x i32> <i32 1, i32 1, i32 1, i32 1, i32 2, i32 2, i32 2, i32 2>
383+
br label %finally
384+
385+
else:
386+
%val2 = shufflevector <4 x i32> %val0, <4 x i32> poison, <8 x i32> <i32 3, i32 3, i32 3, i32 3, i32 4, i32 4, i32 4, i32 4>
387+
br label %finally
388+
389+
finally:
390+
%val3 = phi <8 x i32> [ %val1, %then ], [ %val2, %else ]
391+
ret <8 x i32> %val3
392+
}

0 commit comments

Comments
 (0)