[llvm] [VPlan] Unroll VPReplicateRecipe by VF. (PR #142433)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 10 02:52:16 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp llvm/lib/Transforms/Vectorize/VPlan.cpp llvm/lib/Transforms/Vectorize/VPlan.h llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp llvm/lib/Transforms/Vectorize/VPlanTransforms.h llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 454accba7..8764454a7 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -907,10 +907,12 @@ public:
BranchOnCount,
BranchOnCond,
Broadcast,
- /// Creates a struct of fixed-width vectors containing all operands. The number of operands
-/// matches the number of fields in the struct.
+ /// Creates a struct of fixed-width vectors containing all operands. The
+ /// number of operands
+ /// matches the number of fields in the struct.
BuildStructVector,
- /// Creates a fixed-width vector containing all operands. The number of operands matches the vector element count.
+ /// Creates a fixed-width vector containing all operands. The number of
+ /// operands matches the vector element count.
BuildVector,
ComputeAnyOfResult,
ComputeFindLastIVResult,
diff --git a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
index 7c427ac18..48a96e010 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
@@ -276,8 +276,7 @@ using UnaryVPInstruction_match =
UnaryRecipe_match<Op0_t, Opcode, VPInstruction>;
template <unsigned Opcode>
-using ZeroOpVPInstruction_match =
- ZeroOpRecipe_match<Opcode, VPInstruction>;
+using ZeroOpVPInstruction_match = ZeroOpRecipe_match<Opcode, VPInstruction>;
template <typename Op0_t, unsigned Opcode>
using AllUnaryRecipe_match =
@@ -310,8 +309,7 @@ using AllBinaryRecipe_match =
BinaryRecipe_match<Op0_t, Op1_t, Opcode, Commutative, VPWidenRecipe,
VPReplicateRecipe, VPWidenCastRecipe, VPInstruction>;
-inline ZeroOpVPInstruction_match<VPInstruction::BuildVector>
-m_BuildVector() {
+inline ZeroOpVPInstruction_match<VPInstruction::BuildVector> m_BuildVector() {
return ZeroOpVPInstruction_match<VPInstruction::BuildVector>();
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 2eb03ab64..4a1d7fd85 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -493,10 +493,9 @@ Value *VPInstruction::generate(VPTransformState &State) {
}
case Instruction::ExtractElement: {
assert(State.VF.isVector() && "Only extract elements from vectors");
- unsigned IdxToExtract = cast<ConstantInt>(getOperand(1)->getLiveInIRValue())
- ->getZExtValue();
- return State.get(getOperand(0),
- VPLane(IdxToExtract));
+ unsigned IdxToExtract =
+ cast<ConstantInt>(getOperand(1)->getLiveInIRValue())->getZExtValue();
+ return State.get(getOperand(0), VPLane(IdxToExtract));
}
case Instruction::Freeze: {
Value *Op = State.get(getOperand(0), vputils::onlyFirstLaneUsed(this));
@@ -611,11 +610,11 @@ Value *VPInstruction::generate(VPTransformState &State) {
auto *StructTy =
cast<StructType>(State.TypeAnalysis.inferScalarType(getOperand(0)));
auto NumOfElements = ElementCount::getFixed(getNumOperands());
- Value *Res = PoisonValue::get(
- toVectorizedTy(StructTy, NumOfElements));
- assert(NumOfElements.getKnownMinValue() == StructTy->getNumElements() && "number of operands must match number of elements in StructTy");
+ Value *Res = PoisonValue::get(toVectorizedTy(StructTy, NumOfElements));
+ assert(NumOfElements.getKnownMinValue() == StructTy->getNumElements() &&
+ "number of operands must match number of elements in StructTy");
for (const auto &[Idx, Op] : enumerate(operands())) {
- for (unsigned I = 0 ; I != NumOfElements .getKnownMinValue(); I++) {
+ for (unsigned I = 0; I != NumOfElements.getKnownMinValue(); I++) {
Value *ScalarValue = Builder.CreateExtractValue(State.get(Op, true), I);
Value *VectorValue = Builder.CreateExtractValue(Res, I);
VectorValue =
@@ -628,8 +627,7 @@ Value *VPInstruction::generate(VPTransformState &State) {
case VPInstruction::BuildVector: {
auto *ScalarTy = State.TypeAnalysis.inferScalarType(getOperand(0));
auto NumOfElements = ElementCount::getFixed(getNumOperands());
- Value *Res = PoisonValue::get(
- toVectorizedTy(ScalarTy, NumOfElements));
+ Value *Res = PoisonValue::get(toVectorizedTy(ScalarTy, NumOfElements));
for (const auto &[Idx, Op] : enumerate(operands()))
Res = State.Builder.CreateInsertElement(Res, State.get(Op, true),
State.Builder.getInt32(Idx));
@@ -2800,7 +2798,8 @@ void VPReplicateRecipe::execute(VPTransformState &State) {
Instruction *UI = getUnderlyingInstr();
if (!State.Lane) {
- assert(IsSingleScalar && "VPReplicateRecipes outside replicate regions must be unrolled");
+ assert(IsSingleScalar &&
+ "VPReplicateRecipes outside replicate regions must be unrolled");
scalarizeInstruction(UI, this, VPLane(0), State);
return;
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index df65874f6..906763e6d 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -1142,18 +1142,20 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
// Look through ExtractLastElement (BuildVector ....).
if (match(&R, m_VPInstruction<VPInstruction::ExtractLastElement>(
- m_BuildVector()))) {
+ m_BuildVector()))) {
auto *BuildVector = cast<VPInstruction>(R.getOperand(0));
- Def->replaceAllUsesWith(BuildVector->getOperand(BuildVector->getNumOperands() - 1));
+ Def->replaceAllUsesWith(
+ BuildVector->getOperand(BuildVector->getNumOperands() - 1));
return;
}
// Look through ExtractPenultimateElement (BuildVector ....).
if (match(&R, m_VPInstruction<VPInstruction::ExtractPenultimateElement>(
- m_BuildVector()))) {
+ m_BuildVector()))) {
auto *BuildVector = cast<VPInstruction>(R.getOperand(0));
- Def->replaceAllUsesWith(BuildVector->getOperand(BuildVector->getNumOperands() - 2));
+ Def->replaceAllUsesWith(
+ BuildVector->getOperand(BuildVector->getNumOperands() - 2));
return;
-}
+ }
// Some simplifications can only be applied after unrolling. Perform them
// below.
diff --git a/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp b/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp
index 9b0476114..2b15e9ca0 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp
@@ -459,12 +459,14 @@ static VPReplicateRecipe *cloneForLane(VPlan &Plan, VPBuilder &Builder,
continue;
}
if (Lane.getKind() == VPLane::Kind::ScalableLast) {
- NewOps.push_back(Builder.createNaryOp(VPInstruction::ExtractLastElement, {Op}));
+ NewOps.push_back(
+ Builder.createNaryOp(VPInstruction::ExtractLastElement, {Op}));
continue;
}
// Look through buildvector to avoid unnecessary extracts.
if (match(Op, m_BuildVector())) {
- NewOps.push_back(cast<VPInstruction>(Op)->getOperand(Lane.getKnownLane()));
+ NewOps.push_back(
+ cast<VPInstruction>(Op)->getOperand(Lane.getKnownLane()));
continue;
}
VPValue *Idx =
``````````
</details>
https://github.com/llvm/llvm-project/pull/142433
More information about the llvm-commits
mailing list