Skip to content

Commit 14d0d1f

Browse files
DylanFleming-armtstellar
authored andcommitted
[InstCombine] Fixed select + masked load fold failure
Fixed type assertion failure caused by trying to fold a masked load with a select where the select condition is a scalar value Reviewed By: sdesmalen, lebedev.ri Differential Revision: https://reviews.llvm.org/D107372 (cherry picked from commit 3943a74)
1 parent 37e964d commit 14d0d1f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3230,7 +3230,8 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
32303230
Value *Mask;
32313231
if (match(TrueVal, m_Zero()) &&
32323232
match(FalseVal, m_MaskedLoad(m_Value(), m_Value(), m_Value(Mask),
3233-
m_CombineOr(m_Undef(), m_Zero())))) {
3233+
m_CombineOr(m_Undef(), m_Zero()))) &&
3234+
(CondVal->getType() == Mask->getType())) {
32343235
// We can remove the select by ensuring the load zeros all lanes the
32353236
// select would have. We determine this by proving there is no overlap
32363237
// between the load and select masks.

llvm/test/Transforms/InstCombine/select-masked_load.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,18 @@ define <4 x float> @masked_load_and_zero_inactive_8(<4 x float>* %ptr, <4 x i1>
9494
ret <4 x float> %masked
9595
}
9696

97+
define <8 x float> @masked_load_and_scalar_select_cond(<8 x float>* %ptr, <8 x i1> %mask, i1 %cond) {
98+
; CHECK-LABEL: @masked_load_and_scalar_select_cond(
99+
; CHECK-NEXT: entry:
100+
; CHECK-NEXT: [[TMP0:%.*]] = call <8 x float> @llvm.masked.load.v8f32.p0v8f32(<8 x float>* [[PTR:%.*]], i32 32, <8 x i1> [[MASK:%.*]], <8 x float> undef)
101+
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[COND:%.*]], <8 x float> zeroinitializer, <8 x float> [[TMP0]]
102+
; CHECK-NEXT: ret <8 x float> [[TMP1]]
103+
entry:
104+
%0 = call <8 x float> @llvm.masked.load.v8f32.p0v8f32(<8 x float>* %ptr, i32 32, <8 x i1> %mask, <8 x float> undef)
105+
%1 = select i1 %cond, <8 x float> zeroinitializer, <8 x float> %0
106+
ret <8 x float> %1
107+
}
108+
109+
declare <8 x float> @llvm.masked.load.v8f32.p0v8f32(<8 x float>*, i32 immarg, <8 x i1>, <8 x float>)
97110
declare <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>*, i32 immarg, <4 x i1>, <4 x i32>)
98111
declare <4 x float> @llvm.masked.load.v4f32.p0v4f32(<4 x float>*, i32 immarg, <4 x i1>, <4 x float>)

0 commit comments

Comments
 (0)