Skip to content

Commit e7e8c09

Browse files
authored
[OpaquePointers] Correctly find leader of EC in type scavenger (#2133)
Signed-off-by: Lu, John <john.lu@intel.com>
1 parent e6eae86 commit e7e8c09

File tree

2 files changed

+82
-5
lines changed

2 files changed

+82
-5
lines changed

lib/SPIRV/SPIRVTypeScavenger.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ Type *SPIRVTypeScavenger::substituteTypeVariables(Type *T) {
252252
}
253253
if (auto Index = isTypeVariable(T)) {
254254
unsigned TypeVarNum = *Index;
255-
TypeVarNum = UnifiedTypeVars.join(TypeVarNum, TypeVarNum);
255+
TypeVarNum = UnifiedTypeVars.findLeader(TypeVarNum);
256256
Type *&SubstTy = TypeVariables[TypeVarNum];
257257
// A value in TypeVariables may itself contain type variables that need to
258258
// be substituted. Substitute these as well.
@@ -273,9 +273,7 @@ bool SPIRVTypeScavenger::unifyType(Type *T1, Type *T2) {
273273
return true;
274274

275275
auto SetTypeVar = [&](unsigned TypeVarNum, Type *ActualTy) {
276-
// .findLeader doesn't work in uncompressed mode, so use .join with itself
277-
// to find the leader.
278-
unsigned Leader = UnifiedTypeVars.join(TypeVarNum, TypeVarNum);
276+
unsigned Leader = UnifiedTypeVars.findLeader(TypeVarNum);
279277

280278
// This method might be called with T1 as a concrete type containing
281279
// pointers, and we want to make sure those don't leak into type variables.
@@ -411,7 +409,7 @@ void SPIRVTypeScavenger::typeModule(Module &M) {
411409
// them as an i8* type.
412410
Type *Int8Ty = Type::getInt8Ty(M.getContext());
413411
for (const auto &[TypeVarNum, TypeVar] : enumerate(TypeVariables)) {
414-
unsigned PrimaryVar = UnifiedTypeVars.join(TypeVarNum, TypeVarNum);
412+
unsigned PrimaryVar = UnifiedTypeVars.findLeader(TypeVarNum);
415413
Type *LeaderTy = TypeVariables[PrimaryVar];
416414
if (TypeVar)
417415
TypeVar = substituteTypeVariables(TypeVar);

test/type-scavenger/equivalence.ll

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
; Test if llvm-spirv type scavenging has an assertion
2+
; failure due to incorrect lookup of an equivalence class leader.
3+
4+
; RUN: llvm-as < %s | llvm-spirv -o %t.spv
5+
; RUN: spirv-val %t.spv
6+
; RUN: llvm-spirv %t.spv -o - -to-text | FileCheck %s --check-prefix=CHECK-SPIRV
7+
; RUN: llvm-spirv %t.spv -o - -r | llvm-dis | FileCheck %s --check-prefix=CHECK-LLVM
8+
9+
; Incorrect lookup of equivalence class leader caused an assertion failure when
10+
; processing call instruction to this name
11+
; CHECK-SPIRV: _func0
12+
; CHECK-LLVM: _func0
13+
14+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
15+
target triple = "spir64-unknown-unknown"
16+
17+
define spir_func void @_func1() {
18+
entry:
19+
br label %for.cond
20+
21+
for.cond: ; preds = %for.cond, %entry
22+
%call3 = call spir_func ptr addrspace(4) @_func2()
23+
%call5 = call spir_func ptr addrspace(4) @_func0(ptr addrspace(4) %call3, i64 0)
24+
br label %for.cond
25+
}
26+
27+
define spir_func void @_func3() {
28+
entry:
29+
br label %for.cond
30+
31+
for.cond: ; preds = %for.cond, %entry
32+
%call3 = call spir_func ptr @_func4()
33+
%call3.ascast = addrspacecast ptr %call3 to ptr addrspace(4)
34+
%call5 = call spir_func ptr addrspace(4) @_func0(ptr addrspace(4) %call3.ascast, i64 0)
35+
br label %for.cond
36+
}
37+
38+
declare spir_func ptr addrspace(4) @_func5()
39+
40+
define spir_func void @_func6(ptr addrspace(4) %call3.ascast) {
41+
entry:
42+
br label %for.cond
43+
44+
for.cond: ; preds = %for.cond, %entry
45+
%call5 = call spir_func ptr addrspace(4) @_func0(ptr addrspace(4) %call3.ascast, i64 0)
46+
br label %for.cond
47+
}
48+
49+
define spir_func void @_func7() {
50+
entry:
51+
br label %for.cond
52+
53+
for.cond: ; preds = %for.cond, %entry
54+
%call3 = call spir_func ptr addrspace(4) @_func5()
55+
%call5 = call spir_func ptr addrspace(4) @_func0(ptr addrspace(4) %call3, i64 0)
56+
br label %for.cond
57+
}
58+
59+
declare spir_func ptr @_func4()
60+
61+
declare spir_func ptr addrspace(4) @_func2()
62+
63+
define spir_func ptr addrspace(4) @_func0(ptr addrspace(4) %this, i64 %index) {
64+
entry:
65+
%arrayidx = getelementptr [5 x i32], ptr addrspace(4) %this, i64 0, i64 %index
66+
ret ptr addrspace(4) null
67+
}
68+
69+
define spir_func void @_func8() {
70+
entry:
71+
br label %for.cond
72+
73+
for.cond: ; preds = %for.cond, %entry
74+
%call8 = call spir_func ptr addrspace(4) @_func0(ptr addrspace(4) null, i64 0)
75+
br label %for.cond
76+
}
77+
78+
; uselistorder directives
79+
uselistorder ptr @_func0, { 0, 4, 3, 2, 1 }

0 commit comments

Comments
 (0)