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
4 changes: 3 additions & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2904,7 +2904,9 @@ Instruction *InstCombinerImpl::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
if (auto *SI = dyn_cast<SelectInst>(LHS)) {
// We cannot do this fold for elementwise select since ShuffleVector is
// not elementwise.
if (SI->getCondition()->getType()->isIntegerTy()) {
if (SI->getCondition()->getType()->isIntegerTy() &&
(isa<PoisonValue>(RHS) ||
isGuaranteedNotToBePoison(SI->getCondition()))) {
if (Instruction *I = FoldOpIntoSelect(SVI, SI))
return I;
}
Expand Down
12 changes: 12 additions & 0 deletions llvm/test/Transforms/InstCombine/vec_shuffle.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2411,6 +2411,18 @@ define <4 x i32> @shuf_same_length_vec_select(<4 x i1> %cond) {
ret <4 x i32> %shuf
}

; Make sure we do not fold in this case.
define <4 x i8> @shuf_cmp_may_be_poison(<4 x i8> %x, <4 x i8> %y, i1 %cmp) {
; CHECK-LABEL: @shuf_cmp_may_be_poison(
; CHECK-NEXT: [[Y:%.*]] = select i1 [[CMP:%.*]], <4 x i8> [[Y1:%.*]], <4 x i8> <i8 0, i8 poison, i8 0, i8 poison>
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i8> [[Y]], <4 x i8> <i8 poison, i8 1, i8 poison, i8 3>, <4 x i32> <i32 0, i32 5, i32 2, i32 7>
; CHECK-NEXT: ret <4 x i8> [[TMP1]]
;
%sel = select i1 %cmp, <4 x i8> %y, <4 x i8> <i8 0, i8 poison, i8 0, i8 poison>
%shuf = shufflevector <4 x i8> %sel, <4 x i8> <i8 poison, i8 1, i8 poison, i8 3>, <4 x i32> <i32 0, i32 5, i32 2, i32 7>
ret <4 x i8> %shuf
}

declare i1 @cond()
declare <4 x i32> @value()

Expand Down
Loading