Skip to content

Commit a2bca29

Browse files
cuonglmgopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Keith Randall <[email protected]> Auto-Submit: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: xiaodong liu <[email protected]> Reviewed-by: WANG Xuerui <[email protected]>
1 parent 2138124 commit a2bca29

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

src/cmd/compile/internal/ssa/gen/LOONG64.rules

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,10 +617,10 @@
617617
(SRLVconst [c] (MOVVconst [d])) => (MOVVconst [int64(uint64(d)>>uint64(c))])
618618
(SRAVconst [c] (MOVVconst [d])) => (MOVVconst [d>>uint64(c)])
619619
(Select1 (MULVU (MOVVconst [c]) (MOVVconst [d]))) => (MOVVconst [c*d])
620-
(Select1 (DIVV (MOVVconst [c]) (MOVVconst [d]))) => (MOVVconst [c/d])
621-
(Select1 (DIVVU (MOVVconst [c]) (MOVVconst [d]))) => (MOVVconst [int64(uint64(c)/uint64(d))])
622-
(Select0 (DIVV (MOVVconst [c]) (MOVVconst [d]))) => (MOVVconst [c%d]) // mod
623-
(Select0 (DIVVU (MOVVconst [c]) (MOVVconst [d]))) => (MOVVconst [int64(uint64(c)%uint64(d))]) // mod
620+
(Select1 (DIVV (MOVVconst [c]) (MOVVconst [d]))) && d != 0 => (MOVVconst [c/d])
621+
(Select1 (DIVVU (MOVVconst [c]) (MOVVconst [d]))) && d != 0 => (MOVVconst [int64(uint64(c)/uint64(d))])
622+
(Select0 (DIVV (MOVVconst [c]) (MOVVconst [d]))) && d != 0 => (MOVVconst [c%d]) // mod
623+
(Select0 (DIVVU (MOVVconst [c]) (MOVVconst [d]))) && d != 0 => (MOVVconst [int64(uint64(c)%uint64(d))]) // mod
624624
(ANDconst [c] (MOVVconst [d])) => (MOVVconst [c&d])
625625
(ANDconst [c] (ANDconst [d] x)) => (ANDconst [c&d] x)
626626
(ORconst [c] (MOVVconst [d])) => (MOVVconst [c|d])

src/cmd/compile/internal/ssa/rewriteLOONG64.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixedbugs/issue53018.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// compile
2+
3+
// Copyright 2022 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package p
8+
9+
var V []int
10+
11+
func f(i int, c chan int) int {
12+
arr := []int{0, 1}
13+
for range c {
14+
for a2 := range arr {
15+
var a []int
16+
V = V[:1/a2]
17+
a[i] = 0
18+
}
19+
return func() int {
20+
arr = []int{}
21+
return func() int {
22+
return func() int {
23+
return func() int { return 4 }()
24+
}()
25+
}()
26+
}()
27+
}
28+
29+
return 0
30+
}

0 commit comments

Comments
 (0)