Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: lack of constant folding in array addressing for the stack on ppc64le #17134

Closed
laboger opened this issue Sep 16, 2016 · 5 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@laboger
Copy link
Contributor

laboger commented Sep 16, 2016

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

gotip

What operating system and processor architecture are you using (go env)?

Ubuntu 16.04 ppc64le

What did you do?

Compiled a simple testcase using arrays declared on the stack, then looked at an objdump.
package main
arrtest1.go.txt

What did you expect to see?

Efficient generated code.

What did you see instead?

Opportunities for improvement.

11024: 00 01 61 38 addi r3,r1,256
11028: 98 00 83 38 addi r4,r3,152
1102c: f8 ff 63 38 addi r3,r3,-8
11030: 09 00 03 f8 stdu r0,8(r3)

Instead of 3 addi, the constant values could all be combined and a single addi used:

addi r3,r1,400 // 256+152-8

I know this might be due to the way I wrote this rule.

@laboger
Copy link
Contributor Author

laboger commented Sep 23, 2016

I'm seeing this:
main
b1:
v1 = InitMem
v5 = VarDef {x} v1
v2 = SP : SP
v54 = MOVDaddr <[20]int> {x} v2 : R3
v137 = ADDconst <
[20]int> [152] v54 : R4
v6 = LoweredZero [8] v54 v137 v5
v8 = VarDef {y} v6
v97 = MOVDaddr <[20]int> {y} v2 : R3
v116 = ADDconst <
[20]int> [152] v97 : R4
v9 = LoweredZero [8] v97 v116 v8
v112 = MOVDconst [20] : R4
v16 = MOVDaddr <*[20]int> {x} v2 : R5
v17 = MOVDconst [0] : R6
Plain -> b2

This is being done to clear the storage (LoweredZero). Looks like the LoweredZero generates the last ADD of -8 to make the stdu work correctly. Perhaps that can't be combined because it is part of the LoweredZero, although I don't understand why the first two aren't combined.

@randall77
Copy link
Contributor

randall77 commented Sep 23, 2016

The first two need a rule to combine ADDconst and MOVDaddr.
Something like

(ADDconst [c] (MOVDaddr [d] {sym} base)) -> (MOVDaddr [c+d] {sym} base)

The equivalent rule in AMD64.rules is:

(ADDQconst [c] (LEAQ [d] {s} x)) && is32Bit(c+d) -> (LEAQ [c+d] {s} x)

The add of -8 is done during ssa->prog so it can't be optimized away by SSA. The -8 is done there because if it was explicit in the SSA form, it would generate a pointer outside the bounds of the object it was pointing to. We can't let the GC see such a pointer.

@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 3, 2016
@quentinmit quentinmit added this to the Go1.8 milestone Oct 3, 2016
@laboger
Copy link
Contributor Author

laboger commented Oct 18, 2016

This rule is already in PPC64.rules:

(ADDconst [c] (MOVDaddr [d] {sym} x)) -> (MOVDaddr [c+d] {sym} x)

@randall77
Copy link
Contributor

Looks like it got added in 2f0b8f88
Is this fixed then?

@laboger
Copy link
Contributor Author

laboger commented Oct 18, 2016

Ooops I should have checked that first! It looks fine now except for the unnecessary add of -8, but I understand the reason why that can't go away. So this can be closed?

@golang golang locked and limited conversation to collaborators Oct 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants