[llvm] [VPlan] Perform interleaving as VPlan-to-VPlan transform. (PR #94339)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 4 04:50:23 PDT 2024


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 c631131a1490af9f908a3a3be9aae5295ecff67d 737bbfccf1d5c275019ae36a3272e197c6b984bc -- llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h 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/VPlanAnalysis.h llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp llvm/lib/Transforms/Vectorize/VPlanTransforms.h llvm/lib/Transforms/Vectorize/VPlanValue.h
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 8f21c42ee6..9c0d0cf05b 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -9169,24 +9169,24 @@ void VPWidenPointerInductionRecipe::execute(VPTransformState &State) {
   // Create UF many actual address geps that use the pointer
   // phi as base and a vectorized version of the step value
   // (<step*0, ..., step*N>) as offset.
-    Type *VecPhiType = VectorType::get(PhiType, State.VF);
-    Value *StartOffsetScalar =
-        State.Builder.CreateMul(RuntimeVF, ConstantInt::get(PhiType, Part));
-    Value *StartOffset =
-        State.Builder.CreateVectorSplat(State.VF, StartOffsetScalar);
-    // Create a vector of consecutive numbers from zero to VF.
-    StartOffset = State.Builder.CreateAdd(
-        StartOffset, State.Builder.CreateStepVector(VecPhiType));
-
-    assert(ScalarStepValue == State.get(getOperand(1), VPLane(0)) &&
-           "scalar step must be the same across all parts");
-    Value *GEP = State.Builder.CreateGEP(
-        State.Builder.getInt8Ty(), NewPointerPhi,
-        State.Builder.CreateMul(
-            StartOffset,
-            State.Builder.CreateVectorSplat(State.VF, ScalarStepValue),
-            "vector.gep"));
-    State.set(this, GEP, 0);
+  Type *VecPhiType = VectorType::get(PhiType, State.VF);
+  Value *StartOffsetScalar =
+      State.Builder.CreateMul(RuntimeVF, ConstantInt::get(PhiType, Part));
+  Value *StartOffset =
+      State.Builder.CreateVectorSplat(State.VF, StartOffsetScalar);
+  // Create a vector of consecutive numbers from zero to VF.
+  StartOffset = State.Builder.CreateAdd(
+      StartOffset, State.Builder.CreateStepVector(VecPhiType));
+
+  assert(ScalarStepValue == State.get(getOperand(1), VPLane(0)) &&
+         "scalar step must be the same across all parts");
+  Value *GEP = State.Builder.CreateGEP(
+      State.Builder.getInt8Ty(), NewPointerPhi,
+      State.Builder.CreateMul(
+          StartOffset,
+          State.Builder.CreateVectorSplat(State.VF, ScalarStepValue),
+          "vector.gep"));
+  State.set(this, GEP, 0);
 }
 
 void VPDerivedIVRecipe::execute(VPTransformState &State) {
@@ -9266,14 +9266,14 @@ void VPWidenLoadRecipe::execute(VPTransformState &State) {
 
   auto &Builder = State.Builder;
   State.setDebugLocFrom(getDebugLoc());
-    Value *NewLI;
-    Value *Mask = nullptr;
-    if (auto *VPMask = getMask()) {
-      // Mask reversal is only needed for non-all-one (null) masks, as reverse
-      // of a null all-one mask is a null mask.
-      Mask = State.get(VPMask);
-      if (isReverse())
-        Mask = Builder.CreateVectorReverse(Mask, "reverse");
+  Value *NewLI;
+  Value *Mask = nullptr;
+  if (auto *VPMask = getMask()) {
+    // Mask reversal is only needed for non-all-one (null) masks, as reverse
+    // of a null all-one mask is a null mask.
+    Mask = State.get(VPMask);
+    if (isReverse())
+      Mask = Builder.CreateVectorReverse(Mask, "reverse");
     }
 
     Value *Addr = State.get(getAddr(), /*IsScalar*/ !CreateGather);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index b0f5600988..d8c55ece3d 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -604,14 +604,14 @@ void VPInstruction::execute(VPTransformState &State) {
       canGenerateScalarForFirstLane() &&
       (vputils::onlyFirstLaneUsed(this) || isVectorToScalar());
   bool GeneratesPerAllLanes = doesGeneratePerAllLanes();
-    if (GeneratesPerAllLanes) {
-      for (unsigned Lane = 0, NumLanes = State.VF.getKnownMinValue();
-           Lane != NumLanes; ++Lane) {
-        Value *GeneratedValue = generatePerLane(State, Lane);
-        assert(GeneratedValue && "generatePerLane must produce a value");
-        State.set(this, GeneratedValue, VPLane(Lane));
-      }
-      return;
+  if (GeneratesPerAllLanes) {
+    for (unsigned Lane = 0, NumLanes = State.VF.getKnownMinValue();
+         Lane != NumLanes; ++Lane) {
+      Value *GeneratedValue = generatePerLane(State, Lane);
+      assert(GeneratedValue && "generatePerLane must produce a value");
+      State.set(this, GeneratedValue, VPLane(Lane));
+    }
+    return;
     }
 
     Value *GeneratedValue = generate(State);
@@ -1365,9 +1365,9 @@ void VPWidenGEPRecipe::execute(VPTransformState &State) {
     auto *NewGEP =
         State.Builder.CreateGEP(GEP->getSourceElementType(), Ops[0],
                                 ArrayRef(Ops).drop_front(), "", isInBounds());
-      Value *EntryPart = State.Builder.CreateVectorSplat(State.VF, NewGEP);
-      State.set(this, EntryPart, 0);
-      State.addMetadata(EntryPart, GEP);
+    Value *EntryPart = State.Builder.CreateVectorSplat(State.VF, NewGEP);
+    State.set(this, EntryPart, 0);
+    State.addMetadata(EntryPart, GEP);
   } else {
     // If the GEP has at least one loop-varying operand, we are sure to
     // produce a vector of pointers. But if we are only unrolling, we want
@@ -1376,8 +1376,8 @@ void VPWidenGEPRecipe::execute(VPTransformState &State) {
     // (otherwise). Note that for the unroll-only case, we still maintain
     // values in the vector mapping with initVector, as we do for other
     // instructions.
-      // The pointer operand of the new GEP. If it's loop-invariant, we
-      // won't broadcast it.
+    // The pointer operand of the new GEP. If it's loop-invariant, we
+    // won't broadcast it.
     auto *Ptr = isPointerLoopInvariant() ? State.get(getOperand(0), VPLane(0))
                                          : State.get(getOperand(0));
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/94339


More information about the llvm-commits mailing list