mirror of
https://github.com/golang/go
synced 2024-11-11 20:20:23 -07:00
cmd/compile: fix loong64 constant folding in division rules
The divisor must be non-zero for the rule to be triggered. Fixes #53018 Change-Id: Id56b8d986945bbb66e13131d11264ee438de5cb2 Reviewed-on: https://go-review.googlesource.com/c/go/+/407655 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: xiaodong liu <teaofmoli@gmail.com> Reviewed-by: WANG Xuerui <git@xen0n.name>
This commit is contained in:
parent
2138124143
commit
a2bca290e7
@ -617,10 +617,10 @@
|
|||||||
(SRLVconst [c] (MOVVconst [d])) => (MOVVconst [int64(uint64(d)>>uint64(c))])
|
(SRLVconst [c] (MOVVconst [d])) => (MOVVconst [int64(uint64(d)>>uint64(c))])
|
||||||
(SRAVconst [c] (MOVVconst [d])) => (MOVVconst [d>>uint64(c)])
|
(SRAVconst [c] (MOVVconst [d])) => (MOVVconst [d>>uint64(c)])
|
||||||
(Select1 (MULVU (MOVVconst [c]) (MOVVconst [d]))) => (MOVVconst [c*d])
|
(Select1 (MULVU (MOVVconst [c]) (MOVVconst [d]))) => (MOVVconst [c*d])
|
||||||
(Select1 (DIVV (MOVVconst [c]) (MOVVconst [d]))) => (MOVVconst [c/d])
|
(Select1 (DIVV (MOVVconst [c]) (MOVVconst [d]))) && d != 0 => (MOVVconst [c/d])
|
||||||
(Select1 (DIVVU (MOVVconst [c]) (MOVVconst [d]))) => (MOVVconst [int64(uint64(c)/uint64(d))])
|
(Select1 (DIVVU (MOVVconst [c]) (MOVVconst [d]))) && d != 0 => (MOVVconst [int64(uint64(c)/uint64(d))])
|
||||||
(Select0 (DIVV (MOVVconst [c]) (MOVVconst [d]))) => (MOVVconst [c%d]) // mod
|
(Select0 (DIVV (MOVVconst [c]) (MOVVconst [d]))) && d != 0 => (MOVVconst [c%d]) // mod
|
||||||
(Select0 (DIVVU (MOVVconst [c]) (MOVVconst [d]))) => (MOVVconst [int64(uint64(c)%uint64(d))]) // mod
|
(Select0 (DIVVU (MOVVconst [c]) (MOVVconst [d]))) && d != 0 => (MOVVconst [int64(uint64(c)%uint64(d))]) // mod
|
||||||
(ANDconst [c] (MOVVconst [d])) => (MOVVconst [c&d])
|
(ANDconst [c] (MOVVconst [d])) => (MOVVconst [c&d])
|
||||||
(ANDconst [c] (ANDconst [d] x)) => (ANDconst [c&d] x)
|
(ANDconst [c] (ANDconst [d] x)) => (ANDconst [c&d] x)
|
||||||
(ORconst [c] (MOVVconst [d])) => (MOVVconst [c|d])
|
(ORconst [c] (MOVVconst [d])) => (MOVVconst [c|d])
|
||||||
|
@ -6828,6 +6828,7 @@ func rewriteValueLOONG64_OpSelect0(v *Value) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// match: (Select0 (DIVV (MOVVconst [c]) (MOVVconst [d])))
|
// match: (Select0 (DIVV (MOVVconst [c]) (MOVVconst [d])))
|
||||||
|
// cond: d != 0
|
||||||
// result: (MOVVconst [c%d])
|
// result: (MOVVconst [c%d])
|
||||||
for {
|
for {
|
||||||
if v_0.Op != OpLOONG64DIVV {
|
if v_0.Op != OpLOONG64DIVV {
|
||||||
@ -6844,11 +6845,15 @@ func rewriteValueLOONG64_OpSelect0(v *Value) bool {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
d := auxIntToInt64(v_0_1.AuxInt)
|
d := auxIntToInt64(v_0_1.AuxInt)
|
||||||
|
if !(d != 0) {
|
||||||
|
break
|
||||||
|
}
|
||||||
v.reset(OpLOONG64MOVVconst)
|
v.reset(OpLOONG64MOVVconst)
|
||||||
v.AuxInt = int64ToAuxInt(c % d)
|
v.AuxInt = int64ToAuxInt(c % d)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// match: (Select0 (DIVVU (MOVVconst [c]) (MOVVconst [d])))
|
// match: (Select0 (DIVVU (MOVVconst [c]) (MOVVconst [d])))
|
||||||
|
// cond: d != 0
|
||||||
// result: (MOVVconst [int64(uint64(c)%uint64(d))])
|
// result: (MOVVconst [int64(uint64(c)%uint64(d))])
|
||||||
for {
|
for {
|
||||||
if v_0.Op != OpLOONG64DIVVU {
|
if v_0.Op != OpLOONG64DIVVU {
|
||||||
@ -6865,6 +6870,9 @@ func rewriteValueLOONG64_OpSelect0(v *Value) bool {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
d := auxIntToInt64(v_0_1.AuxInt)
|
d := auxIntToInt64(v_0_1.AuxInt)
|
||||||
|
if !(d != 0) {
|
||||||
|
break
|
||||||
|
}
|
||||||
v.reset(OpLOONG64MOVVconst)
|
v.reset(OpLOONG64MOVVconst)
|
||||||
v.AuxInt = int64ToAuxInt(int64(uint64(c) % uint64(d)))
|
v.AuxInt = int64ToAuxInt(int64(uint64(c) % uint64(d)))
|
||||||
return true
|
return true
|
||||||
@ -7040,6 +7048,7 @@ func rewriteValueLOONG64_OpSelect1(v *Value) bool {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
// match: (Select1 (DIVV (MOVVconst [c]) (MOVVconst [d])))
|
// match: (Select1 (DIVV (MOVVconst [c]) (MOVVconst [d])))
|
||||||
|
// cond: d != 0
|
||||||
// result: (MOVVconst [c/d])
|
// result: (MOVVconst [c/d])
|
||||||
for {
|
for {
|
||||||
if v_0.Op != OpLOONG64DIVV {
|
if v_0.Op != OpLOONG64DIVV {
|
||||||
@ -7056,11 +7065,15 @@ func rewriteValueLOONG64_OpSelect1(v *Value) bool {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
d := auxIntToInt64(v_0_1.AuxInt)
|
d := auxIntToInt64(v_0_1.AuxInt)
|
||||||
|
if !(d != 0) {
|
||||||
|
break
|
||||||
|
}
|
||||||
v.reset(OpLOONG64MOVVconst)
|
v.reset(OpLOONG64MOVVconst)
|
||||||
v.AuxInt = int64ToAuxInt(c / d)
|
v.AuxInt = int64ToAuxInt(c / d)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// match: (Select1 (DIVVU (MOVVconst [c]) (MOVVconst [d])))
|
// match: (Select1 (DIVVU (MOVVconst [c]) (MOVVconst [d])))
|
||||||
|
// cond: d != 0
|
||||||
// result: (MOVVconst [int64(uint64(c)/uint64(d))])
|
// result: (MOVVconst [int64(uint64(c)/uint64(d))])
|
||||||
for {
|
for {
|
||||||
if v_0.Op != OpLOONG64DIVVU {
|
if v_0.Op != OpLOONG64DIVVU {
|
||||||
@ -7077,6 +7090,9 @@ func rewriteValueLOONG64_OpSelect1(v *Value) bool {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
d := auxIntToInt64(v_0_1.AuxInt)
|
d := auxIntToInt64(v_0_1.AuxInt)
|
||||||
|
if !(d != 0) {
|
||||||
|
break
|
||||||
|
}
|
||||||
v.reset(OpLOONG64MOVVconst)
|
v.reset(OpLOONG64MOVVconst)
|
||||||
v.AuxInt = int64ToAuxInt(int64(uint64(c) / uint64(d)))
|
v.AuxInt = int64ToAuxInt(int64(uint64(c) / uint64(d)))
|
||||||
return true
|
return true
|
||||||
|
30
test/fixedbugs/issue53018.go
Normal file
30
test/fixedbugs/issue53018.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// compile
|
||||||
|
|
||||||
|
// Copyright 2022 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.
|
||||||
|
|
||||||
|
package p
|
||||||
|
|
||||||
|
var V []int
|
||||||
|
|
||||||
|
func f(i int, c chan int) int {
|
||||||
|
arr := []int{0, 1}
|
||||||
|
for range c {
|
||||||
|
for a2 := range arr {
|
||||||
|
var a []int
|
||||||
|
V = V[:1/a2]
|
||||||
|
a[i] = 0
|
||||||
|
}
|
||||||
|
return func() int {
|
||||||
|
arr = []int{}
|
||||||
|
return func() int {
|
||||||
|
return func() int {
|
||||||
|
return func() int { return 4 }()
|
||||||
|
}()
|
||||||
|
}()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user