[llvm] [LoopFlatten] Recognise gep+gep (PR #72515)

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 16 06:26:17 PST 2023


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 4cf996d6a20d8fd0817c953fd383d261409e6d04 231badf6e5aba72ce6ca83d1177ce645de7ef061 -- llvm/include/llvm/IR/PatternMatch.h llvm/lib/Transforms/Scalar/LoopFlatten.cpp
``````````

</details>

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

``````````diff
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index ec0144de2f..e40d08633f 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -1457,23 +1457,22 @@ struct ThreeOps_match {
 };
 
 /// Matches instructions with Opcode and any number of operands
-template <unsigned Opcode, typename... OperandTypes>
-struct AnyOps_match {
+template <unsigned Opcode, typename... OperandTypes> struct AnyOps_match {
   std::tuple<OperandTypes...> Operands;
 
-  AnyOps_match(const OperandTypes&... Ops) : Operands(Ops...) {}
+  AnyOps_match(const OperandTypes &...Ops) : Operands(Ops...) {}
 
   // Operand matching works by recursively calling match_operands, matching the
   // operands left to right. The first version is called for each operand but
   // the last, for which the second version is called. The second version of
   // match_operands is also used to match each individual operand.
   template <int Idx, int Last>
-  std::enable_if_t<Idx!=Last, bool> match_operands(const Instruction *I) {
-    return match_operands<Idx, Idx>(I) && match_operands<Idx+1, Last>(I);
+  std::enable_if_t<Idx != Last, bool> match_operands(const Instruction *I) {
+    return match_operands<Idx, Idx>(I) && match_operands<Idx + 1, Last>(I);
   }
 
   template <int Idx, int Last>
-  std::enable_if_t<Idx==Last, bool> match_operands(const Instruction *I) {
+  std::enable_if_t<Idx == Last, bool> match_operands(const Instruction *I) {
     return std::get<Idx>(Operands).match(I->getOperand(Idx));
   }
 
@@ -1481,7 +1480,7 @@ struct AnyOps_match {
     if (V->getValueID() == Value::InstructionVal + Opcode) {
       auto *I = cast<Instruction>(V);
       return I->getNumOperands() == sizeof...(OperandTypes) &&
-             match_operands<0, sizeof...(OperandTypes)-1>(I);
+             match_operands<0, sizeof...(OperandTypes) - 1>(I);
     }
     return false;
   }
@@ -1605,7 +1604,7 @@ m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp) {
 
 /// Matches GetElementPtrInst.
 template <typename... OperandTypes>
-inline auto m_GEP(const OperandTypes&... Ops) {
+inline auto m_GEP(const OperandTypes &...Ops) {
   return AnyOps_match<Instruction::GetElementPtr, OperandTypes...>(Ops...);
 }
 
diff --git a/llvm/lib/Transforms/Scalar/LoopFlatten.cpp b/llvm/lib/Transforms/Scalar/LoopFlatten.cpp
index b298d7ac1a..2972116736 100644
--- a/llvm/lib/Transforms/Scalar/LoopFlatten.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopFlatten.cpp
@@ -657,11 +657,9 @@ static OverflowResult checkOverflow(FlattenInfo &FI, DominatorTree *DT,
     for (Value *GEPUser : GEP->users()) {
       auto *GEPUserInst = cast<Instruction>(GEPUser);
       if (!isa<LoadInst>(GEPUserInst) &&
-          !(isa<StoreInst>(GEPUserInst) &&
-            GEP == GEPUserInst->getOperand(1)))
+          !(isa<StoreInst>(GEPUserInst) && GEP == GEPUserInst->getOperand(1)))
         continue;
-      if (!isGuaranteedToExecuteForEveryIteration(GEPUserInst,
-                                                  FI.InnerLoop))
+      if (!isGuaranteedToExecuteForEveryIteration(GEPUserInst, FI.InnerLoop))
         continue;
       // The IV is used as the operand of a GEP which dominates the loop
       // latch, and the IV is at least as wide as the address space of the
@@ -669,10 +667,10 @@ static OverflowResult checkOverflow(FlattenInfo &FI, DominatorTree *DT,
       // before the IV increment wraps, which would be UB.
       if (GEP->isInBounds() &&
           GEPOperand->getType()->getIntegerBitWidth() >=
-          DL.getPointerTypeSizeInBits(GEP->getType())) {
+              DL.getPointerTypeSizeInBits(GEP->getType())) {
         LLVM_DEBUG(
-          dbgs() << "use of linear IV would be UB if overflow occurred: ";
-          GEP->dump());
+            dbgs() << "use of linear IV would be UB if overflow occurred: ";
+            GEP->dump());
         return true;
       }
     }
@@ -803,7 +801,7 @@ static bool DoFlattenLoopPair(FlattenInfo &FI, DominatorTree *DT, LoopInfo *LI,
       if (!DT->dominates(Base, &*Builder.GetInsertPoint()))
         Builder.SetInsertPoint(cast<Instruction>(V));
       OuterValue = Builder.CreateGEP(GEP->getSourceElementType(), Base,
-                                     OuterValue, "flatten."+V->getName());
+                                     OuterValue, "flatten." + V->getName());
     }
 
     LLVM_DEBUG(dbgs() << "Replacing: "; V->dump(); dbgs() << "with:      ";

``````````

</details>


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


More information about the llvm-commits mailing list