[llvm] [GVNSink] Fix non-determinisms by using Depth-First ordering (PR #90995)

via llvm-commits llvm-commits at lists.llvm.org
Fri May 3 14:23:57 PDT 2024


================
@@ -222,20 +222,29 @@ raw_ostream &operator<<(raw_ostream &OS, const SinkingInstructionCandidate &C) {
 class ModelledPHI {
   SmallVector<Value *, 4> Values;
   SmallVector<BasicBlock *, 4> Blocks;
+  DominatorTree *DT;
 
 public:
   ModelledPHI() = default;
 
-  ModelledPHI(const PHINode *PN) {
+  ModelledPHI(const PHINode *PN, DominatorTree *DT) : DT(DT) {
     // BasicBlock comes first so we sort by basic block pointer order, then by value pointer order.
-    SmallVector<std::pair<BasicBlock *, Value *>, 4> Ops;
+    using OpsType = std::pair<BasicBlock *, Value *>;
+    SmallVector<OpsType, 4> Ops;
     for (unsigned I = 0, E = PN->getNumIncomingValues(); I != E; ++I)
       Ops.push_back({PN->getIncomingBlock(I), PN->getIncomingValue(I)});
-    llvm::sort(Ops);
+
+    auto DFSOrder = [DT](OpsType O1, OpsType O2) {
+      return DT->getNode(O1.first) < DT->getNode(O2.first);
----------------
hiraditya wrote:

Ah, that was the intent. Thanks for pointing it out.

https://github.com/llvm/llvm-project/pull/90995


More information about the llvm-commits mailing list