-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Open
Labels
Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Milestone
Description
package p
func f() int {
x := 0
for i := 0; i < 10; i++ {
odd := 0
if i%2 == 0 {
odd = 2 // not 1, otherwise this branch gets optimized away!
}
x += odd
// Distract the layout pass with a bunch of loops.
for j := 0; j < 10; j++ {
for j := 0; j < 10; j++ {
for j := 0; j < 10; j++ {
x++
}
}
}
}
return x
}
In this code, we have even odds of the if i%2 == 0
branch being taken. But the code layout is pretty uneven. In this CFG, b3 is that branch, and b6 and b19 are the taken/not-taken blocks; both feed into b7. It seems like a good layout for this would be b3 b6 b19 b7 or b3 b19 b6 b7. But we put b19 at the very end of the function.
This is a simplified version of something that also happens in the fannkuch benchmark. See also #20355 and #18977.
For details on how to read this image, see #20355.
cc @randall77 @dr2chase @cherrymui
Marking 1.9Maybe because we removed the old backend's instruction re-ordering pass during 1.9; this may help prevent regressions from that.
Metadata
Metadata
Assignees
Labels
Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.