golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.74k stars 17.63k forks source link

cmd/compile/internal/ssa: incorrect type width when folding widening ops #67884

Open pmur opened 4 months ago

pmur commented 4 months ago

Go version

tip

Output of go env in your module/workspace:

GOARCH=ppc64le

What did you do?

Further exploration of lower rule improvements has uncovered problems when using a Value Type's size to determine whether to apply a rule.

E.g the rule in PPC64.rules:

(MOVWZreg y:(AND (MOVDconst [c]) _)) && uint64(c) <= 0xFFFFFFFF => y

And later in PPC64latelower.rules:

(AND <t> x:(MOVDconst [m]) n) && t.Size() == 4 && isPPC64WordRotateMask(m) => (RLWINM [encodePPC64RotateMask(0,m,32)] n)

If m is the value 0xF000000F or a similar wrapping mask on PPC64, the upper 32 bits of the value are not always 0. I think this only affects rules which use RLWINM and RLWNM. I believe they are the only GPR opcodes on PPC64 which have this behavior.

What did you see happen?

The latelower rule is triggered in cases where the result is expected to be wider than the assigned type

What did you expect to see?

The Type of the result in lower should reflected the widened type.

gabyhelp commented 4 months ago

Similar Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

pmur commented 4 months ago

I suspect this is not causing problems today. 32 bit constants are sign extended, and thus any wrapping mask would produce a negative int32 constant, which prevents the AND rule above from running for such constants.

gopherbot commented 3 months ago

Change https://go.dev/cl/600817 mentions this issue: cmd/compile/internal/ssa: on PPC64, propogate larger type when folding widening ops