]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix the error of absorbing boolean tests into block(FGE, FGT)
authorfanzha02 <fannie.zhang@arm.com>
Sun, 5 May 2019 03:35:37 +0000 (03:35 +0000)
committerCherry Zhang <cherryyz@google.com>
Thu, 16 May 2019 13:46:25 +0000 (13:46 +0000)
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 <powerman1st@163.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Ben Shi <powerman1st@163.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/ssa/gen/ARM64.rules
src/cmd/compile/internal/ssa/rewriteARM64.go
test/codegen/floats.go

index f3f006905c707d43b608bc286324ffd8d0a66e6c..d4b47bfb0b7cdb6d4b085a42731901156be270b6 100644 (file)
 (NZ (GreaterEqualU cc) yes no) -> (UGE cc yes no)
 (NZ (LessThanF cc) yes no) -> (FLT cc yes no)
 (NZ (LessEqualF cc) yes no) -> (FLE cc yes no)
-(NZ (GreaterThan cc) yes no) -> (FGT cc yes no)
-(NZ (GreaterEqual cc) yes no) -> (FGE cc yes no)
+(NZ (GreaterThanF cc) yes no) -> (FGT cc yes no)
+(NZ (GreaterEqualF cc) yes no) -> (FGE cc yes no)
 
 (EQ (CMPWconst [0] x:(ANDconst [c] y)) yes no) && x.Uses == 1 -> (EQ (TSTWconst [c] y) yes no)
 (NE (CMPWconst [0] x:(ANDconst [c] y)) yes no) && x.Uses == 1 -> (NE (TSTWconst [c] y) yes no)
index 7c3f3b9e0cad41074c37e637b532ee7a5cc32cfe..9dfd848bc4ebb310ce94f75232aecfe846dc219d 100644 (file)
@@ -41214,20 +41214,20 @@ func rewriteBlockARM64(b *Block) bool {
                        b.Aux = nil
                        return true
                }
-               // match: (NZ (GreaterThan cc) yes no)
+               // match: (NZ (GreaterThanF cc) yes no)
                // cond:
                // result: (FGT cc yes no)
-               for v.Op == OpARM64GreaterThan {
+               for v.Op == OpARM64GreaterThanF {
                        cc := v.Args[0]
                        b.Kind = BlockARM64FGT
                        b.SetControl(cc)
                        b.Aux = nil
                        return true
                }
-               // match: (NZ (GreaterEqual cc) yes no)
+               // match: (NZ (GreaterEqualF cc) yes no)
                // cond:
                // result: (FGE cc yes no)
-               for v.Op == OpARM64GreaterEqual {
+               for v.Op == OpARM64GreaterEqualF {
                        cc := v.Args[0]
                        b.Kind = BlockARM64FGE
                        b.SetControl(cc)
index 5e1f60b08bade788c477bcb161c66503bfb151ed..7ec36549814114f0870091fd826d7f2c28c02d51 100644 (file)
@@ -117,6 +117,11 @@ func FusedSub64_b(x, y, z float64) float64 {
        return z - x*y
 }
 
+func Cmp(f float64) bool {
+       // arm64:"FCMPD","BLE",-"CSET\tGT",-"CBZ"
+       return f > 4 || f < -4
+}
+
 // ---------------- //
 //    Non-floats    //
 // ---------------- //