From: Michael Munday Date: Thu, 6 Oct 2016 17:49:57 +0000 (-0400) Subject: cmd/compile: fold extensions into constants on s390x X-Git-Tag: go1.8beta1~991 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=122abe6b122a885c52a53044eedbd3b6905b6124;p=gostls13.git cmd/compile: fold extensions into constants on s390x We insert extensions when lowering comparisons and they were blocking constant folding. Change-Id: I804bbf91c7606612ffe921a90853844a57e55955 Reviewed-on: https://go-review.googlesource.com/30541 Reviewed-by: Cherry Zhang Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/compile/internal/ssa/gen/S390X.rules b/src/cmd/compile/internal/ssa/gen/S390X.rules index 3f1f5f86ef..c09f5b38ef 100644 --- a/src/cmd/compile/internal/ssa/gen/S390X.rules +++ b/src/cmd/compile/internal/ssa/gen/S390X.rules @@ -568,6 +568,14 @@ (MOVWZreg x:(MOVHZreg _)) -> x (MOVWZreg x:(MOVWZreg _)) -> x +// fold extensions into constants +(MOVBreg (MOVDconst [c])) -> (MOVDconst [int64(int8(c))]) +(MOVBZreg (MOVDconst [c])) -> (MOVDconst [int64(uint8(c))]) +(MOVHreg (MOVDconst [c])) -> (MOVDconst [int64(int16(c))]) +(MOVHZreg (MOVDconst [c])) -> (MOVDconst [int64(uint16(c))]) +(MOVWreg (MOVDconst [c])) -> (MOVDconst [int64(int32(c))]) +(MOVWZreg (MOVDconst [c])) -> (MOVDconst [int64(uint32(c))]) + // sign extended loads // Note: The combined instruction must end up in the same block // as the original load. If not, we end up making a value with diff --git a/src/cmd/compile/internal/ssa/rewriteS390X.go b/src/cmd/compile/internal/ssa/rewriteS390X.go index 703939a398..2c2cef1f17 100644 --- a/src/cmd/compile/internal/ssa/rewriteS390X.go +++ b/src/cmd/compile/internal/ssa/rewriteS390X.go @@ -7364,6 +7364,19 @@ func rewriteValueS390X_OpS390XMOVBZreg(v *Value, config *Config) bool { v.AddArg(x) return true } + // match: (MOVBZreg (MOVDconst [c])) + // cond: + // result: (MOVDconst [int64(uint8(c))]) + for { + v_0 := v.Args[0] + if v_0.Op != OpS390XMOVDconst { + break + } + c := v_0.AuxInt + v.reset(OpS390XMOVDconst) + v.AuxInt = int64(uint8(c)) + return true + } // match: (MOVBZreg x:(MOVBZload [off] {sym} ptr mem)) // cond: x.Uses == 1 && clobber(x) // result: @x.Block (MOVBZload [off] {sym} ptr mem) @@ -7523,6 +7536,19 @@ func rewriteValueS390X_OpS390XMOVBreg(v *Value, config *Config) bool { v.AddArg(x) return true } + // match: (MOVBreg (MOVDconst [c])) + // cond: + // result: (MOVDconst [int64(int8(c))]) + for { + v_0 := v.Args[0] + if v_0.Op != OpS390XMOVDconst { + break + } + c := v_0.AuxInt + v.reset(OpS390XMOVDconst) + v.AuxInt = int64(int8(c)) + return true + } // match: (MOVBreg x:(MOVBZload [off] {sym} ptr mem)) // cond: x.Uses == 1 && clobber(x) // result: @x.Block (MOVBload [off] {sym} ptr mem) @@ -10424,6 +10450,19 @@ func rewriteValueS390X_OpS390XMOVHZreg(v *Value, config *Config) bool { v.AddArg(x) return true } + // match: (MOVHZreg (MOVDconst [c])) + // cond: + // result: (MOVDconst [int64(uint16(c))]) + for { + v_0 := v.Args[0] + if v_0.Op != OpS390XMOVDconst { + break + } + c := v_0.AuxInt + v.reset(OpS390XMOVDconst) + v.AuxInt = int64(uint16(c)) + return true + } // match: (MOVHZreg x:(MOVHZload [off] {sym} ptr mem)) // cond: x.Uses == 1 && clobber(x) // result: @x.Block (MOVHZload [off] {sym} ptr mem) @@ -10635,6 +10674,19 @@ func rewriteValueS390X_OpS390XMOVHreg(v *Value, config *Config) bool { v.AddArg(x) return true } + // match: (MOVHreg (MOVDconst [c])) + // cond: + // result: (MOVDconst [int64(int16(c))]) + for { + v_0 := v.Args[0] + if v_0.Op != OpS390XMOVDconst { + break + } + c := v_0.AuxInt + v.reset(OpS390XMOVDconst) + v.AuxInt = int64(int16(c)) + return true + } // match: (MOVHreg x:(MOVHZload [off] {sym} ptr mem)) // cond: x.Uses == 1 && clobber(x) // result: @x.Block (MOVHload [off] {sym} ptr mem) @@ -11865,6 +11917,19 @@ func rewriteValueS390X_OpS390XMOVWZreg(v *Value, config *Config) bool { v.AddArg(x) return true } + // match: (MOVWZreg (MOVDconst [c])) + // cond: + // result: (MOVDconst [int64(uint32(c))]) + for { + v_0 := v.Args[0] + if v_0.Op != OpS390XMOVDconst { + break + } + c := v_0.AuxInt + v.reset(OpS390XMOVDconst) + v.AuxInt = int64(uint32(c)) + return true + } // match: (MOVWZreg x:(MOVWZload [off] {sym} ptr mem)) // cond: x.Uses == 1 && clobber(x) // result: @x.Block (MOVWZload [off] {sym} ptr mem) @@ -12128,6 +12193,19 @@ func rewriteValueS390X_OpS390XMOVWreg(v *Value, config *Config) bool { v.AddArg(x) return true } + // match: (MOVWreg (MOVDconst [c])) + // cond: + // result: (MOVDconst [int64(int32(c))]) + for { + v_0 := v.Args[0] + if v_0.Op != OpS390XMOVDconst { + break + } + c := v_0.AuxInt + v.reset(OpS390XMOVDconst) + v.AuxInt = int64(int32(c)) + return true + } // match: (MOVWreg x:(MOVWZload [off] {sym} ptr mem)) // cond: x.Uses == 1 && clobber(x) // result: @x.Block (MOVWload [off] {sym} ptr mem)