[llvm] r361257 - [MergeICmps][NFC] Make BCEAtom move-only.

Clement Courbet via llvm-commits llvm-commits at lists.llvm.org
Tue May 21 06:34:13 PDT 2019


Author: courbet
Date: Tue May 21 06:34:12 2019
New Revision: 361257

URL: http://llvm.org/viewvc/llvm-project?rev=361257&view=rev
Log:
[MergeICmps][NFC] Make BCEAtom move-only.

And handle for self-move. This is required so that llvm::sort can work
with EXPENSIVE_CHECKS, as it will do a random shuffle of the input
which can result in self-moves.

Modified:
    llvm/trunk/lib/Transforms/Scalar/MergeICmps.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/MergeICmps.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/MergeICmps.cpp?rev=361257&r1=361256&r2=361257&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/MergeICmps.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/MergeICmps.cpp Tue May 21 06:34:12 2019
@@ -81,6 +81,20 @@ struct BCEAtom {
   BCEAtom(GetElementPtrInst *GEP, LoadInst *LoadI, int BaseId, APInt Offset)
       : GEP(GEP), LoadI(LoadI), BaseId(BaseId), Offset(Offset) {}
 
+  BCEAtom(const BCEAtom &) = delete;
+  BCEAtom &operator=(const BCEAtom &) = delete;
+
+  BCEAtom(BCEAtom &&that) = default;
+  BCEAtom &operator=(BCEAtom &&that) {
+    if (this == &that)
+      return *this;
+    GEP = that.GEP;
+    LoadI = that.LoadI;
+    BaseId = that.BaseId;
+    Offset = std::move(that.Offset);
+    return *this;
+  }
+
   // We want to order BCEAtoms by (Base, Offset). However we cannot use
   // the pointer values for Base because these are non-deterministic.
   // To make sure that the sort order is stable, we first assign to each atom
@@ -175,7 +189,7 @@ class BCECmpBlock {
   BCECmpBlock() {}
 
   BCECmpBlock(BCEAtom L, BCEAtom R, int SizeBits)
-      : Lhs_(L), Rhs_(R), SizeBits_(SizeBits) {
+      : Lhs_(std::move(L)), Rhs_(std::move(R)), SizeBits_(SizeBits) {
     if (Rhs_ < Lhs_) std::swap(Rhs_, Lhs_);
   }
 
@@ -376,7 +390,7 @@ BCECmpBlock visitCmpBlock(Value *const V
 }
 
 static inline void enqueueBlock(std::vector<BCECmpBlock> &Comparisons,
-                                BCECmpBlock &Comparison) {
+                                BCECmpBlock &&Comparison) {
   LLVM_DEBUG(dbgs() << "Block '" << Comparison.BB->getName()
                     << "': Found cmp of " << Comparison.SizeBits()
                     << " bits between " << Comparison.Lhs().BaseId << " + "
@@ -384,7 +398,7 @@ static inline void enqueueBlock(std::vec
                     << Comparison.Rhs().BaseId << " + "
                     << Comparison.Rhs().Offset << "\n");
   LLVM_DEBUG(dbgs() << "\n");
-  Comparisons.push_back(Comparison);
+  Comparisons.push_back(std::move(Comparison));
 }
 
 // A chain of comparisons.
@@ -456,7 +470,7 @@ BCECmpChain::BCECmpChain(const std::vect
                      << "Split initial block '" << Comparison.BB->getName()
                      << "' that does extra work besides compare\n");
           Comparison.RequireSplit = true;
-          enqueueBlock(Comparisons, Comparison);
+          enqueueBlock(Comparisons, std::move(Comparison));
         } else {
           LLVM_DEBUG(dbgs()
                      << "ignoring initial block '" << Comparison.BB->getName()
@@ -489,7 +503,7 @@ BCECmpChain::BCECmpChain(const std::vect
       // We could still merge bb1 and bb2 though.
       return;
     }
-    enqueueBlock(Comparisons, Comparison);
+    enqueueBlock(Comparisons, std::move(Comparison));
   }
 
   // It is possible we have no suitable comparison to merge.
@@ -507,7 +521,7 @@ BCECmpChain::BCECmpChain(const std::vect
   // semantics because we are only accessing dereferencable memory.
   llvm::sort(Comparisons_,
              [](const BCECmpBlock &LhsBlock, const BCECmpBlock &RhsBlock) {
-               return LhsBlock.Lhs() < RhsBlock.Lhs();
+               return LhsBlock.Rhs() < RhsBlock.Lhs();
              });
 #ifdef MERGEICMPS_DOT_ON
   errs() << "AFTER REORDERING:\n\n";




More information about the llvm-commits mailing list