[llvm] bf0bd85 - [LV] Move trunc codegen to buildScalarSteps (NFCI).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 26 15:50:01 PST 2022
Author: Florian Hahn
Date: 2022-11-26T23:48:46Z
New Revision: bf0bd85f9d823216501dcc09ae5461c2cf633ccf
URL: https://github.com/llvm/llvm-project/commit/bf0bd85f9d823216501dcc09ae5461c2cf633ccf
DIFF: https://github.com/llvm/llvm-project/commit/bf0bd85f9d823216501dcc09ae5461c2cf633ccf.diff
LOG: [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.
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index f57c394427e5..478d587cbca6 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) {
More information about the llvm-commits
mailing list