Skip to content

Commit 4ef3a42

Browse files
committed
compiler/testdata: update zero map key padding bytes test
1 parent 7d04806 commit 4ef3a42

File tree

2 files changed

+153
-91
lines changed

2 files changed

+153
-91
lines changed

compiler/testdata/zeromap.go

+27-10
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,32 @@ type hasPadding struct {
66
b2 bool
77
}
88

9+
type nestedPadding struct {
10+
b bool
11+
hasPadding
12+
i int
13+
}
14+
15+
//go:noinline
16+
func testZeroGet(m map[hasPadding]int, s hasPadding) int {
17+
return m[s]
18+
}
19+
20+
//go:noinline
21+
func testZeroSet(m map[hasPadding]int, s hasPadding) {
22+
m[s] = 5
23+
}
24+
25+
//go:noinline
26+
func testZeroArrayGet(m map[[2]hasPadding]int, s [2]hasPadding) int {
27+
return m[s]
28+
}
29+
30+
//go:noinline
31+
func testZeroArraySet(m map[[2]hasPadding]int, s [2]hasPadding) {
32+
m[s] = 5
33+
}
34+
935
func main() {
10-
m := make(map[hasPadding]int)
11-
var s hasPadding
12-
13-
for i := 0; i < 10; i++ {
14-
s.b1 = i&1 == 0
15-
s.i = i
16-
s.b2 = i&1 == 1
17-
m[s]++
18-
}
19-
println(len(m))
36+
2037
}

compiler/testdata/zeromap.ll

+126-81
Original file line numberDiff line numberDiff line change
@@ -15,111 +15,156 @@ entry:
1515
ret void
1616
}
1717

18-
; Function Attrs: nounwind
19-
define hidden void @main.main(ptr %context) unnamed_addr #1 {
18+
; Function Attrs: noinline nounwind
19+
define hidden i32 @main.testZeroGet(ptr dereferenceable_or_null(40) %m, i1 %s.b1, i32 %s.i, i1 %s.b2, ptr %context) unnamed_addr #2 {
2020
entry:
21-
%hashmap.key6 = alloca %main.hasPadding, align 8
22-
%hashmap.value5 = alloca i32, align 4
2321
%hashmap.key = alloca %main.hasPadding, align 8
2422
%hashmap.value = alloca i32, align 4
2523
%s = alloca %main.hasPadding, align 8
24+
%0 = insertvalue %main.hasPadding zeroinitializer, i1 %s.b1, 0
25+
%1 = insertvalue %main.hasPadding %0, i32 %s.i, 1
26+
%2 = insertvalue %main.hasPadding %1, i1 %s.b2, 2
2627
%stackalloc = alloca i8, align 1
27-
%0 = call ptr @runtime.hashmapMake(i32 12, i32 4, i32 8, i8 0, ptr undef) #3
28-
call void @runtime.trackPointer(ptr %0, ptr nonnull %stackalloc, ptr undef) #3
2928
store %main.hasPadding zeroinitializer, ptr %s, align 8
30-
call void @runtime.trackPointer(ptr nonnull %s, ptr nonnull %stackalloc, ptr undef) #3
31-
br label %for.loop
32-
33-
for.loop: ; preds = %store.next4, %entry
34-
%1 = phi i32 [ 0, %entry ], [ %17, %store.next4 ]
35-
%2 = icmp slt i32 %1, 10
36-
br i1 %2, label %for.body, label %for.done
37-
38-
for.body: ; preds = %for.loop
39-
br i1 false, label %store.throw, label %store.next
40-
41-
store.next: ; preds = %for.body
42-
%3 = and i32 %1, 1
43-
%4 = icmp eq i32 %3, 0
44-
store i1 %4, ptr %s, align 8
45-
br i1 false, label %store.throw1, label %store.next2
46-
47-
store.next2: ; preds = %store.next
48-
%5 = getelementptr inbounds %main.hasPadding, ptr %s, i32 0, i32 1
49-
store i32 %1, ptr %5, align 4
50-
br i1 false, label %store.throw3, label %store.next4
51-
52-
store.next4: ; preds = %store.next2
53-
%6 = getelementptr inbounds %main.hasPadding, ptr %s, i32 0, i32 2
54-
%7 = and i32 %1, 1
55-
%8 = icmp ne i32 %7, 0
56-
store i1 %8, ptr %6, align 8
57-
%9 = load %main.hasPadding, ptr %s, align 8
29+
call void @runtime.trackPointer(ptr nonnull %s, ptr nonnull %stackalloc, ptr undef) #4
30+
store %main.hasPadding %2, ptr %s, align 8
5831
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value)
5932
call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %hashmap.key)
60-
store %main.hasPadding %9, ptr %hashmap.key, align 8
61-
%10 = getelementptr inbounds i8, ptr %hashmap.key, i32 1
62-
call void @runtime.memzero(ptr nonnull %10, i32 3, ptr undef) #3
63-
%11 = getelementptr inbounds i8, ptr %hashmap.key, i32 9
64-
call void @runtime.memzero(ptr nonnull %11, i32 3, ptr undef) #3
65-
%12 = call i1 @runtime.hashmapBinaryGet(ptr %0, ptr nonnull %hashmap.key, ptr nonnull %hashmap.value, i32 4, ptr undef) #3
33+
store %main.hasPadding %2, ptr %hashmap.key, align 8
34+
%3 = getelementptr inbounds ptr, ptr %hashmap.key, i32 1
35+
call void @runtime.memzero(ptr nonnull %3, i32 3, ptr undef) #4
36+
%4 = getelementptr inbounds i8, ptr %hashmap.key, i32 9
37+
call void @runtime.memzero(ptr nonnull %4, i32 3, ptr undef) #4
38+
%5 = call i1 @runtime.hashmapBinaryGet(ptr %m, ptr nonnull %hashmap.key, ptr nonnull %hashmap.value, i32 4, ptr undef) #4
6639
call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %hashmap.key)
67-
%13 = load i32, ptr %hashmap.value, align 4
40+
%6 = load i32, ptr %hashmap.value, align 4
6841
call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %hashmap.value)
69-
%14 = add i32 %13, 1
70-
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value5)
71-
store i32 %14, ptr %hashmap.value5, align 4
72-
call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %hashmap.key6)
73-
store %main.hasPadding %9, ptr %hashmap.key6, align 8
74-
%15 = getelementptr inbounds i8, ptr %hashmap.key6, i32 1
75-
call void @runtime.memzero(ptr nonnull %15, i32 3, ptr undef) #3
76-
%16 = getelementptr inbounds i8, ptr %hashmap.key6, i32 9
77-
call void @runtime.memzero(ptr nonnull %16, i32 3, ptr undef) #3
78-
call void @runtime.hashmapBinarySet(ptr %0, ptr nonnull %hashmap.key6, ptr nonnull %hashmap.value5, ptr undef) #3
79-
call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %hashmap.key6)
80-
call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %hashmap.value5)
81-
%17 = add i32 %1, 1
82-
br label %for.loop
83-
84-
for.done: ; preds = %for.loop
85-
%len = call i32 @runtime.hashmapLen(ptr %0, ptr undef) #3
86-
call void @runtime.printint32(i32 %len, ptr undef) #3
87-
call void @runtime.printnl(ptr undef) #3
88-
ret void
89-
90-
store.throw: ; preds = %for.body
91-
unreachable
92-
93-
store.throw1: ; preds = %store.next
94-
unreachable
95-
96-
store.throw3: ; preds = %store.next2
97-
unreachable
42+
ret i32 %6
9843
}
9944

100-
declare ptr @runtime.hashmapMake(i32, i32, i32, i8, ptr) #0
101-
102-
declare void @runtime.nilPanic(ptr) #0
103-
10445
; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn
105-
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2
46+
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3
10647

10748
declare void @runtime.memzero(ptr, i32, ptr) #0
10849

10950
declare i1 @runtime.hashmapBinaryGet(ptr dereferenceable_or_null(40), ptr, ptr, i32, ptr) #0
11051

11152
; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn
112-
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2
53+
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3
54+
55+
; Function Attrs: noinline nounwind
56+
define hidden void @main.testZeroSet(ptr dereferenceable_or_null(40) %m, i1 %s.b1, i32 %s.i, i1 %s.b2, ptr %context) unnamed_addr #2 {
57+
entry:
58+
%hashmap.key = alloca %main.hasPadding, align 8
59+
%hashmap.value = alloca i32, align 4
60+
%s = alloca %main.hasPadding, align 8
61+
%0 = insertvalue %main.hasPadding zeroinitializer, i1 %s.b1, 0
62+
%1 = insertvalue %main.hasPadding %0, i32 %s.i, 1
63+
%2 = insertvalue %main.hasPadding %1, i1 %s.b2, 2
64+
%stackalloc = alloca i8, align 1
65+
store %main.hasPadding zeroinitializer, ptr %s, align 8
66+
call void @runtime.trackPointer(ptr nonnull %s, ptr nonnull %stackalloc, ptr undef) #4
67+
store %main.hasPadding %2, ptr %s, align 8
68+
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value)
69+
store i32 5, ptr %hashmap.value, align 4
70+
call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %hashmap.key)
71+
store %main.hasPadding %2, ptr %hashmap.key, align 8
72+
%3 = getelementptr inbounds ptr, ptr %hashmap.key, i32 1
73+
call void @runtime.memzero(ptr nonnull %3, i32 3, ptr undef) #4
74+
%4 = getelementptr inbounds i8, ptr %hashmap.key, i32 9
75+
call void @runtime.memzero(ptr nonnull %4, i32 3, ptr undef) #4
76+
call void @runtime.hashmapBinarySet(ptr %m, ptr nonnull %hashmap.key, ptr nonnull %hashmap.value, ptr undef) #4
77+
call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %hashmap.key)
78+
call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %hashmap.value)
79+
ret void
80+
}
11381

11482
declare void @runtime.hashmapBinarySet(ptr dereferenceable_or_null(40), ptr, ptr, ptr) #0
11583

116-
declare i32 @runtime.hashmapLen(ptr dereferenceable_or_null(40), ptr) #0
84+
; Function Attrs: noinline nounwind
85+
define hidden i32 @main.testZeroArrayGet(ptr dereferenceable_or_null(40) %m, [2 x %main.hasPadding] %s, ptr %context) unnamed_addr #2 {
86+
entry:
87+
%hashmap.key = alloca [2 x %main.hasPadding], align 8
88+
%hashmap.value = alloca i32, align 4
89+
%s1 = alloca [2 x %main.hasPadding], align 8
90+
%stackalloc = alloca i8, align 1
91+
store %main.hasPadding zeroinitializer, ptr %s1, align 8
92+
%s1.repack2 = getelementptr inbounds [2 x %main.hasPadding], ptr %s1, i32 0, i32 1
93+
store %main.hasPadding zeroinitializer, ptr %s1.repack2, align 4
94+
call void @runtime.trackPointer(ptr nonnull %s1, ptr nonnull %stackalloc, ptr undef) #4
95+
%s.elt = extractvalue [2 x %main.hasPadding] %s, 0
96+
store %main.hasPadding %s.elt, ptr %s1, align 8
97+
%s1.repack3 = getelementptr inbounds [2 x %main.hasPadding], ptr %s1, i32 0, i32 1
98+
%s.elt4 = extractvalue [2 x %main.hasPadding] %s, 1
99+
store %main.hasPadding %s.elt4, ptr %s1.repack3, align 4
100+
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value)
101+
call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %hashmap.key)
102+
%s.elt7 = extractvalue [2 x %main.hasPadding] %s, 0
103+
store %main.hasPadding %s.elt7, ptr %hashmap.key, align 8
104+
%hashmap.key.repack8 = getelementptr inbounds [2 x %main.hasPadding], ptr %hashmap.key, i32 0, i32 1
105+
%s.elt9 = extractvalue [2 x %main.hasPadding] %s, 1
106+
store %main.hasPadding %s.elt9, ptr %hashmap.key.repack8, align 4
107+
%0 = getelementptr inbounds ptr, ptr %hashmap.key, i32 1
108+
call void @runtime.memzero(ptr nonnull %0, i32 3, ptr undef) #4
109+
%1 = getelementptr inbounds i8, ptr %hashmap.key, i32 9
110+
call void @runtime.memzero(ptr nonnull %1, i32 3, ptr undef) #4
111+
%2 = getelementptr inbounds [2 x %main.hasPadding], ptr %hashmap.key, i32 0, i32 1, i32 1
112+
call void @runtime.memzero(ptr nonnull %2, i32 3, ptr undef) #4
113+
%3 = getelementptr inbounds i8, ptr %hashmap.key, i32 21
114+
call void @runtime.memzero(ptr nonnull %3, i32 3, ptr undef) #4
115+
%4 = call i1 @runtime.hashmapBinaryGet(ptr %m, ptr nonnull %hashmap.key, ptr nonnull %hashmap.value, i32 4, ptr undef) #4
116+
call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %hashmap.key)
117+
%5 = load i32, ptr %hashmap.value, align 4
118+
call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %hashmap.value)
119+
ret i32 %5
120+
}
117121

118-
declare void @runtime.printint32(i32, ptr) #0
122+
; Function Attrs: noinline nounwind
123+
define hidden void @main.testZeroArraySet(ptr dereferenceable_or_null(40) %m, [2 x %main.hasPadding] %s, ptr %context) unnamed_addr #2 {
124+
entry:
125+
%hashmap.key = alloca [2 x %main.hasPadding], align 8
126+
%hashmap.value = alloca i32, align 4
127+
%s1 = alloca [2 x %main.hasPadding], align 8
128+
%stackalloc = alloca i8, align 1
129+
store %main.hasPadding zeroinitializer, ptr %s1, align 8
130+
%s1.repack2 = getelementptr inbounds [2 x %main.hasPadding], ptr %s1, i32 0, i32 1
131+
store %main.hasPadding zeroinitializer, ptr %s1.repack2, align 4
132+
call void @runtime.trackPointer(ptr nonnull %s1, ptr nonnull %stackalloc, ptr undef) #4
133+
%s.elt = extractvalue [2 x %main.hasPadding] %s, 0
134+
store %main.hasPadding %s.elt, ptr %s1, align 8
135+
%s1.repack3 = getelementptr inbounds [2 x %main.hasPadding], ptr %s1, i32 0, i32 1
136+
%s.elt4 = extractvalue [2 x %main.hasPadding] %s, 1
137+
store %main.hasPadding %s.elt4, ptr %s1.repack3, align 4
138+
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value)
139+
store i32 5, ptr %hashmap.value, align 4
140+
call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %hashmap.key)
141+
%s.elt7 = extractvalue [2 x %main.hasPadding] %s, 0
142+
store %main.hasPadding %s.elt7, ptr %hashmap.key, align 8
143+
%hashmap.key.repack8 = getelementptr inbounds [2 x %main.hasPadding], ptr %hashmap.key, i32 0, i32 1
144+
%s.elt9 = extractvalue [2 x %main.hasPadding] %s, 1
145+
store %main.hasPadding %s.elt9, ptr %hashmap.key.repack8, align 4
146+
%0 = getelementptr inbounds ptr, ptr %hashmap.key, i32 1
147+
call void @runtime.memzero(ptr nonnull %0, i32 3, ptr undef) #4
148+
%1 = getelementptr inbounds i8, ptr %hashmap.key, i32 9
149+
call void @runtime.memzero(ptr nonnull %1, i32 3, ptr undef) #4
150+
%2 = getelementptr inbounds [2 x %main.hasPadding], ptr %hashmap.key, i32 0, i32 1, i32 1
151+
call void @runtime.memzero(ptr nonnull %2, i32 3, ptr undef) #4
152+
%3 = getelementptr inbounds i8, ptr %hashmap.key, i32 21
153+
call void @runtime.memzero(ptr nonnull %3, i32 3, ptr undef) #4
154+
call void @runtime.hashmapBinarySet(ptr %m, ptr nonnull %hashmap.key, ptr nonnull %hashmap.value, ptr undef) #4
155+
call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %hashmap.key)
156+
call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %hashmap.value)
157+
ret void
158+
}
119159

120-
declare void @runtime.printnl(ptr) #0
160+
; Function Attrs: nounwind
161+
define hidden void @main.main(ptr %context) unnamed_addr #1 {
162+
entry:
163+
ret void
164+
}
121165

122166
attributes #0 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" }
123167
attributes #1 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" }
124-
attributes #2 = { argmemonly nocallback nofree nosync nounwind willreturn }
125-
attributes #3 = { nounwind }
168+
attributes #2 = { noinline nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" }
169+
attributes #3 = { argmemonly nocallback nofree nosync nounwind willreturn }
170+
attributes #4 = { nounwind }

0 commit comments

Comments
 (0)