Skip to content

Commit 7ce48be

Browse files
committed
[LV] Inline CreateSplatIV call for scalar VFs (NFC).
This is a NFC change split off from D116123, as suggested there. D116123 will remove the last user of CreateSplatIV.
1 parent ec0a880 commit 7ce48be

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2580,7 +2580,26 @@ void InnerLoopVectorizer::widenIntOrFpInduction(
25802580
Value *Step = CreateStepValue(ID.getStep());
25812581
if (State.VF.isScalar()) {
25822582
Value *ScalarIV = CreateScalarIV(Step);
2583-
CreateSplatIV(ScalarIV, Step);
2583+
Type *ScalarTy = IntegerType::get(ScalarIV->getContext(),
2584+
Step->getType()->getScalarSizeInBits());
2585+
for (unsigned Part = 0; Part < UF; ++Part) {
2586+
Value *StartIdx = ConstantInt::get(ScalarTy, Part);
2587+
Instruction::BinaryOps MulOp = Instruction::Mul;
2588+
if (Step->getType()->isFloatingPointTy()) {
2589+
StartIdx = Builder.CreateUIToFP(StartIdx, Step->getType());
2590+
MulOp = Instruction::FMul;
2591+
}
2592+
2593+
Value *Mul = Builder.CreateBinOp(MulOp, StartIdx, Step);
2594+
Value *EntryPart = Builder.CreateBinOp(ID.getInductionOpcode(), ScalarIV,
2595+
Mul, "induction");
2596+
State.set(Def, EntryPart, Part);
2597+
if (Trunc) {
2598+
assert(!Step->getType()->isFloatingPointTy() &&
2599+
"fp inductions shouldn't be truncated");
2600+
addMetadata(EntryPart, Trunc);
2601+
}
2602+
}
25842603
return;
25852604
}
25862605

llvm/test/Transforms/LoopVectorize/float-induction.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,11 +1603,11 @@ define void @non_primary_iv_float_scalar(float* %A, i64 %N) {
16031603
; VEC1_INTERL2-NEXT: br label [[PRED_STORE_CONTINUE]]
16041604
; VEC1_INTERL2: pred.store.continue:
16051605
; VEC1_INTERL2-NEXT: br i1 [[TMP6]], label [[PRED_STORE_IF4:%.*]], label [[PRED_STORE_CONTINUE5]]
1606-
; VEC1_INTERL2: pred.store.if4:
1606+
; VEC1_INTERL2: pred.store.if6:
16071607
; VEC1_INTERL2-NEXT: [[TMP7:%.*]] = fadd fast float [[TMP0]], 1.000000e+00
16081608
; VEC1_INTERL2-NEXT: store float [[TMP7]], float* [[TMP2]], align 4
16091609
; VEC1_INTERL2-NEXT: br label [[PRED_STORE_CONTINUE5]]
1610-
; VEC1_INTERL2: pred.store.continue5:
1610+
; VEC1_INTERL2: pred.store.continue7:
16111611
; VEC1_INTERL2-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
16121612
; VEC1_INTERL2-NEXT: [[TMP8:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
16131613
; VEC1_INTERL2-NEXT: br i1 [[TMP8]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP11:![0-9]+]]

0 commit comments

Comments
 (0)