[llvm] r313702 - GVNSink: Make ModelledPHIs constructor linear (and avoid edge case it worries about) by avoiding getIncomingValueForBlock

Daniel Berlin via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 19 17:07:27 PDT 2017


Author: dannyb
Date: Tue Sep 19 17:07:27 2017
New Revision: 313702

URL: http://llvm.org/viewvc/llvm-project?rev=313702&view=rev
Log:
GVNSink: Make ModelledPHIs constructor linear (and avoid edge case it worries about) by avoiding getIncomingValueForBlock

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

Modified: llvm/trunk/lib/Transforms/Scalar/GVNSink.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVNSink.cpp?rev=313702&r1=313701&r2=313702&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVNSink.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVNSink.cpp Tue Sep 19 17:07:27 2017
@@ -206,14 +206,15 @@ class ModelledPHI {
 public:
   ModelledPHI() {}
   ModelledPHI(const PHINode *PN) {
+    // BasicBlock comes first so we sort by basic block pointer order, then by value pointer order.
+    SmallVector<std::pair<BasicBlock *, Value *>, 4> Ops;
     for (unsigned I = 0, E = PN->getNumIncomingValues(); I != E; ++I)
-      Blocks.push_back(PN->getIncomingBlock(I));
-    std::sort(Blocks.begin(), Blocks.end());
-
-    // This assumes the PHI is already well-formed and there aren't conflicting
-    // incoming values for the same block.
-    for (auto *B : Blocks)
-      Values.push_back(PN->getIncomingValueForBlock(B));
+      Ops.push_back({PN->getIncomingBlock(I), PN->getIncomingValue(I)});
+    std::sort(Ops.begin(), Ops.end());
+    for (auto &P : Ops) {
+      Blocks.push_back(P.first);
+      Values.push_back(P.second);
+    }
   }
   /// Create a dummy ModelledPHI that will compare unequal to any other ModelledPHI
   /// without the same ID.




More information about the llvm-commits mailing list