Skip to content

Commit 09c179d

Browse files
MaskRayAlexisPerry
authored andcommitted
[CodeGenPrepare] Use MapVector to stabilize iteration order
DenseMap iteration order is not guaranteed to be deterministic. Without the change, llvm/test/Transforms/CodeGenPrepare/X86/statepoint-relocate.ll would fail when `combineHashValue` changes (llvm#95970). Fixes: dba7329
1 parent 4e24e12 commit 09c179d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,12 +1194,12 @@ void CodeGenPrepare::eliminateMostlyEmptyBlock(BasicBlock *BB) {
11941194
// derived pointer relocation instructions given a vector of all relocate calls
11951195
static void computeBaseDerivedRelocateMap(
11961196
const SmallVectorImpl<GCRelocateInst *> &AllRelocateCalls,
1197-
DenseMap<GCRelocateInst *, SmallVector<GCRelocateInst *, 2>>
1197+
MapVector<GCRelocateInst *, SmallVector<GCRelocateInst *, 0>>
11981198
&RelocateInstMap) {
11991199
// Collect information in two maps: one primarily for locating the base object
12001200
// while filling the second map; the second map is the final structure holding
12011201
// a mapping between Base and corresponding Derived relocate calls
1202-
DenseMap<std::pair<unsigned, unsigned>, GCRelocateInst *> RelocateIdxMap;
1202+
MapVector<std::pair<unsigned, unsigned>, GCRelocateInst *> RelocateIdxMap;
12031203
for (auto *ThisRelocate : AllRelocateCalls) {
12041204
auto K = std::make_pair(ThisRelocate->getBasePtrIndex(),
12051205
ThisRelocate->getDerivedPtrIndex());
@@ -1375,7 +1375,7 @@ bool CodeGenPrepare::simplifyOffsetableRelocate(GCStatepointInst &I) {
13751375

13761376
// RelocateInstMap is a mapping from the base relocate instruction to the
13771377
// corresponding derived relocate instructions
1378-
DenseMap<GCRelocateInst *, SmallVector<GCRelocateInst *, 2>> RelocateInstMap;
1378+
MapVector<GCRelocateInst *, SmallVector<GCRelocateInst *, 0>> RelocateInstMap;
13791379
computeBaseDerivedRelocateMap(AllRelocateCalls, RelocateInstMap);
13801380
if (RelocateInstMap.empty())
13811381
return false;

llvm/test/Transforms/CodeGenPrepare/X86/statepoint-relocate.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ entry:
1818
}
1919

2020
define i32 @test_sor_two_derived(ptr addrspace(1) %base) gc "statepoint-example" {
21+
; CHECK-LABEL: @test_sor_two_derived(
2122
; CHECK: getelementptr i32, ptr addrspace(1) %base, i32 15
2223
; CHECK: getelementptr i32, ptr addrspace(1) %base, i32 12
23-
; CHECK: getelementptr i32, ptr addrspace(1) %base-new, i32 12
2424
; CHECK: getelementptr i32, ptr addrspace(1) %base-new, i32 15
25+
; CHECK: getelementptr i32, ptr addrspace(1) %base-new, i32 12
2526
entry:
2627
%ptr = getelementptr i32, ptr addrspace(1) %base, i32 15
2728
%ptr2 = getelementptr i32, ptr addrspace(1) %base, i32 12
@@ -34,6 +35,7 @@ entry:
3435
}
3536

3637
define i32 @test_sor_ooo(ptr addrspace(1) %base) gc "statepoint-example" {
38+
; CHECK-LABEL: @test_sor_ooo(
3739
; CHECK: getelementptr i32, ptr addrspace(1) %base, i32 15
3840
; CHECK: getelementptr i32, ptr addrspace(1) %base-new, i32 15
3941
entry:

0 commit comments

Comments
 (0)