mirror of
https://github.com/golang/go
synced 2024-11-06 15:26:13 -07:00
6a64efc250
(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 Reviewed-on: https://go-review.googlesource.com/c/155798 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
24 lines
417 B
Go
24 lines
417 B
Go
// run
|
|
|
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Issue 29402: wrong optimization of comparison of
|
|
// constant and shift on MIPS.
|
|
|
|
package main
|
|
|
|
//go:noinline
|
|
func F(s []int) bool {
|
|
half := len(s) / 2
|
|
return half >= 0
|
|
}
|
|
|
|
func main() {
|
|
b := F([]int{1, 2, 3, 4})
|
|
if !b {
|
|
panic("FAIL")
|
|
}
|
|
}
|