Skip to content

Commit 6c1c97c

Browse files
committed
[InstCombine][X86] Peek through bitcast+shuffle+bitcast sequence when folding BLENDV to SELECT
Mentioned on #96882
1 parent 0488f21 commit 6c1c97c

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,6 +2882,8 @@ X86TTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
28822882
return SelectInst::Create(NewSelector, Op1, Op0, "blendv");
28832883
}
28842884

2885+
Mask = InstCombiner::peekThroughBitcast(Mask);
2886+
28852887
// Peek through a one-use shuffle - VectorCombine should have simplified
28862888
// this for cases where we're splitting wider vectors to use blendv
28872889
// intrinsics.
@@ -2895,13 +2897,12 @@ X86TTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
28952897
any_of(ShuffleMask,
28962898
[NumElts](int M) { return M < 0 || M >= NumElts; }))
28972899
break;
2898-
Mask = MaskSrc;
2900+
Mask = InstCombiner::peekThroughBitcast(MaskSrc);
28992901
}
29002902

29012903
// Convert to a vector select if we can bypass casts and find a boolean
29022904
// vector condition value.
29032905
Value *BoolVec;
2904-
Mask = InstCombiner::peekThroughBitcast(Mask);
29052906
if (match(Mask, m_SExt(m_Value(BoolVec))) &&
29062907
BoolVec->getType()->isVectorTy() &&
29072908
BoolVec->getType()->getScalarSizeInBits() == 1) {

llvm/test/Transforms/InstCombine/X86/blend_x86.ll

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,13 @@ define <2 x i64> @sel_v16i8_sse_reality(ptr nocapture readonly %x, <2 x i64> %y,
285285
define <4 x float> @sel_v16i8_bitcast_shuffle_bitcast_cmp(<8 x float> %a, <8 x float> %b, <8 x float> %c, <8 x float> %d) {
286286
; CHECK-LABEL: @sel_v16i8_bitcast_shuffle_bitcast_cmp(
287287
; CHECK-NEXT: [[CMP:%.*]] = fcmp olt <8 x float> [[A:%.*]], [[B:%.*]]
288-
; CHECK-NEXT: [[SEXT:%.*]] = sext <8 x i1> [[CMP]] to <8 x i32>
289288
; CHECK-NEXT: [[A_BC:%.*]] = bitcast <8 x float> [[A]] to <8 x i32>
290289
; CHECK-NEXT: [[B_BC:%.*]] = bitcast <8 x float> [[B]] to <8 x i32>
291-
; CHECK-NEXT: [[SEXT_LO:%.*]] = shufflevector <8 x i32> [[SEXT]], <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
292290
; CHECK-NEXT: [[A_LO:%.*]] = shufflevector <8 x i32> [[A_BC]], <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
293291
; CHECK-NEXT: [[B_LO:%.*]] = shufflevector <8 x i32> [[B_BC]], <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
294-
; CHECK-NEXT: [[A_LO_BC:%.*]] = bitcast <4 x i32> [[A_LO]] to <16 x i8>
295-
; CHECK-NEXT: [[B_LO_BC:%.*]] = bitcast <4 x i32> [[B_LO]] to <16 x i8>
296-
; CHECK-NEXT: [[SEXT_LO_BC:%.*]] = bitcast <4 x i32> [[SEXT_LO]] to <16 x i8>
297-
; CHECK-NEXT: [[BLENDV:%.*]] = call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> [[A_LO_BC]], <16 x i8> [[B_LO_BC]], <16 x i8> [[SEXT_LO_BC]])
298-
; CHECK-NEXT: [[RES:%.*]] = bitcast <16 x i8> [[BLENDV]] to <4 x float>
292+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i1> [[CMP]], <8 x i1> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
293+
; CHECK-NEXT: [[TMP2:%.*]] = select <4 x i1> [[TMP1]], <4 x i32> [[B_LO]], <4 x i32> [[A_LO]]
294+
; CHECK-NEXT: [[RES:%.*]] = bitcast <4 x i32> [[TMP2]] to <4 x float>
299295
; CHECK-NEXT: ret <4 x float> [[RES]]
300296
;
301297
%cmp = fcmp olt <8 x float> %a, %b

0 commit comments

Comments
 (0)