[llvm] 6de3afe - [TableGen] Simplify how commuted variants are generated in GenerateVariantsOf. NFC

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 10 11:29:18 PDT 2023


Author: Craig Topper
Date: 2023-04-10T11:29:01-07:00
New Revision: 6de3afeaef70f35ab10384625cefaba5311c1d64

URL: https://github.com/llvm/llvm-project/commit/6de3afeaef70f35ab10384625cefaba5311c1d64
DIFF: https://github.com/llvm/llvm-project/commit/6de3afeaef70f35ab10384625cefaba5311c1d64.diff

LOG: [TableGen] Simplify how commuted variants are generated in GenerateVariantsOf. NFC

We don't need to copy the ChildVariants vector into a new vector.
We're using std::move on every entry we copy so they clearly
aren't needed again. We can swap entries in the vector and reuse
it instead.

Added: 
    

Modified: 
    llvm/utils/TableGen/CodeGenDAGPatterns.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
index 3bd5bfad5cd62..c2c560117ca54 100644
--- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -4695,17 +4695,10 @@ static void GenerateVariantsOf(TreePatternNodePtr N,
     }
     // Consider the commuted order.
     if (NoRegisters) {
-      std::vector<std::vector<TreePatternNodePtr>> Variants;
-      unsigned i = 0;
-      if (isCommIntrinsic)
-        Variants.push_back(std::move(ChildVariants[i++])); // Intrinsic id.
-      Variants.push_back(std::move(ChildVariants[i + 1]));
-      Variants.push_back(std::move(ChildVariants[i]));
-      i += 2;
-      // Remaining operands are not commuted.
-      for (; i != N->getNumChildren(); ++i)
-        Variants.push_back(std::move(ChildVariants[i]));
-      CombineChildVariants(N, Variants, OutVariants, CDP, DepVars);
+      // Swap the first two operands after the intrinsic id, if present.
+      unsigned i = isCommIntrinsic ? 1 : 0;
+      std::swap(ChildVariants[i], ChildVariants[i + 1]);
+      CombineChildVariants(N, ChildVariants, OutVariants, CDP, DepVars);
     }
   }
 }


        


More information about the llvm-commits mailing list