From bf0bd85f9d823216501dcc09ae5461c2cf633ccf Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sat, 26 Nov 2022 23:48:46 +0000 Subject: [PATCH] [LV] Move trunc codegen to buildScalarSteps (NFCI). This moves the code to truncate step and IV into buildScalarSteps, closer to the place where they are actually used. Suggested in D133758. --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index f57c394..478d587 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2333,11 +2333,19 @@ static Value *getStepVector(Value *Val, Value *StartIdx, Value *Step, /// variable on which to base the steps, \p Step is the size of the step. static void buildScalarSteps(Value *ScalarIV, Value *Step, const InductionDescriptor &ID, VPValue *Def, - VPTransformState &State) { + Type *TruncToTy, VPTransformState &State) { IRBuilderBase &Builder = State.Builder; + Type *ScalarIVTy = ScalarIV->getType()->getScalarType(); + if (TruncToTy) { + assert(Step->getType()->isIntegerTy() && + "Truncation requires an integer step"); + ScalarIV = State.Builder.CreateTrunc(ScalarIV, TruncToTy); + Step = State.Builder.CreateTrunc(Step, TruncToTy); + ScalarIVTy = ScalarIV->getType()->getScalarType(); + } + // We shouldn't have to build scalar steps if we aren't vectorizing. // Get the value type and ensure it and the step have the same integer type. - Type *ScalarIVTy = ScalarIV->getType()->getScalarType(); assert(ScalarIVTy == Step->getType() && "Val and Step should have the same type"); @@ -9545,17 +9553,11 @@ void VPScalarIVStepsRecipe::execute(VPTransformState &State) { IndDesc); ScalarIV->setName("offset.idx"); } - if (TruncToTy) { - assert(Step->getType()->isIntegerTy() && - "Truncation requires an integer step"); - ScalarIV = State.Builder.CreateTrunc(ScalarIV, TruncToTy); - Step = State.Builder.CreateTrunc(Step, TruncToTy); - } return ScalarIV; }; Value *ScalarIV = CreateScalarIV(Step); - buildScalarSteps(ScalarIV, Step, IndDesc, this, State); + buildScalarSteps(ScalarIV, Step, IndDesc, this, TruncToTy, State); } void VPInterleaveRecipe::execute(VPTransformState &State) { -- 2.7.4