[llvm] r358636 - Fix bad compare function over FusionCandidate.

Richard Trieu via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 17 18:39:46 PDT 2019


Author: rtrieu
Date: Wed Apr 17 18:39:45 2019
New Revision: 358636

URL: http://llvm.org/viewvc/llvm-project?rev=358636&view=rev
Log:
Fix bad compare function over FusionCandidate.

Reverse the checking of the domiance order so that when a self compare happens,
it returns false.  This makes compare function have strict weak ordering.

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

Modified: llvm/trunk/lib/Transforms/Scalar/LoopFuse.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopFuse.cpp?rev=358636&r1=358635&r2=358636&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopFuse.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopFuse.cpp Wed Apr 17 18:39:45 2019
@@ -264,18 +264,20 @@ struct FusionCandidateCompare {
     // will trigger an unused variable warning if building without asserts.
     assert(DT && LHS.PDT && "Expecting valid dominator tree");
 
-    if (DT->dominates(LHS.Preheader, RHS.Preheader)) {
-      // Verify RHS Postdominates LHS
-      assert(LHS.PDT->dominates(RHS.Preheader, LHS.Preheader));
-      return true;
-    }
-
+    // Do this compare first so if LHS == RHS, function returns false.
     if (DT->dominates(RHS.Preheader, LHS.Preheader)) {
       // RHS dominates LHS
       // Verify LHS post-dominates RHS
       assert(LHS.PDT->dominates(LHS.Preheader, RHS.Preheader));
       return false;
     }
+
+    if (DT->dominates(LHS.Preheader, RHS.Preheader)) {
+      // Verify RHS Postdominates LHS
+      assert(LHS.PDT->dominates(RHS.Preheader, LHS.Preheader));
+      return true;
+    }
+
     // If LHS does not dominate RHS and RHS does not dominate LHS then there is
     // no dominance relationship between the two FusionCandidates. Thus, they
     // should not be in the same set together.




More information about the llvm-commits mailing list