Skip to content

Commit af278bf

Browse files
committed
cmd/compile: add additional flag constant folding rules
Fixes #73200 Change-Id: I77518d37acd838acf79ed113194bac5e2c30897f Reviewed-on: https://go-review.googlesource.com/c/go/+/663535 Reviewed-by: David Chase <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]>
1 parent 92309ff commit af278bf

File tree

3 files changed

+70
-10
lines changed

3 files changed

+70
-10
lines changed

src/cmd/compile/internal/ssa/_gen/ARM64.rules

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,16 +1385,18 @@
13851385
(CSNEG [cc] x y (InvertFlags cmp)) => (CSNEG [arm64Invert(cc)] x y cmp)
13861386

13871387
// absorb flag constants into boolean values
1388-
(Equal (FlagConstant [fc])) => (MOVDconst [b2i(fc.eq())])
1389-
(NotEqual (FlagConstant [fc])) => (MOVDconst [b2i(fc.ne())])
1390-
(LessThan (FlagConstant [fc])) => (MOVDconst [b2i(fc.lt())])
1391-
(LessThanU (FlagConstant [fc])) => (MOVDconst [b2i(fc.ult())])
1392-
(LessEqual (FlagConstant [fc])) => (MOVDconst [b2i(fc.le())])
1393-
(LessEqualU (FlagConstant [fc])) => (MOVDconst [b2i(fc.ule())])
1394-
(GreaterThan (FlagConstant [fc])) => (MOVDconst [b2i(fc.gt())])
1395-
(GreaterThanU (FlagConstant [fc])) => (MOVDconst [b2i(fc.ugt())])
1396-
(GreaterEqual (FlagConstant [fc])) => (MOVDconst [b2i(fc.ge())])
1397-
(GreaterEqualU (FlagConstant [fc])) => (MOVDconst [b2i(fc.uge())])
1388+
(Equal (FlagConstant [fc])) => (MOVDconst [b2i(fc.eq())])
1389+
(NotEqual (FlagConstant [fc])) => (MOVDconst [b2i(fc.ne())])
1390+
(LessThan (FlagConstant [fc])) => (MOVDconst [b2i(fc.lt())])
1391+
(LessThanU (FlagConstant [fc])) => (MOVDconst [b2i(fc.ult())])
1392+
(LessEqual (FlagConstant [fc])) => (MOVDconst [b2i(fc.le())])
1393+
(LessEqualU (FlagConstant [fc])) => (MOVDconst [b2i(fc.ule())])
1394+
(GreaterThan (FlagConstant [fc])) => (MOVDconst [b2i(fc.gt())])
1395+
(GreaterThanU (FlagConstant [fc])) => (MOVDconst [b2i(fc.ugt())])
1396+
(GreaterEqual (FlagConstant [fc])) => (MOVDconst [b2i(fc.ge())])
1397+
(GreaterEqualU (FlagConstant [fc])) => (MOVDconst [b2i(fc.uge())])
1398+
(LessThanNoov (FlagConstant [fc])) => (MOVDconst [b2i(fc.ltNoov())])
1399+
(GreaterEqualNoov (FlagConstant [fc])) => (MOVDconst [b2i(fc.geNoov())])
13981400

13991401
// absorb InvertFlags into boolean values
14001402
(Equal (InvertFlags x)) => (Equal x)

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

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

test/fixedbugs/issue73200.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// build
2+
3+
// Copyright 2025 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 main
8+
9+
var g bool
10+
11+
func main() {
12+
l_4 := uint32(0x6E54EE87)
13+
v4 := int8(-Int64FromInt64(1))
14+
g = int32(v4) >= safe_mod_func_int32_t_s_s(BoolInt32(l_4 >= 1), 7)
15+
}
16+
17+
func safe_mod_func_int32_t_s_s(si1 int32, si2 int32) (r int32) {
18+
var v1 int32
19+
if si2 == 0 {
20+
v1 = si1
21+
} else {
22+
v1 = si1 % si2
23+
}
24+
return v1
25+
}
26+
27+
func Int64FromInt64(n int64) int64 {
28+
return n
29+
}
30+
31+
func BoolInt32(b bool) int32 {
32+
if b {
33+
return 1
34+
}
35+
return 0
36+
}

0 commit comments

Comments
 (0)