[llvm] [GVNSink] Fix non-determinisms by using Depth-First ordering (PR #90995)
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Fri May 3 13:54:37 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);
----------------
efriedma-quic wrote:
DT->getNode() returns a pointer. If you want the domtree to generate DFS numbers, you need to explicitly request them (see updateDFSNumbers()/getDFSNumIn()).
Splitting an edge with SplitBlockPredecessors will invalidate this numbering; not sure how you handle that.
https://github.com/llvm/llvm-project/pull/90995
More information about the llvm-commits
mailing list