Skip to content

Commit 89e87aa

Browse files
committed
[VPlan] Update type of cloned instruction in scalarizeInstruction.
The operands of the replicate recipe may have been narrowed, resulting in a narrower result type. Update the type of the cloned instruction to the correct type. Fixes llvm#151392.
1 parent 3f5ac7d commit 89e87aa

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,12 +2852,12 @@ static void scalarizeInstruction(const Instruction *Instr,
28522852
Instruction *Cloned = Instr->clone();
28532853
if (!IsVoidRetTy) {
28542854
Cloned->setName(Instr->getName() + ".cloned");
2855-
#if !defined(NDEBUG)
2856-
// Verify that VPlan type inference results agree with the type of the
2857-
// generated values.
2858-
assert(State.TypeAnalysis.inferScalarType(RepRecipe) == Cloned->getType() &&
2859-
"inferred type and type from generated instructions do not match");
2860-
#endif
2855+
Type *ResultTy = State.TypeAnalysis.inferScalarType(RepRecipe);
2856+
// The operands of the replicate recipe may have been narrowed, resulting in
2857+
// a narrower result type. Update the type of the cloned instruction to the
2858+
// correct type.
2859+
if (ResultTy != Cloned->getType())
2860+
Cloned->mutateType(ResultTy);
28612861
}
28622862

28632863
RepRecipe->applyFlags(*Cloned);

llvm/test/Transforms/LoopVectorize/single-scalar-cast-minbw.ll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,12 @@ define void @single_scalar_cast_stored(ptr %src, ptr %dst, i32 %n) {
8181
; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 [[N]], 4
8282
; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 [[N]], [[N_MOD_VF]]
8383
; CHECK-NEXT: [[TMP0:%.*]] = load i16, ptr [[SRC]], align 2, !alias.scope [[META4:![0-9]+]]
84-
; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i16 [[TMP0]], 0
85-
; CHECK-NEXT: [[TMP4:%.*]] = and i16 [[TMP0]], 15
84+
; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i16> poison, i16 [[TMP0]], i64 0
85+
; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i16> [[BROADCAST_SPLATINSERT]], <4 x i16> poison, <4 x i32> zeroinitializer
86+
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq <4 x i16> [[BROADCAST_SPLAT]], zeroinitializer
87+
; CHECK-NEXT: [[TMP2:%.*]] = and <4 x i16> [[BROADCAST_SPLAT]], splat (i16 15)
88+
; CHECK-NEXT: [[TMP3:%.*]] = extractelement <4 x i1> [[TMP1]], i32 0
89+
; CHECK-NEXT: [[TMP4:%.*]] = extractelement <4 x i16> [[TMP2]], i32 0
8690
; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP3]], i16 0, i16 [[TMP4]]
8791
; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
8892
; CHECK: [[VECTOR_BODY]]:

0 commit comments

Comments
 (0)