]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: optimize (ZeroExt (Const [c]))
authorJosh Bleecher Snyder <josharian@gmail.com>
Fri, 3 Feb 2017 06:38:04 +0000 (22:38 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Fri, 3 Feb 2017 06:52:46 +0000 (06:52 +0000)
These rules trigger 116 times while running make.bash.
And at least for the sample code at
https://github.com/golang/go/issues/18906#issuecomment-277174241
they are providing optimizations not already present
in amd64.

Updates #18906

Change-Id: I410a480f566f5ab176fc573fb5ac74f9cffec225
Reviewed-on: https://go-review.googlesource.com/36217
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/ssa/gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go

index 7891d42d8ad1494ef9c74b788e98f59884934ca8..738fcef50d2901bfccfe453facd7265853708ab3 100644 (file)
 (Trunc64to32 (SignExt16to64 x)) -> (SignExt16to32 x)
 (Trunc64to32 (SignExt32to64 x)) -> x
 
+(ZeroExt8to16  (Const8  [c])) -> (Const16 [int64( uint8(c))])
+(ZeroExt8to32  (Const8  [c])) -> (Const32 [int64( uint8(c))])
+(ZeroExt8to64  (Const8  [c])) -> (Const64 [int64( uint8(c))])
+(ZeroExt16to32 (Const16 [c])) -> (Const32 [int64(uint16(c))])
+(ZeroExt16to64 (Const16 [c])) -> (Const64 [int64(uint16(c))])
+(ZeroExt32to64 (Const32 [c])) -> (Const64 [int64(uint32(c))])
+(SignExt8to16  (Const8  [c])) -> (Const16 [int64(  int8(c))])
+(SignExt8to32  (Const8  [c])) -> (Const32 [int64(  int8(c))])
+(SignExt8to64  (Const8  [c])) -> (Const64 [int64(  int8(c))])
+(SignExt16to32 (Const16 [c])) -> (Const32 [int64( int16(c))])
+(SignExt16to64 (Const16 [c])) -> (Const64 [int64( int16(c))])
+(SignExt32to64 (Const32 [c])) -> (Const64 [int64( int32(c))])
+
 // const negation is currently handled by frontend
 //(Neg8 (Const8 [c])) -> (Const8 [-c])
 //(Neg16 (Const16 [c])) -> (Const16 [-c])
index 9fcffce0c71cdba2df3943a220a006ab3450f6be..60d72b3c471107dc6dec70b1ace4d626203fff18 100644 (file)
@@ -9801,6 +9801,19 @@ func rewriteValuegeneric_OpRsh8x8(v *Value, config *Config) bool {
 func rewriteValuegeneric_OpSignExt16to32(v *Value, config *Config) bool {
        b := v.Block
        _ = b
+       // match: (SignExt16to32 (Const16 [c]))
+       // cond:
+       // result: (Const32 [int64( int16(c))])
+       for {
+               v_0 := v.Args[0]
+               if v_0.Op != OpConst16 {
+                       break
+               }
+               c := v_0.AuxInt
+               v.reset(OpConst32)
+               v.AuxInt = int64(int16(c))
+               return true
+       }
        // match: (SignExt16to32 (Trunc32to16 x:(Rsh32x64 _ (Const64 [s]))))
        // cond: s >= 16
        // result: x
@@ -9831,6 +9844,19 @@ func rewriteValuegeneric_OpSignExt16to32(v *Value, config *Config) bool {
 func rewriteValuegeneric_OpSignExt16to64(v *Value, config *Config) bool {
        b := v.Block
        _ = b
+       // match: (SignExt16to64 (Const16 [c]))
+       // cond:
+       // result: (Const64 [int64( int16(c))])
+       for {
+               v_0 := v.Args[0]
+               if v_0.Op != OpConst16 {
+                       break
+               }
+               c := v_0.AuxInt
+               v.reset(OpConst64)
+               v.AuxInt = int64(int16(c))
+               return true
+       }
        // match: (SignExt16to64 (Trunc64to16 x:(Rsh64x64 _ (Const64 [s]))))
        // cond: s >= 48
        // result: x
@@ -9861,6 +9887,19 @@ func rewriteValuegeneric_OpSignExt16to64(v *Value, config *Config) bool {
 func rewriteValuegeneric_OpSignExt32to64(v *Value, config *Config) bool {
        b := v.Block
        _ = b
+       // match: (SignExt32to64 (Const32 [c]))
+       // cond:
+       // result: (Const64 [int64( int32(c))])
+       for {
+               v_0 := v.Args[0]
+               if v_0.Op != OpConst32 {
+                       break
+               }
+               c := v_0.AuxInt
+               v.reset(OpConst64)
+               v.AuxInt = int64(int32(c))
+               return true
+       }
        // match: (SignExt32to64 (Trunc64to32 x:(Rsh64x64 _ (Const64 [s]))))
        // cond: s >= 32
        // result: x
@@ -9891,6 +9930,19 @@ func rewriteValuegeneric_OpSignExt32to64(v *Value, config *Config) bool {
 func rewriteValuegeneric_OpSignExt8to16(v *Value, config *Config) bool {
        b := v.Block
        _ = b
+       // match: (SignExt8to16  (Const8  [c]))
+       // cond:
+       // result: (Const16 [int64(  int8(c))])
+       for {
+               v_0 := v.Args[0]
+               if v_0.Op != OpConst8 {
+                       break
+               }
+               c := v_0.AuxInt
+               v.reset(OpConst16)
+               v.AuxInt = int64(int8(c))
+               return true
+       }
        // match: (SignExt8to16  (Trunc16to8  x:(Rsh16x64 _ (Const64 [s]))))
        // cond: s >= 8
        // result: x
@@ -9921,6 +9973,19 @@ func rewriteValuegeneric_OpSignExt8to16(v *Value, config *Config) bool {
 func rewriteValuegeneric_OpSignExt8to32(v *Value, config *Config) bool {
        b := v.Block
        _ = b
+       // match: (SignExt8to32  (Const8  [c]))
+       // cond:
+       // result: (Const32 [int64(  int8(c))])
+       for {
+               v_0 := v.Args[0]
+               if v_0.Op != OpConst8 {
+                       break
+               }
+               c := v_0.AuxInt
+               v.reset(OpConst32)
+               v.AuxInt = int64(int8(c))
+               return true
+       }
        // match: (SignExt8to32  (Trunc32to8  x:(Rsh32x64 _ (Const64 [s]))))
        // cond: s >= 24
        // result: x
@@ -9951,6 +10016,19 @@ func rewriteValuegeneric_OpSignExt8to32(v *Value, config *Config) bool {
 func rewriteValuegeneric_OpSignExt8to64(v *Value, config *Config) bool {
        b := v.Block
        _ = b
+       // match: (SignExt8to64  (Const8  [c]))
+       // cond:
+       // result: (Const64 [int64(  int8(c))])
+       for {
+               v_0 := v.Args[0]
+               if v_0.Op != OpConst8 {
+                       break
+               }
+               c := v_0.AuxInt
+               v.reset(OpConst64)
+               v.AuxInt = int64(int8(c))
+               return true
+       }
        // match: (SignExt8to64  (Trunc64to8  x:(Rsh64x64 _ (Const64 [s]))))
        // cond: s >= 56
        // result: x
@@ -12225,6 +12303,19 @@ func rewriteValuegeneric_OpZero(v *Value, config *Config) bool {
 func rewriteValuegeneric_OpZeroExt16to32(v *Value, config *Config) bool {
        b := v.Block
        _ = b
+       // match: (ZeroExt16to32 (Const16 [c]))
+       // cond:
+       // result: (Const32 [int64(uint16(c))])
+       for {
+               v_0 := v.Args[0]
+               if v_0.Op != OpConst16 {
+                       break
+               }
+               c := v_0.AuxInt
+               v.reset(OpConst32)
+               v.AuxInt = int64(uint16(c))
+               return true
+       }
        // match: (ZeroExt16to32 (Trunc32to16 x:(Rsh32Ux64 _ (Const64 [s]))))
        // cond: s >= 16
        // result: x
@@ -12255,6 +12346,19 @@ func rewriteValuegeneric_OpZeroExt16to32(v *Value, config *Config) bool {
 func rewriteValuegeneric_OpZeroExt16to64(v *Value, config *Config) bool {
        b := v.Block
        _ = b
+       // match: (ZeroExt16to64 (Const16 [c]))
+       // cond:
+       // result: (Const64 [int64(uint16(c))])
+       for {
+               v_0 := v.Args[0]
+               if v_0.Op != OpConst16 {
+                       break
+               }
+               c := v_0.AuxInt
+               v.reset(OpConst64)
+               v.AuxInt = int64(uint16(c))
+               return true
+       }
        // match: (ZeroExt16to64 (Trunc64to16 x:(Rsh64Ux64 _ (Const64 [s]))))
        // cond: s >= 48
        // result: x
@@ -12285,6 +12389,19 @@ func rewriteValuegeneric_OpZeroExt16to64(v *Value, config *Config) bool {
 func rewriteValuegeneric_OpZeroExt32to64(v *Value, config *Config) bool {
        b := v.Block
        _ = b
+       // match: (ZeroExt32to64 (Const32 [c]))
+       // cond:
+       // result: (Const64 [int64(uint32(c))])
+       for {
+               v_0 := v.Args[0]
+               if v_0.Op != OpConst32 {
+                       break
+               }
+               c := v_0.AuxInt
+               v.reset(OpConst64)
+               v.AuxInt = int64(uint32(c))
+               return true
+       }
        // match: (ZeroExt32to64 (Trunc64to32 x:(Rsh64Ux64 _ (Const64 [s]))))
        // cond: s >= 32
        // result: x
@@ -12315,6 +12432,19 @@ func rewriteValuegeneric_OpZeroExt32to64(v *Value, config *Config) bool {
 func rewriteValuegeneric_OpZeroExt8to16(v *Value, config *Config) bool {
        b := v.Block
        _ = b
+       // match: (ZeroExt8to16  (Const8  [c]))
+       // cond:
+       // result: (Const16 [int64( uint8(c))])
+       for {
+               v_0 := v.Args[0]
+               if v_0.Op != OpConst8 {
+                       break
+               }
+               c := v_0.AuxInt
+               v.reset(OpConst16)
+               v.AuxInt = int64(uint8(c))
+               return true
+       }
        // match: (ZeroExt8to16  (Trunc16to8  x:(Rsh16Ux64 _ (Const64 [s]))))
        // cond: s >= 8
        // result: x
@@ -12345,6 +12475,19 @@ func rewriteValuegeneric_OpZeroExt8to16(v *Value, config *Config) bool {
 func rewriteValuegeneric_OpZeroExt8to32(v *Value, config *Config) bool {
        b := v.Block
        _ = b
+       // match: (ZeroExt8to32  (Const8  [c]))
+       // cond:
+       // result: (Const32 [int64( uint8(c))])
+       for {
+               v_0 := v.Args[0]
+               if v_0.Op != OpConst8 {
+                       break
+               }
+               c := v_0.AuxInt
+               v.reset(OpConst32)
+               v.AuxInt = int64(uint8(c))
+               return true
+       }
        // match: (ZeroExt8to32  (Trunc32to8  x:(Rsh32Ux64 _ (Const64 [s]))))
        // cond: s >= 24
        // result: x
@@ -12375,6 +12518,19 @@ func rewriteValuegeneric_OpZeroExt8to32(v *Value, config *Config) bool {
 func rewriteValuegeneric_OpZeroExt8to64(v *Value, config *Config) bool {
        b := v.Block
        _ = b
+       // match: (ZeroExt8to64  (Const8  [c]))
+       // cond:
+       // result: (Const64 [int64( uint8(c))])
+       for {
+               v_0 := v.Args[0]
+               if v_0.Op != OpConst8 {
+                       break
+               }
+               c := v_0.AuxInt
+               v.reset(OpConst64)
+               v.AuxInt = int64(uint8(c))
+               return true
+       }
        // match: (ZeroExt8to64  (Trunc64to8  x:(Rsh64Ux64 _ (Const64 [s]))))
        // cond: s >= 56
        // result: x