| 1 |
// Copyright 2024 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package p |
| 6 |
|
| 7 |
// This type and the following one will share the same GC shape and size. |
| 8 |
type Pointery struct { |
| 9 |
p *Pointery |
| 10 |
x [1024]int |
| 11 |
} |
| 12 |
|
| 13 |
type Pointery2 struct { |
| 14 |
p *Pointery2 |
| 15 |
x [1024]int |
| 16 |
} |
| 17 |
|
| 18 |
// This type and the following one will have the same size. |
| 19 |
type Vanilla struct { |
| 20 |
np uintptr |
| 21 |
x [1024]int |
| 22 |
} |
| 23 |
|
| 24 |
type Vanilla2 struct { |
| 25 |
np uintptr |
| 26 |
x [1023]int |
| 27 |
y int |
| 28 |
} |
| 29 |
|
| 30 |
type Single struct { |
| 31 |
np uintptr |
| 32 |
x [1023]int |
| 33 |
} |
| 34 |
|
| 35 |
var G int |
| 36 |
|
| 37 |
//go:noinline |
| 38 |
func clobber() { |
| 39 |
G++ |
| 40 |
} |
| 41 |
|
| 42 |
func ABC(i, j int) int { |
| 43 |
r := 0 |
| 44 |
|
| 45 |
// here v2 and v3 can be overlapped. |
| 46 |
clobber() |
| 47 |
if i < 101 { |
| 48 |
var v2 Vanilla |
| 49 |
v2.x[i] = j |
| 50 |
r += v2.x[j] |
| 51 |
} |
| 52 |
if j != 303 { |
| 53 |
var v3 Vanilla2 |
| 54 |
v3.x[i] = j |
| 55 |
r += v3.x[j] |
| 56 |
} |
| 57 |
clobber() |
| 58 |
|
| 59 |
// not an overlap candidate (only one var of this size). |
| 60 |
var s Single |
| 61 |
s.x[i] = j |
| 62 |
r += s.x[j] |
| 63 |
|
| 64 |
// Here p1 and p2 interfere, but p1 could be overlapped with xp3 + xp4. |
| 65 |
var p1, p2 Pointery |
| 66 |
p1.x[i] = j |
| 67 |
r += p1.x[j] |
| 68 |
p2.x[i] = j |
| 69 |
r += p2.x[j] |
| 70 |
if j != 505 { |
| 71 |
var xp3 Pointery2 |
| 72 |
xp3.x[i] = j |
| 73 |
r += xp3.x[j] |
| 74 |
} |
| 75 |
|
| 76 |
if i == j*2 { |
| 77 |
// p2 live on this path |
| 78 |
p2.x[i] += j |
| 79 |
r += p2.x[j] |
| 80 |
} else { |
| 81 |
// p2 not live on this path |
| 82 |
var xp4 Pointery2 |
| 83 |
xp4.x[i] = j |
| 84 |
r += xp4.x[j] |
| 85 |
} |
| 86 |
|
| 87 |
return r + G |
| 88 |
} |