@@ -606,14 +606,6 @@ class InnerLoopVectorizer {
606
606
// / represented as.
607
607
void truncateToMinimalBitwidths (VPTransformState &State);
608
608
609
- // / This function adds
610
- // / (StartIdx * Step, (StartIdx + 1) * Step, (StartIdx + 2) * Step, ...)
611
- // / to each vector element of Val. The sequence starts at StartIndex.
612
- // / \p Opcode is relevant for FP induction variable.
613
- virtual Value *
614
- getStepVector (Value *Val, Value *StartIdx, Value *Step,
615
- Instruction::BinaryOps Opcode = Instruction::BinaryOpsEnd);
616
-
617
609
// / Compute scalar induction steps. \p ScalarIV is the scalar induction
618
610
// / variable on which to base the steps, \p Step is the size of the step, and
619
611
// / \p EntryVal is the value from the original loop that maps to the steps.
@@ -856,9 +848,6 @@ class InnerLoopUnroller : public InnerLoopVectorizer {
856
848
857
849
private:
858
850
Value *getBroadcastInstrs (Value *V) override ;
859
- Value *getStepVector (
860
- Value *Val, Value *StartIdx, Value *Step,
861
- Instruction::BinaryOps Opcode = Instruction::BinaryOpsEnd) override ;
862
851
Value *reverseVector (Value *Vec) override ;
863
852
};
864
853
@@ -2335,6 +2324,72 @@ Value *InnerLoopVectorizer::getBroadcastInstrs(Value *V) {
2335
2324
return Shuf;
2336
2325
}
2337
2326
2327
+ // / This function adds
2328
+ // / (StartIdx * Step, (StartIdx + 1) * Step, (StartIdx + 2) * Step, ...)
2329
+ // / to each vector element of Val. The sequence starts at StartIndex.
2330
+ // / \p Opcode is relevant for FP induction variable.
2331
+ static Value *getStepVector (Value *Val, Value *StartIdx, Value *Step,
2332
+ Instruction::BinaryOps BinOp, ElementCount VF,
2333
+ IRBuilder<> &Builder) {
2334
+ if (VF.isScalar ()) {
2335
+ // When unrolling and the VF is 1, we only need to add a simple scalar.
2336
+ Type *Ty = Val->getType ();
2337
+ assert (!Ty->isVectorTy () && " Val must be a scalar" );
2338
+
2339
+ if (Ty->isFloatingPointTy ()) {
2340
+ // Floating-point operations inherit FMF via the builder's flags.
2341
+ Value *MulOp = Builder.CreateFMul (StartIdx, Step);
2342
+ return Builder.CreateBinOp (BinOp, Val, MulOp);
2343
+ }
2344
+ return Builder.CreateAdd (Val, Builder.CreateMul (StartIdx, Step),
2345
+ " induction" );
2346
+ }
2347
+
2348
+ // Create and check the types.
2349
+ auto *ValVTy = cast<VectorType>(Val->getType ());
2350
+ ElementCount VLen = ValVTy->getElementCount ();
2351
+
2352
+ Type *STy = Val->getType ()->getScalarType ();
2353
+ assert ((STy->isIntegerTy () || STy->isFloatingPointTy ()) &&
2354
+ " Induction Step must be an integer or FP" );
2355
+ assert (Step->getType () == STy && " Step has wrong type" );
2356
+
2357
+ SmallVector<Constant *, 8 > Indices;
2358
+
2359
+ // Create a vector of consecutive numbers from zero to VF.
2360
+ VectorType *InitVecValVTy = ValVTy;
2361
+ Type *InitVecValSTy = STy;
2362
+ if (STy->isFloatingPointTy ()) {
2363
+ InitVecValSTy =
2364
+ IntegerType::get (STy->getContext (), STy->getScalarSizeInBits ());
2365
+ InitVecValVTy = VectorType::get (InitVecValSTy, VLen);
2366
+ }
2367
+ Value *InitVec = Builder.CreateStepVector (InitVecValVTy);
2368
+
2369
+ // Splat the StartIdx
2370
+ Value *StartIdxSplat = Builder.CreateVectorSplat (VLen, StartIdx);
2371
+
2372
+ if (STy->isIntegerTy ()) {
2373
+ InitVec = Builder.CreateAdd (InitVec, StartIdxSplat);
2374
+ Step = Builder.CreateVectorSplat (VLen, Step);
2375
+ assert (Step->getType () == Val->getType () && " Invalid step vec" );
2376
+ // FIXME: The newly created binary instructions should contain nsw/nuw
2377
+ // flags, which can be found from the original scalar operations.
2378
+ Step = Builder.CreateMul (InitVec, Step);
2379
+ return Builder.CreateAdd (Val, Step, " induction" );
2380
+ }
2381
+
2382
+ // Floating point induction.
2383
+ assert ((BinOp == Instruction::FAdd || BinOp == Instruction::FSub) &&
2384
+ " Binary Opcode should be specified for FP induction" );
2385
+ InitVec = Builder.CreateUIToFP (InitVec, ValVTy);
2386
+ InitVec = Builder.CreateFAdd (InitVec, StartIdxSplat);
2387
+
2388
+ Step = Builder.CreateVectorSplat (VLen, Step);
2389
+ Value *MulOp = Builder.CreateFMul (InitVec, Step);
2390
+ return Builder.CreateBinOp (BinOp, Val, MulOp, " induction" );
2391
+ }
2392
+
2338
2393
void InnerLoopVectorizer::createVectorIntOrFpInductionPHI (
2339
2394
const InductionDescriptor &II, Value *Step, Value *Start,
2340
2395
Instruction *EntryVal, VPValue *Def, VPTransformState &State) {
@@ -2355,8 +2410,8 @@ void InnerLoopVectorizer::createVectorIntOrFpInductionPHI(
2355
2410
2356
2411
Value *Zero = getSignedIntOrFpConstant (Start->getType (), 0 );
2357
2412
Value *SplatStart = Builder.CreateVectorSplat (State.VF , Start);
2358
- Value *SteppedStart =
2359
- getStepVector ( SplatStart, Zero, Step, II.getInductionOpcode ());
2413
+ Value *SteppedStart = getStepVector (
2414
+ SplatStart, Zero, Step, II.getInductionOpcode (), State. VF , State. Builder );
2360
2415
2361
2416
// We create vector phi nodes for both integer and floating-point induction
2362
2417
// variables. Here, we determine the kind of arithmetic we will perform.
@@ -2502,7 +2557,8 @@ void InnerLoopVectorizer::widenIntOrFpInduction(PHINode *IV,
2502
2557
StartIdx = getRuntimeVF (Builder, Step->getType (), State.VF * Part);
2503
2558
2504
2559
Value *EntryPart =
2505
- getStepVector (Broadcasted, StartIdx, Step, ID.getInductionOpcode ());
2560
+ getStepVector (Broadcasted, StartIdx, Step, ID.getInductionOpcode (),
2561
+ State.VF , State.Builder );
2506
2562
State.set (Def, EntryPart, Part);
2507
2563
if (Trunc)
2508
2564
addMetadata (EntryPart, Trunc);
@@ -2554,54 +2610,6 @@ void InnerLoopVectorizer::widenIntOrFpInduction(PHINode *IV,
2554
2610
buildScalarSteps (ScalarIV, Step, EntryVal, ID, Def, State);
2555
2611
}
2556
2612
2557
- Value *InnerLoopVectorizer::getStepVector (Value *Val, Value *StartIdx,
2558
- Value *Step,
2559
- Instruction::BinaryOps BinOp) {
2560
- // Create and check the types.
2561
- auto *ValVTy = cast<VectorType>(Val->getType ());
2562
- ElementCount VLen = ValVTy->getElementCount ();
2563
-
2564
- Type *STy = Val->getType ()->getScalarType ();
2565
- assert ((STy->isIntegerTy () || STy->isFloatingPointTy ()) &&
2566
- " Induction Step must be an integer or FP" );
2567
- assert (Step->getType () == STy && " Step has wrong type" );
2568
-
2569
- SmallVector<Constant *, 8 > Indices;
2570
-
2571
- // Create a vector of consecutive numbers from zero to VF.
2572
- VectorType *InitVecValVTy = ValVTy;
2573
- Type *InitVecValSTy = STy;
2574
- if (STy->isFloatingPointTy ()) {
2575
- InitVecValSTy =
2576
- IntegerType::get (STy->getContext (), STy->getScalarSizeInBits ());
2577
- InitVecValVTy = VectorType::get (InitVecValSTy, VLen);
2578
- }
2579
- Value *InitVec = Builder.CreateStepVector (InitVecValVTy);
2580
-
2581
- // Splat the StartIdx
2582
- Value *StartIdxSplat = Builder.CreateVectorSplat (VLen, StartIdx);
2583
-
2584
- if (STy->isIntegerTy ()) {
2585
- InitVec = Builder.CreateAdd (InitVec, StartIdxSplat);
2586
- Step = Builder.CreateVectorSplat (VLen, Step);
2587
- assert (Step->getType () == Val->getType () && " Invalid step vec" );
2588
- // FIXME: The newly created binary instructions should contain nsw/nuw flags,
2589
- // which can be found from the original scalar operations.
2590
- Step = Builder.CreateMul (InitVec, Step);
2591
- return Builder.CreateAdd (Val, Step, " induction" );
2592
- }
2593
-
2594
- // Floating point induction.
2595
- assert ((BinOp == Instruction::FAdd || BinOp == Instruction::FSub) &&
2596
- " Binary Opcode should be specified for FP induction" );
2597
- InitVec = Builder.CreateUIToFP (InitVec, ValVTy);
2598
- InitVec = Builder.CreateFAdd (InitVec, StartIdxSplat);
2599
-
2600
- Step = Builder.CreateVectorSplat (VLen, Step);
2601
- Value *MulOp = Builder.CreateFMul (InitVec, Step);
2602
- return Builder.CreateBinOp (BinOp, Val, MulOp, " induction" );
2603
- }
2604
-
2605
2613
void InnerLoopVectorizer::buildScalarSteps (Value *ScalarIV, Value *Step,
2606
2614
Instruction *EntryVal,
2607
2615
const InductionDescriptor &ID,
@@ -8036,21 +8044,6 @@ Value *InnerLoopUnroller::reverseVector(Value *Vec) { return Vec; }
8036
8044
8037
8045
Value *InnerLoopUnroller::getBroadcastInstrs (Value *V) { return V; }
8038
8046
8039
- Value *InnerLoopUnroller::getStepVector (Value *Val, Value *StartIdx,
8040
- Value *Step,
8041
- Instruction::BinaryOps BinOp) {
8042
- // When unrolling and the VF is 1, we only need to add a simple scalar.
8043
- Type *Ty = Val->getType ();
8044
- assert (!Ty->isVectorTy () && " Val must be a scalar" );
8045
-
8046
- if (Ty->isFloatingPointTy ()) {
8047
- // Floating-point operations inherit FMF via the builder's flags.
8048
- Value *MulOp = Builder.CreateFMul (StartIdx, Step);
8049
- return Builder.CreateBinOp (BinOp, Val, MulOp);
8050
- }
8051
- return Builder.CreateAdd (Val, Builder.CreateMul (StartIdx, Step), " induction" );
8052
- }
8053
-
8054
8047
static void AddRuntimeUnrollDisableMetaData (Loop *L) {
8055
8048
SmallVector<Metadata *, 4 > MDs;
8056
8049
// Reserve first location for self reference to the LoopID metadata node.
0 commit comments