Skip to content

Commit cd65d49

Browse files
committed
[AMDGPU] Create local KnownBits in case DenseMap gets invalidated
1 parent 50866e8 commit cd65d49

File tree

2 files changed

+126
-2
lines changed

2 files changed

+126
-2
lines changed

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,12 @@ static void knownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM,
537537

538538
// Variable value retrieval is not for actual use but only for knownbits
539539
// analysis.
540-
knownBitsMapHelper(Sym.getVariableValue(/*SetUsed=*/false), KBM, Depth + 1);
541-
KBM[Expr] = KBM[Sym.getVariableValue(/*SetUsed=*/false)];
540+
const MCExpr *SymVal = Sym.getVariableValue(/*setUsed=*/false);
541+
knownBitsMapHelper(SymVal, KBM, Depth + 1);
542+
543+
// Explicitly copy-construct so that there exists a local KnownBits in case
544+
// KBM[SymVal] gets invalidated after a potential growth through KBM[Expr].
545+
KBM[Expr] = KnownBits(KBM[SymVal]);
542546
return;
543547
}
544548
case MCExpr::ExprKind::Unary: {
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
; REQUIRES: asserts
2+
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1030 -o - %s 2>&1 | FileCheck %s
3+
4+
; CHECK-NOT: Assertion `BitWidth == RHS.BitWidth && "Bit widths must be same for comparison"' failed
5+
6+
define void @RunTic() {
7+
%call5.i1 = call i32 @G_CheckDemoStatus()
8+
tail call void @D_AdvanceDemo()
9+
call void @G_Ticker()
10+
ret void
11+
}
12+
13+
define void @G_Ticker() {
14+
call void @G_DoReborn()
15+
tail call void @F_Ticker()
16+
tail call void @AM_Stop()
17+
tail call void @F_StartFinale()
18+
tail call void @D_AdvanceDemo()
19+
%call.i.i449 = call i32 @R_FlatNumForName()
20+
%call9.i.i = call i32 @R_TextureNumForName()
21+
%call.i306 = tail call ptr @P_TempSaveGameFile()
22+
%call1.i307 = call ptr @P_SaveGameFile()
23+
call void (...) @I_Error()
24+
ret void
25+
}
26+
27+
define void @G_DoReborn() {
28+
call void @P_RemoveMobj()
29+
call void @P_SpawnMobj()
30+
call void @P_SpawnPlayer()
31+
call void (...) @I_Error()
32+
ret void
33+
}
34+
35+
define void @AM_Stop() {
36+
ret void
37+
}
38+
39+
define void @D_AdvanceDemo() {
40+
ret void
41+
}
42+
43+
define void @F_StartFinale() {
44+
ret void
45+
}
46+
47+
define void @F_Ticker() {
48+
ret void
49+
}
50+
51+
define void @G_PlayerReborn() {
52+
ret void
53+
}
54+
55+
define i32 @G_CheckDemoStatus() {
56+
tail call void @I_Quit()
57+
tail call void @D_AdvanceDemo()
58+
call void (...) @I_Error()
59+
ret i32 0
60+
}
61+
62+
define void @HU_Start() {
63+
ret void
64+
}
65+
66+
define void @I_Quit() {
67+
%fptr = load ptr, ptr null, align 8
68+
tail call void %fptr()
69+
ret void
70+
}
71+
72+
define void @P_SetThingPosition() {
73+
ret void
74+
}
75+
76+
define void @P_RemoveMobj() {
77+
ret void
78+
}
79+
80+
define void @P_SpawnMobj() {
81+
ret void
82+
}
83+
84+
define void @P_SpawnPlayer() {
85+
call void @G_PlayerReborn()
86+
call void @P_SetThingPosition()
87+
call void @P_SetupPsprites(ptr addrspace(1) null)
88+
tail call void @HU_Start()
89+
ret void
90+
}
91+
92+
define void @P_SetupPsprites(ptr addrspace(1) %i) {
93+
%fptr = load ptr, ptr addrspace(1) %i, align 8
94+
tail call void %fptr()
95+
ret void
96+
}
97+
98+
define ptr @P_TempSaveGameFile() {
99+
ret ptr null
100+
}
101+
102+
define ptr @P_SaveGameFile() {
103+
ret ptr null
104+
}
105+
106+
define i32 @R_TextureNumForName() {
107+
%ret = call i32 @R_FlatNumForName()
108+
ret i32 0
109+
}
110+
111+
define void @I_Error(...) {
112+
%fptr = load ptr, ptr null, align 8
113+
call void %fptr()
114+
ret void
115+
}
116+
117+
define i32 @R_FlatNumForName() {
118+
call void (...) @I_Error()
119+
unreachable
120+
}

0 commit comments

Comments
 (0)