You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[bug] Fix crash when lowering multi-dimension groupshared variable (microsoft#5895)
This commit fixes a crash in the compiler when lowering a groupshared
variable with a multi-dimensional array type. The root cause of the bug
was that we had a nested gep expression that could not be merged into a
single gep because of an intervening addrspacecast.
The `MultiDimArrayToOneDimArray` pass flattens the multi-dimension
global variables to a single dimension. It relies on the `MergeGepUse`
function to flatten any nested geps into a single gep that fully
dereferences a scalar element.
The fix is to modify the `MergeGepUse` function to look through
addrspacecast instructions when trying to merge geps. We can now merge
geps like
gep(addrspacecast(gep(p0, gep_args0)) to p1*, gep_args1)
into
addrspacecast(gep(p0, gep_args0+gep_args1) to p1*)
We also added a call to `removeDeadConstantUsers` before flattening
multi-dimension globals because we can have some dead constants hanging
around after merging geps and these constants should be ignored by the
flattening pass.
@ArrayOfArray = addrspace(3) global [256 x [9 x float]] undef, align4
15
+
@ArrayOfArrayOfArray = addrspace(3) global [256 x [9 x [3 x float]]] undef, align4
16
+
17
+
; Test that we can merge the geps when all parts are instructions.
18
+
; CHECK-LABEL: @merge_gep_instr_instr_instr
19
+
; CHECK: load float, float* addrspacecast (float addrspace(3)* getelementptr inbounds ([2304 x float], [2304 x float] addrspace(3)* @ArrayOfArray.1dim, i32 0, i32 1) to float*)
20
+
definevoid@merge_gep_instr_instr_instr() {
21
+
entry:
22
+
%gep0 = getelementptrinbounds [256 x [9 x float]], [256 x [9 x float]] addrspace(3)* @ArrayOfArray, i320, i320
23
+
%asc = addrspacecast [9 x float] addrspace(3)* %gep0to [9 x float]*
24
+
%gep1 = getelementptrinbounds [9 x float], [9 x float]* %asc, i320, i321
25
+
%load = loadfloat, float* %gep1
26
+
retvoid
27
+
}
28
+
29
+
; Test that we can merge the geps when the inner gep are constants.
30
+
; CHECK-LABEL: @merge_gep_instr_instr_const
31
+
; CHECK: load float, float* addrspacecast (float addrspace(3)* getelementptr inbounds ([2304 x float], [2304 x float] addrspace(3)* @ArrayOfArray.1dim, i32 0, i32 1) to float*)
32
+
definevoid@merge_gep_instr_instr_const() {
33
+
entry:
34
+
%asc = addrspacecast [9 x float] addrspace(3)* getelementptrinbounds ([256 x [9 x float]], [256 x [9 x float]] addrspace(3)* @ArrayOfArray, i320, i320) to [9 x float]*
35
+
%gep1 = getelementptrinbounds [9 x float], [9 x float]* %asc, i320, i321
36
+
%load = loadfloat, float* %gep1
37
+
retvoid
38
+
}
39
+
40
+
; Test that we can merge the geps when the addrspace and inner gep are constants.
41
+
; CHECK-LABEL: @merge_gep_instr_const_const
42
+
; CHECK: load float, float* addrspacecast (float addrspace(3)* getelementptr inbounds ([2304 x float], [2304 x float] addrspace(3)* @ArrayOfArray.1dim, i32 0, i32 1) to float*)
43
+
definevoid@merge_gep_instr_const_const() {
44
+
entry:
45
+
%gep1 = getelementptrinbounds [9 x float], [9 x float]* addrspacecast ([9 x float] addrspace(3)* getelementptrinbounds ([256 x [9 x float]], [256 x [9 x float]] addrspace(3)* @ArrayOfArray, i320, i320) to [9 x float]*), i320, i321
46
+
%load = loadfloat, float* %gep1
47
+
retvoid
48
+
}
49
+
50
+
; Test that we can merge the geps when all parts are constants.
51
+
; CHECK-LABEL: @merge_gep_const_const
52
+
; CHECK: load float, float* addrspacecast (float addrspace(3)* getelementptr inbounds ([2304 x float], [2304 x float] addrspace(3)* @ArrayOfArray.1dim, i32 0, i32 1) to float*)
53
+
definevoid@merge_gep_const_const_const() {
54
+
entry:
55
+
%load = loadfloat, float* getelementptrinbounds ([9 x float], [9 x float]* addrspacecast ([9 x float] addrspace(3)* getelementptrinbounds ([256 x [9 x float]], [256 x [9 x float]] addrspace(3)* @ArrayOfArray, i320, i320) to [9 x float]*), i320, i321)
56
+
retvoid
57
+
}
58
+
59
+
; Test that we compute the correct index when the outer array has
60
+
; a non-zero constant index.
61
+
; CHECK-LABEL: @merge_gep_const_outer_array_index
62
+
; CHECK: load float, float* addrspacecast (float addrspace(3)* getelementptr inbounds ([2304 x float], [2304 x float] addrspace(3)* @ArrayOfArray.1dim, i32 0, i32 66) to float*)
63
+
definevoid@merge_gep_const_outer_array_index() {
64
+
entry:
65
+
%gep0 = getelementptrinbounds [256 x [9 x float]], [256 x [9 x float]] addrspace(3)* @ArrayOfArray, i320, i327
66
+
%asc = addrspacecast [9 x float] addrspace(3)* %gep0to [9 x float]*
67
+
%gep1 = getelementptrinbounds [9 x float], [9 x float]* %asc, i320, i323
68
+
%load = loadfloat, float* %gep1
69
+
retvoid
70
+
}
71
+
72
+
; Test that we compute the correct index when the outer array has
0 commit comments