From 97cbd1f2e7cde40ba67d1ce282a85d22013a0640 Mon Sep 17 00:00:00 2001 From: Michael Hackner Date: Mon, 28 Jul 2025 10:34:27 -0700 Subject: [PATCH] [Bitcode] Fix nondeterministic phi instruction order Currently there can be nondeterminism of the form ```diff - + ``` in generated bitcode. Stably sorting the use-list entries solves that. --- llvm/lib/Bitcode/Writer/ValueEnumerator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp index e133abe577c22..2fda69d2c8239 100644 --- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -186,7 +186,7 @@ static void predictValueUseListOrderImpl(const Value *V, const Function *F, return; bool IsGlobalValue = OM.isGlobalValue(ID); - llvm::sort(List, [&](const Entry &L, const Entry &R) { + llvm::stable_sort(List, [&](const Entry &L, const Entry &R) { const Use *LU = L.first; const Use *RU = R.first; if (LU == RU)