[llvm-branch-commits] [llvm] 9e7895a - [SLP] reduce code duplication while processing reductions; NFC

Sanjay Patel via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 12 13:10:11 PST 2021


Author: Sanjay Patel
Date: 2021-01-12T16:03:57-05:00
New Revision: 9e7895a8682ce3ad98c006955d573d5f2fded4f6

URL: https://github.com/llvm/llvm-project/commit/9e7895a8682ce3ad98c006955d573d5f2fded4f6
DIFF: https://github.com/llvm/llvm-project/commit/9e7895a8682ce3ad98c006955d573d5f2fded4f6.diff

LOG: [SLP] reduce code duplication while processing reductions; NFC

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 1ef762c9dfa7..403170447f5a 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -6863,33 +6863,32 @@ class HorizontalReduction {
       // (possibly) a reduced value. If the reduced value opcode is not set,
       // the first met operation != reduction operation is considered as the
       // reduced value class.
+      // Only handle trees in the current basic block.
+      // Each tree node needs to have minimal number of users except for the
+      // ultimate reduction.
       const bool IsRdxInst = EdgeOpData == RdxTreeInst;
-      if (I && I != Phi &&
+      if (I && I != Phi && I != B &&
+          RdxTreeInst.hasSameParent(I, B->getParent(), IsRdxInst) &&
+          RdxTreeInst.hasRequiredNumberOfUses(I, IsRdxInst) &&
           (!RdxLeafVal || EdgeOpData == RdxLeafVal || IsRdxInst)) {
-        // Only handle trees in the current basic block.
-        // Each tree node needs to have minimal number of users except for the
-        // ultimate reduction.
-        if (RdxTreeInst.hasSameParent(I, B->getParent(), IsRdxInst) &&
-            RdxTreeInst.hasRequiredNumberOfUses(I, IsRdxInst) && I != B) {
-          if (IsRdxInst) {
-            // We need to be able to reassociate the reduction operations.
-            if (!EdgeOpData.isAssociative(I)) {
-              // I is an extra argument for TreeN (its parent operation).
-              markExtraArg(Stack.back(), I);
-              continue;
-            }
-          } else if (RdxLeafVal && RdxLeafVal != EdgeOpData) {
-            // Make sure that the opcodes of the operations that we are going to
-            // reduce match.
+        if (IsRdxInst) {
+          // We need to be able to reassociate the reduction operations.
+          if (!EdgeOpData.isAssociative(I)) {
             // I is an extra argument for TreeN (its parent operation).
             markExtraArg(Stack.back(), I);
             continue;
-          } else if (!RdxLeafVal) {
-            RdxLeafVal = EdgeOpData;
           }
-          Stack.push_back(std::make_pair(I, EdgeOpData.getFirstOperandIndex()));
+        } else if (RdxLeafVal && RdxLeafVal != EdgeOpData) {
+          // Make sure that the opcodes of the operations that we are going to
+          // reduce match.
+          // I is an extra argument for TreeN (its parent operation).
+          markExtraArg(Stack.back(), I);
           continue;
+        } else if (!RdxLeafVal) {
+          RdxLeafVal = EdgeOpData;
         }
+        Stack.push_back(std::make_pair(I, EdgeOpData.getFirstOperandIndex()));
+        continue;
       }
       // NextV is an extra argument for TreeN (its parent operation).
       markExtraArg(Stack.back(), NextV);


        


More information about the llvm-branch-commits mailing list