]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: use correct types in phiopt
authorJosh Bleecher Snyder <josharian@gmail.com>
Sat, 29 Feb 2020 01:04:16 +0000 (17:04 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Sat, 29 Feb 2020 17:02:29 +0000 (17:02 +0000)
We try to preserve type correctness of generic ops.
phiopt modified a bool to be an int without a conversion.
Add a conversion. There are a few random fluctations in the
generated code as a result, but nothing noteworthy or systematic.

no binary size changes

file                        before   after    Δ       %
math.s                      35966    35961    -5      -0.014%
debug/dwarf.s               108141   108147   +6      +0.006%
crypto/dsa.s                6047     6044     -3      -0.050%
image/png.s                 42882    42885    +3      +0.007%
go/parser.s                 80281    80278    -3      -0.004%
cmd/internal/obj.s          115116   115113   -3      -0.003%
go/types.s                  322130   322118   -12     -0.004%
cmd/internal/obj/arm64.s    151679   151685   +6      +0.004%
go/internal/gccgoimporter.s 56487    56493    +6      +0.011%
cmd/test2json.s             1650     1647     -3      -0.182%
cmd/link/internal/loadelf.s 35442    35443    +1      +0.003%
cmd/go/internal/work.s      305039   305035   -4      -0.001%
cmd/link/internal/ld.s      544835   544834   -1      -0.000%
net/http.s                  558777   558774   -3      -0.001%
cmd/compile/internal/ssa.s  3926551  3926994  +443    +0.011%
cmd/compile/internal/gc.s   1552320  1552321  +1      +0.000%
total                       18862241 18862670 +429    +0.002%

Change-Id: I4289e773be6be534ea3f907d68f614441b8f9b46
Reviewed-on: https://go-review.googlesource.com/c/go/+/221607
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
23 files changed:
src/cmd/compile/internal/ssa/gen/386.rules
src/cmd/compile/internal/ssa/gen/AMD64.rules
src/cmd/compile/internal/ssa/gen/ARM.rules
src/cmd/compile/internal/ssa/gen/ARM64.rules
src/cmd/compile/internal/ssa/gen/MIPS.rules
src/cmd/compile/internal/ssa/gen/MIPS64.rules
src/cmd/compile/internal/ssa/gen/PPC64.rules
src/cmd/compile/internal/ssa/gen/RISCV64.rules
src/cmd/compile/internal/ssa/gen/S390X.rules
src/cmd/compile/internal/ssa/gen/Wasm.rules
src/cmd/compile/internal/ssa/gen/genericOps.go
src/cmd/compile/internal/ssa/opGen.go
src/cmd/compile/internal/ssa/phiopt.go
src/cmd/compile/internal/ssa/rewrite386.go
src/cmd/compile/internal/ssa/rewriteAMD64.go
src/cmd/compile/internal/ssa/rewriteARM.go
src/cmd/compile/internal/ssa/rewriteARM64.go
src/cmd/compile/internal/ssa/rewriteMIPS.go
src/cmd/compile/internal/ssa/rewriteMIPS64.go
src/cmd/compile/internal/ssa/rewritePPC64.go
src/cmd/compile/internal/ssa/rewriteRISCV64.go
src/cmd/compile/internal/ssa/rewriteS390X.go
src/cmd/compile/internal/ssa/rewriteWasm.go

index 78916bebc37cbb560020762d09fc4d0bde2bf109..64a6cbaf8496e28bd76ead2e21d3ad6d0114b00c 100644 (file)
@@ -92,6 +92,8 @@
 (Round32F ...) -> (Copy ...)
 (Round64F ...) -> (Copy ...)
 
+(CvtBoolToUint8 ...) -> (Copy ...)
+
 // Lowering shifts
 // Unsigned shifts need to return 0 if shift amount is >= width of shifted value.
 //   result = (arg << shift) & (shift >= argbits ? 0 : 0xffffffffffffffff)
index 4fd13a50568d176f0b1d8119186bbc0789444c0f..f915ea43550b30eea9727a9a36a7fdf980cf85f4 100644 (file)
 
 (Round(32|64)F ...) -> (Copy ...)
 
+(CvtBoolToUint8 ...) -> (Copy ...)
+
 // Lowering shifts
 // Unsigned shifts need to return 0 if shift amount is >= width of shifted value.
 //   result = (arg << shift) & (shift >= argbits ? 0 : 0xffffffffffffffff)
index 77e7b477c6693c6432c383ba12ef2f8099548e44..839d701b8cc24a5bb53fad8bd8ed9d36d23a5982 100644 (file)
 
 (Round(32|64)F ...) -> (Copy ...)
 
+(CvtBoolToUint8 ...) -> (Copy ...)
+
 // fused-multiply-add
 (FMA x y z) -> (FMULAD z x y)
 
index 4e0ab3288d7039c62cd3320c554eb4c38333869a..61994a15a1f7474f11793e12a3b634bf0a5394cd 100644 (file)
 (Cvt32Fto64F ...) -> (FCVTSD ...)
 (Cvt64Fto32F ...) -> (FCVTDS ...)
 
+(CvtBoolToUint8 ...) -> (Copy ...)
+
 (Round32F ...) -> (LoweredRound32F ...)
 (Round64F ...) -> (LoweredRound64F ...)
 
index 228d5ee454a2d8f5fc812971cf5172be59861d8a..9ac8e5f47129154189dcd6c0858dd17dec41961d 100644 (file)
 (Cvt32Fto64F ...) -> (MOVFD ...)
 (Cvt64Fto32F ...) -> (MOVDF ...)
 
+(CvtBoolToUint8 ...) -> (Copy ...)
+
 (Round(32|64)F ...) -> (Copy ...)
 
 // comparisons
index 35c65023cdcf421c71e3c465622a5ad943e5bed6..6df2b3e6b9f4cfbb3fe13ea3eebdb31618cb986f 100644 (file)
 (Cvt32Fto64F ...) -> (MOVFD ...)
 (Cvt64Fto32F ...) -> (MOVDF ...)
 
+(CvtBoolToUint8 ...) -> (Copy ...)
+
 (Round(32|64)F ...) -> (Copy ...)
 
 // comparisons
index d4ef49e20b7118131d72b7891fef4828eb94086a..961f833e90ab24d0849e60788a38465dd34d4be8 100644 (file)
@@ -59,6 +59,8 @@
 (Cvt32Fto64F ...) -> (Copy ...) // Note v will have the wrong type for patterns dependent on Float32/Float64
 (Cvt64Fto32F ...) -> (FRSP ...)
 
+(CvtBoolToUint8 ...) -> (Copy ...)
+
 (Round(32|64)F ...) -> (LoweredRound(32|64)F ...)
 
 (Sqrt ...) -> (FSQRT ...)
index 720724647e7b306baa56e210a984084ecc6a1926..4ab4656bd564f45a7530334105c05faee82b898e 100644 (file)
 (Cvt32Fto64F ...) -> (FCVTDS ...)
 (Cvt64Fto32F ...) -> (FCVTSD ...)
 
+(CvtBoolToUint8 ...) -> (Copy ...)
+
 (Round32F ...) -> (Copy ...)
 (Round64F ...) -> (Copy ...)
 
index 30a024975986570f2a2d7aec44ca6f78b660e69d..f2c7f62dcf559a2891596fadc71f490ce21269d7 100644 (file)
 (Cvt32Fto64F ...) -> (LDEBR ...)
 (Cvt64Fto32F ...) -> (LEDBR ...)
 
+(CvtBoolToUint8 ...) -> (Copy ...)
+
 (Round(32|64)F ...) -> (LoweredRound(32|64)F ...)
 
 // Lowering shifts
index 010adcb09578118c3542169c2dd2fe0030766eea..cdcbc28c306a9451932c49bd0777621c68ef05e2 100644 (file)
@@ -91,6 +91,8 @@
 (Cvt32Fto64F ...) -> (F64PromoteF32 ...)
 (Cvt64Fto32F ...) -> (F32DemoteF64 ...)
 
+(CvtBoolToUint8 ...) -> (Copy ...)
+
 (Round32F ...) -> (Copy ...)
 (Round64F ...) -> (Copy ...)
 
index 9f172996109ce67a8bbd7b7da5bc9f97a33e0acf..54c6968c5b16cc40ad2eecc882e82314b697f23b 100644 (file)
@@ -418,6 +418,7 @@ var genericOps = []opData{
        {name: "Cvt64Fto64", argLength: 1},
        {name: "Cvt32Fto64F", argLength: 1},
        {name: "Cvt64Fto32F", argLength: 1},
+       {name: "CvtBoolToUint8", argLength: 1},
 
        // Force rounding to precision of type.
        {name: "Round32F", argLength: 1},
index 1111316d9b35f58ca95273c2e254a14bac377270..963f1aa07ab01eb933cb03045662ca85bebae02a 100644 (file)
@@ -2584,6 +2584,7 @@ const (
        OpCvt64Fto64
        OpCvt32Fto64F
        OpCvt64Fto32F
+       OpCvtBoolToUint8
        OpRound32F
        OpRound64F
        OpIsNonNil
@@ -32561,6 +32562,11 @@ var opcodeTable = [...]opInfo{
                argLen:  1,
                generic: true,
        },
+       {
+               name:    "CvtBoolToUint8",
+               argLen:  1,
+               generic: true,
+       },
        {
                name:    "Round32F",
                argLen:  1,
index cc3319e188ac454e327f9ee8329508607c4352f7..8643fa584c3839df2ceadb9ae15471b2ace6380c 100644 (file)
@@ -148,6 +148,13 @@ func phioptint(v *Value, b0 *Block, reverse int) {
                negate = !negate
        }
 
+       a := b0.Controls[0]
+       if negate {
+               a = v.Block.NewValue1(v.Pos, OpNot, a.Type, a)
+       }
+       v.AddArg(a)
+
+       cvt := v.Block.NewValue1(v.Pos, OpCvtBoolToUint8, a.Type, a)
        switch v.Type.Size() {
        case 1:
                v.reset(OpCopy)
@@ -160,12 +167,7 @@ func phioptint(v *Value, b0 *Block, reverse int) {
        default:
                v.Fatalf("bad int size %d", v.Type.Size())
        }
-
-       a := b0.Controls[0]
-       if negate {
-               a = v.Block.NewValue1(v.Pos, OpNot, a.Type, a)
-       }
-       v.AddArg(a)
+       v.AddArg(cvt)
 
        f := b0.Func
        if f.pass.debug > 0 {
index cf9a7362a2c7e6ed947bc7909bcc4d87912666f4..4efb2d4f7422daad12e434fe39d8520c82862b43 100644 (file)
@@ -408,6 +408,9 @@ func rewriteValue386(v *Value) bool {
        case OpCvt64Fto32F:
                v.Op = Op386CVTSD2SS
                return true
+       case OpCvtBoolToUint8:
+               v.Op = OpCopy
+               return true
        case OpDiv16:
                v.Op = Op386DIVW
                return true
index 665b20c42d6af73fd8ba481e3376744a4d8a1bd3..ee7f9ad1906c80437b27db61b36786e9b423edf2 100644 (file)
@@ -780,6 +780,9 @@ func rewriteValueAMD64(v *Value) bool {
        case OpCvt64to64F:
                v.Op = OpAMD64CVTSQ2SD
                return true
+       case OpCvtBoolToUint8:
+               v.Op = OpCopy
+               return true
        case OpDiv128u:
                v.Op = OpAMD64DIVQU2
                return true
index baa3c66e0f0f556777ee5d15f1ada3189e00cad7..6849fecc2a44c0162d0a088bd85e772cee699644 100644 (file)
@@ -545,6 +545,9 @@ func rewriteValueARM(v *Value) bool {
        case OpCvt64Fto32U:
                v.Op = OpARMMOVDWU
                return true
+       case OpCvtBoolToUint8:
+               v.Op = OpCopy
+               return true
        case OpDiv16:
                return rewriteValueARM_OpDiv16(v)
        case OpDiv16u:
index 4bee98e4d3bf82b1f21adf29e55e6fd7dc93086a..51051b93b737bfd69e0ad9ab839be9ddcfd3b2c9 100644 (file)
@@ -604,6 +604,9 @@ func rewriteValueARM64(v *Value) bool {
        case OpCvt64to64F:
                v.Op = OpARM64SCVTFD
                return true
+       case OpCvtBoolToUint8:
+               v.Op = OpCopy
+               return true
        case OpDiv16:
                return rewriteValueARM64_OpDiv16(v)
        case OpDiv16u:
index f4d774c96f9e06c298c28a162d87d30229ad6af5..b3226cddb546c73d0de186c3e6056fb67cc85405 100644 (file)
@@ -129,6 +129,9 @@ func rewriteValueMIPS(v *Value) bool {
        case OpCvt64Fto32F:
                v.Op = OpMIPSMOVDF
                return true
+       case OpCvtBoolToUint8:
+               v.Op = OpCopy
+               return true
        case OpDiv16:
                return rewriteValueMIPS_OpDiv16(v)
        case OpDiv16u:
index 4139361b11d7d28937d71e8b4070cddc50d01edb..315270b16a16a65199e1f836f4faa962ae137db6 100644 (file)
@@ -154,6 +154,9 @@ func rewriteValueMIPS64(v *Value) bool {
        case OpCvt64to64F:
                v.Op = OpMIPS64MOVVD
                return true
+       case OpCvtBoolToUint8:
+               v.Op = OpCopy
+               return true
        case OpDiv16:
                return rewriteValueMIPS64_OpDiv16(v)
        case OpDiv16u:
index c4eb25f38e7c0715c4257429e2fb699806717b09..53549dda748633d789314033cc97625232368d43 100644 (file)
@@ -179,6 +179,9 @@ func rewriteValuePPC64(v *Value) bool {
                return rewriteValuePPC64_OpCvt64to32F(v)
        case OpCvt64to64F:
                return rewriteValuePPC64_OpCvt64to64F(v)
+       case OpCvtBoolToUint8:
+               v.Op = OpCopy
+               return true
        case OpDiv16:
                return rewriteValuePPC64_OpDiv16(v)
        case OpDiv16u:
index e4480dc3669fc8886332e42dd56f58144b201cb3..4d70814cfdd011fec07b8625f115aa721fb8db11 100644 (file)
@@ -114,6 +114,9 @@ func rewriteValueRISCV64(v *Value) bool {
        case OpCvt64to64F:
                v.Op = OpRISCV64FCVTDL
                return true
+       case OpCvtBoolToUint8:
+               v.Op = OpCopy
+               return true
        case OpDiv16:
                return rewriteValueRISCV64_OpDiv16(v)
        case OpDiv16u:
index 43ca2ceb92a0f42ef79b103ca98e369fabafab46..2195f6aa1e69bbe941c40e8ac0ce501f1d37d47b 100644 (file)
@@ -183,6 +183,9 @@ func rewriteValueS390X(v *Value) bool {
        case OpCvt64to64F:
                v.Op = OpS390XCDGBRA
                return true
+       case OpCvtBoolToUint8:
+               v.Op = OpCopy
+               return true
        case OpDiv16:
                return rewriteValueS390X_OpDiv16(v)
        case OpDiv16u:
index ea365f46b6997432cd97b9870697da6c872cd2b9..90701067ce066218a0f5296204afdf4a5ae92763 100644 (file)
@@ -169,6 +169,9 @@ func rewriteValueWasm(v *Value) bool {
        case OpCvt64to64F:
                v.Op = OpWasmF64ConvertI64S
                return true
+       case OpCvtBoolToUint8:
+               v.Op = OpCopy
+               return true
        case OpDiv16:
                return rewriteValueWasm_OpDiv16(v)
        case OpDiv16u: