[llvm] [Bitcode] Fix nondeterministic phi instruction order (PR #151006)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 29 00:56:52 PDT 2025


================
@@ -211,6 +211,10 @@ static void predictValueUseListOrderImpl(const Value *V, const Function *F,
 
     // LID and RID are equal, so we have different operands of the same user.
     // Assume operands are added in order for all instructions.
+    // If operand numbers are equal, use pointer addresses for deterministic ordering.
+    if (LU->getOperandNo() == RU->getOperandNo())
+      return LU->getUser() < RU->getUser();
----------------
efriedma-quic wrote:

Pointer addresses aren't "deterministic" in the sense we want here.  The underlying allocator is often non-deterministic.

Probably what you want is just to switch from sort() to stable_sort(), which uses the order of the original input as the tiebreaker.

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


More information about the llvm-commits mailing list