1
0
mirror of https://github.com/golang/go synced 2024-10-05 16:51:21 -06:00

[dev.ssa] cmd/compile/internal/ssa/gen: more simplifications and foldings.

Change-Id: I74d1267dbfced2663072b4f091732c0fb328690f
Reviewed-on: https://go-review.googlesource.com/13641
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Alexandru Moșoi 2015-08-14 12:59:33 +02:00 committed by Keith Randall
parent 7a6de6d5f2
commit 198fc9a9eb
4 changed files with 413 additions and 0 deletions

View File

@ -490,6 +490,10 @@
(SUBLconst [c] (SUBLconst [d] x)) -> (ADDLconst [-c-d] x)
(SUBWconst [c] (SUBWconst [d] x)) -> (ADDWconst [-c-d] x)
(SUBBconst [c] (SUBBconst [d] x)) -> (ADDBconst [-c-d] x)
(SARQconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)])
(SARLconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)])
(SARWconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)])
(SARBconst [c] (MOVQconst [d])) -> (MOVQconst [d>>uint64(c)])
(NEGQ (MOVQconst [c])) -> (MOVQconst [-c])
(NEGL (MOVLconst [c])) -> (MOVLconst [-c])
(NEGW (MOVWconst [c])) -> (MOVWconst [-c])

View File

@ -37,6 +37,23 @@
(Neq16 x x) -> (ConstBool {false})
(Neq8 x x) -> (ConstBool {false})
// simplifications
(Or64 x x) -> x
(Or32 x x) -> x
(Or16 x x) -> x
(Or8 x x) -> x
(And64 x x) -> x
(And32 x x) -> x
(And16 x x) -> x
(And8 x x) -> x
(Xor64 x x) -> (Const64 [0])
(Xor32 x x) -> (Const32 [0])
(Xor16 x x) -> (Const16 [0])
(Xor8 x x) -> (Const8 [0])
(Sub64 x x) -> (Const64 [0])
(Sub32 x x) -> (Const32 [0])
(Sub16 x x) -> (Const16 [0])
(Sub8 x x) -> (Const8 [0])
(Com8 (Com8 x)) -> x
(Com16 (Com16 x)) -> x
(Com32 (Com32 x)) -> x

View File

@ -5974,6 +5974,26 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
goto end3bf3d17717aa6c04462e56d1c87902ce
end3bf3d17717aa6c04462e56d1c87902ce:
;
case OpAMD64SARBconst:
// match: (SARBconst [c] (MOVQconst [d]))
// cond:
// result: (MOVQconst [d>>uint64(c)])
{
c := v.AuxInt
if v.Args[0].Op != OpAMD64MOVQconst {
goto end06e0e38775f0650ed672427d19cd8fff
}
d := v.Args[0].AuxInt
v.Op = OpAMD64MOVQconst
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = d >> uint64(c)
return true
}
goto end06e0e38775f0650ed672427d19cd8fff
end06e0e38775f0650ed672427d19cd8fff:
;
case OpAMD64SARL:
// match: (SARL x (MOVLconst [c]))
// cond:
@ -5995,6 +6015,26 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
goto ende586a72c1b232ee0b63e37c71eeb8470
ende586a72c1b232ee0b63e37c71eeb8470:
;
case OpAMD64SARLconst:
// match: (SARLconst [c] (MOVQconst [d]))
// cond:
// result: (MOVQconst [d>>uint64(c)])
{
c := v.AuxInt
if v.Args[0].Op != OpAMD64MOVQconst {
goto end8f34dc94323303e75b7bcc8e731cf1db
}
d := v.Args[0].AuxInt
v.Op = OpAMD64MOVQconst
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = d >> uint64(c)
return true
}
goto end8f34dc94323303e75b7bcc8e731cf1db
end8f34dc94323303e75b7bcc8e731cf1db:
;
case OpAMD64SARQ:
// match: (SARQ x (MOVQconst [c]))
// cond:
@ -6016,6 +6056,26 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
goto end25e720ab203be2745dded5550e6d8a7c
end25e720ab203be2745dded5550e6d8a7c:
;
case OpAMD64SARQconst:
// match: (SARQconst [c] (MOVQconst [d]))
// cond:
// result: (MOVQconst [d>>uint64(c)])
{
c := v.AuxInt
if v.Args[0].Op != OpAMD64MOVQconst {
goto endd949ba69a1ff71ba62c49b39c68f269e
}
d := v.Args[0].AuxInt
v.Op = OpAMD64MOVQconst
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = d >> uint64(c)
return true
}
goto endd949ba69a1ff71ba62c49b39c68f269e
endd949ba69a1ff71ba62c49b39c68f269e:
;
case OpAMD64SARW:
// match: (SARW x (MOVWconst [c]))
// cond:
@ -6037,6 +6097,26 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
goto endc46e3f211f94238f9a0aec3c498af490
endc46e3f211f94238f9a0aec3c498af490:
;
case OpAMD64SARWconst:
// match: (SARWconst [c] (MOVQconst [d]))
// cond:
// result: (MOVQconst [d>>uint64(c)])
{
c := v.AuxInt
if v.Args[0].Op != OpAMD64MOVQconst {
goto endca23e80dba22ab574f843c7a4cef24ab
}
d := v.Args[0].AuxInt
v.Op = OpAMD64MOVQconst
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = d >> uint64(c)
return true
}
goto endca23e80dba22ab574f843c7a4cef24ab
endca23e80dba22ab574f843c7a4cef24ab:
;
case OpAMD64SBBLcarrymask:
// match: (SBBLcarrymask (CMPQconst [c] (MOVQconst [d])))
// cond: inBounds64(d, c)

View File

@ -51,6 +51,86 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
goto end145c1aec793b2befff34bc8983b48a38
end145c1aec793b2befff34bc8983b48a38:
;
case OpAnd16:
// match: (And16 x x)
// cond:
// result: x
{
x := v.Args[0]
if v.Args[1] != x {
goto end69ed6ee2a4fb0491b56c17f3c1926b10
}
v.Op = OpCopy
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.Type = x.Type
v.AddArg(x)
return true
}
goto end69ed6ee2a4fb0491b56c17f3c1926b10
end69ed6ee2a4fb0491b56c17f3c1926b10:
;
case OpAnd32:
// match: (And32 x x)
// cond:
// result: x
{
x := v.Args[0]
if v.Args[1] != x {
goto endbbe8c3c5b2ca8f013aa178d856f3a99c
}
v.Op = OpCopy
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.Type = x.Type
v.AddArg(x)
return true
}
goto endbbe8c3c5b2ca8f013aa178d856f3a99c
endbbe8c3c5b2ca8f013aa178d856f3a99c:
;
case OpAnd64:
// match: (And64 x x)
// cond:
// result: x
{
x := v.Args[0]
if v.Args[1] != x {
goto endc9736bf24d2e5cd8d662e1bcf3164640
}
v.Op = OpCopy
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.Type = x.Type
v.AddArg(x)
return true
}
goto endc9736bf24d2e5cd8d662e1bcf3164640
endc9736bf24d2e5cd8d662e1bcf3164640:
;
case OpAnd8:
// match: (And8 x x)
// cond:
// result: x
{
x := v.Args[0]
if v.Args[1] != x {
goto endeaf127389bd0d4b0e0e297830f8f463b
}
v.Op = OpCopy
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.Type = x.Type
v.AddArg(x)
return true
}
goto endeaf127389bd0d4b0e0e297830f8f463b
endeaf127389bd0d4b0e0e297830f8f463b:
;
case OpArrayIndex:
// match: (ArrayIndex (Load ptr mem) idx)
// cond:
@ -612,6 +692,86 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
goto end67d723bb0f39a5c897816abcf411e5cf
end67d723bb0f39a5c897816abcf411e5cf:
;
case OpOr16:
// match: (Or16 x x)
// cond:
// result: x
{
x := v.Args[0]
if v.Args[1] != x {
goto end47a2f25fd31a76807aced3e2b126acdc
}
v.Op = OpCopy
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.Type = x.Type
v.AddArg(x)
return true
}
goto end47a2f25fd31a76807aced3e2b126acdc
end47a2f25fd31a76807aced3e2b126acdc:
;
case OpOr32:
// match: (Or32 x x)
// cond:
// result: x
{
x := v.Args[0]
if v.Args[1] != x {
goto end231e283e568e90bd9a3e6a4fa328c8a4
}
v.Op = OpCopy
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.Type = x.Type
v.AddArg(x)
return true
}
goto end231e283e568e90bd9a3e6a4fa328c8a4
end231e283e568e90bd9a3e6a4fa328c8a4:
;
case OpOr64:
// match: (Or64 x x)
// cond:
// result: x
{
x := v.Args[0]
if v.Args[1] != x {
goto end6b0efc212016dc97d0e3939db04c81d9
}
v.Op = OpCopy
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.Type = x.Type
v.AddArg(x)
return true
}
goto end6b0efc212016dc97d0e3939db04c81d9
end6b0efc212016dc97d0e3939db04c81d9:
;
case OpOr8:
// match: (Or8 x x)
// cond:
// result: x
{
x := v.Args[0]
if v.Args[1] != x {
goto end05295dbfafd6869af79b4daee9fda000
}
v.Op = OpCopy
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.Type = x.Type
v.AddArg(x)
return true
}
goto end05295dbfafd6869af79b4daee9fda000
end05295dbfafd6869af79b4daee9fda000:
;
case OpPtrIndex:
// match: (PtrIndex <t> ptr idx)
// cond:
@ -848,6 +1008,158 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
}
goto end16fdb45e1dd08feb36e3cc3fb5ed8935
end16fdb45e1dd08feb36e3cc3fb5ed8935:
;
case OpSub16:
// match: (Sub16 x x)
// cond:
// result: (Const16 [0])
{
x := v.Args[0]
if v.Args[1] != x {
goto end83da541391be564f2a08464e674a49e7
}
v.Op = OpConst16
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = 0
return true
}
goto end83da541391be564f2a08464e674a49e7
end83da541391be564f2a08464e674a49e7:
;
case OpSub32:
// match: (Sub32 x x)
// cond:
// result: (Const32 [0])
{
x := v.Args[0]
if v.Args[1] != x {
goto enda747581e798f199e07f4ad69747cd069
}
v.Op = OpConst32
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = 0
return true
}
goto enda747581e798f199e07f4ad69747cd069
enda747581e798f199e07f4ad69747cd069:
;
case OpSub64:
// match: (Sub64 x x)
// cond:
// result: (Const64 [0])
{
x := v.Args[0]
if v.Args[1] != x {
goto end0387dc2b7bbe57d4aa54eab5d959da4b
}
v.Op = OpConst64
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = 0
return true
}
goto end0387dc2b7bbe57d4aa54eab5d959da4b
end0387dc2b7bbe57d4aa54eab5d959da4b:
;
case OpSub8:
// match: (Sub8 x x)
// cond:
// result: (Const8 [0])
{
x := v.Args[0]
if v.Args[1] != x {
goto end4e2ee15ef17611919a1a6b5f80bbfe18
}
v.Op = OpConst8
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = 0
return true
}
goto end4e2ee15ef17611919a1a6b5f80bbfe18
end4e2ee15ef17611919a1a6b5f80bbfe18:
;
case OpXor16:
// match: (Xor16 x x)
// cond:
// result: (Const16 [0])
{
x := v.Args[0]
if v.Args[1] != x {
goto end5733ceb1903b8140248d8e2cac02fefe
}
v.Op = OpConst16
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = 0
return true
}
goto end5733ceb1903b8140248d8e2cac02fefe
end5733ceb1903b8140248d8e2cac02fefe:
;
case OpXor32:
// match: (Xor32 x x)
// cond:
// result: (Const32 [0])
{
x := v.Args[0]
if v.Args[1] != x {
goto end268ca02df6515d648e0bfb4e90981d25
}
v.Op = OpConst32
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = 0
return true
}
goto end268ca02df6515d648e0bfb4e90981d25
end268ca02df6515d648e0bfb4e90981d25:
;
case OpXor64:
// match: (Xor64 x x)
// cond:
// result: (Const64 [0])
{
x := v.Args[0]
if v.Args[1] != x {
goto endaf44e7f9fc58af30df69070953fb45ce
}
v.Op = OpConst64
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = 0
return true
}
goto endaf44e7f9fc58af30df69070953fb45ce
endaf44e7f9fc58af30df69070953fb45ce:
;
case OpXor8:
// match: (Xor8 x x)
// cond:
// result: (Const8 [0])
{
x := v.Args[0]
if v.Args[1] != x {
goto end949b3a60b7d181688e6f79f93c782fc8
}
v.Op = OpConst8
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = 0
return true
}
goto end949b3a60b7d181688e6f79f93c782fc8
end949b3a60b7d181688e6f79f93c782fc8:
}
return false
}