cmd/compile: fix MIPS SGTconst-with-shift rules
authorCherry Zhang <cherryyz@google.com>
Wed, 26 Dec 2018 00:36:25 +0000 (19:36 -0500)
committerAnthony Fok <foka@debian.org>
Fri, 28 Dec 2018 18:39:40 +0000 (18:39 +0000)
commiteee3fdb018d78c54c3dba0d4763f72e81f081018
treef6d7e328d205d0055f6ee7750d338144c5bae54e
parenta2297db3c46f3ab6a007f4d5f0a48a0be4e2447a
cmd/compile: fix MIPS SGTconst-with-shift rules

(SGTconst [c] (SRLconst _ [d])) && 0 <= int32(c) && uint32(d) <= 31 && 1<<(32-uint32(d)) <= int32(c) -> (MOVWconst [1])

This rule is problematic. 1<<(32-uint32(d)) <= int32(c) meant to
say that it is true if c is greater than the largest possible
value of the right shift. But when d==1, 1<<(32-1) is negative
and results in the wrong comparison.

Rewrite the rules in a more direct way.

Fixes #29402.

Change-Id: I5940fc9538d9bc3a4bcae8aa34672867540dc60e

Gbp-Pq: Name 0005-fix-MIPS-SGTconst-with-shift-rules.patch
src/cmd/compile/internal/ssa/gen/MIPS.rules
src/cmd/compile/internal/ssa/gen/MIPS64.rules
src/cmd/compile/internal/ssa/rewriteMIPS.go
src/cmd/compile/internal/ssa/rewriteMIPS64.go
test/fixedbugs/issue29402.go [new file with mode: 0644]