Skip to content

Commit 822a9f5

Browse files
zhangfanniecherrymui
authored andcommitted
cmd/compile: fix the error of absorbing boolean tests into block(FGE, FGT)
The CL 164718 mistyped the comparison flags. The rules for floating point comparison should be GreaterThanF and GreaterEqualF. Fortunately, the wrong optimizations were overwritten by other integer rules, so the issue won't cause failure but just some performance impact. The fixed CL optimizes the floating point test as follows. source code: func foo(f float64) bool { return f > 4 || f < -4} previous version: "FCMPD", "CSET\tGT", "CBZ" fixed version: "FCMPD", BLE" Add the test case. Change-Id: Iea954fdbb8272b2d642dae0f816dc77286e6e1fa Reviewed-on: https://go-review.googlesource.com/c/go/+/177121 Reviewed-by: Ben Shi <[email protected]> Reviewed-by: Cherry Zhang <[email protected]> Run-TryBot: Ben Shi <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 12279fa commit 822a9f5

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,8 @@
630630
(NZ (GreaterEqualU cc) yes no) -> (UGE cc yes no)
631631
(NZ (LessThanF cc) yes no) -> (FLT cc yes no)
632632
(NZ (LessEqualF cc) yes no) -> (FLE cc yes no)
633-
(NZ (GreaterThan cc) yes no) -> (FGT cc yes no)
634-
(NZ (GreaterEqual cc) yes no) -> (FGE cc yes no)
633+
(NZ (GreaterThanF cc) yes no) -> (FGT cc yes no)
634+
(NZ (GreaterEqualF cc) yes no) -> (FGE cc yes no)
635635

636636
(EQ (CMPWconst [0] x:(ANDconst [c] y)) yes no) && x.Uses == 1 -> (EQ (TSTWconst [c] y) yes no)
637637
(NE (CMPWconst [0] x:(ANDconst [c] y)) yes no) && x.Uses == 1 -> (NE (TSTWconst [c] y) yes no)

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

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/codegen/floats.go

+5
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ func FusedSub64_b(x, y, z float64) float64 {
117117
return z - x*y
118118
}
119119

120+
func Cmp(f float64) bool {
121+
// arm64:"FCMPD","BLE",-"CSET\tGT",-"CBZ"
122+
return f > 4 || f < -4
123+
}
124+
120125
// ---------------- //
121126
// Non-floats //
122127
// ---------------- //

0 commit comments

Comments
 (0)