]> granicus.if.org Git - llvm/commitdiff
Fix bad compare function over FusionCandidate.
authorRichard Trieu <rtrieu@google.com>
Thu, 18 Apr 2019 01:39:45 +0000 (01:39 +0000)
committerRichard Trieu <rtrieu@google.com>
Thu, 18 Apr 2019 01:39:45 +0000 (01:39 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358636 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopFuse.cpp

index a50cb0a1d96e128b55d34f30e9186be4d7f5c2df..bf45e5a8e75c0534d8aea76c4591a319c36c2960 100644 (file)
@@ -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.