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

[dev.ssa] cmd/compile: simplify repeated OCOM

Rewrite ^{n}x to be ^{n % 2}x.  This will eventually resolve a fuzz
issue that breaks v1.5.

Updates #11352

Change-Id: I1b3f93872d06222f9ff5f6fd5580178ebaf4c003
Reviewed-on: https://go-review.googlesource.com/13110
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Todd Neal 2015-07-30 16:02:24 -04:00
parent faee392814
commit 38ed6c10eb
3 changed files with 97 additions and 0 deletions

View File

@ -156,6 +156,21 @@ func testSubqToNegq_ssa(a, b, c, d, e, f, g, h, i, j, k int64) int64 {
return a + 8207351403619448057 - b - 1779494519303207690 + c*8810076340510052032*d - 4465874067674546219 - e*4361839741470334295 - f + 8688847565426072650*g*8065564729145417479
}
func testOcom() {
want1, want2 := int32(0x55555555), int32(-0x55555556)
if got1, got2 := testOcom_ssa(0x55555555, 0x55555555); want1 != got1 || want2 != got2 {
println("testSubqToNegq failed, wanted", want1, "and", want2,
"got", got1, "and", got2)
failed = true
}
}
func testOcom_ssa(a, b int32) (int32, int32) {
switch { // prevent inlining
}
return ^^^^a, ^^^^^b
}
var failed = false
func main() {
@ -165,6 +180,7 @@ func main() {
testRegallocCVSpill()
testSubqToNegq()
testBitwiseLogic()
testOcom()
if failed {
panic("failed")

View File

@ -34,6 +34,11 @@
(Neq16 x x) -> (ConstBool {false})
(Neq8 x x) -> (ConstBool {false})
(Com8 (Com8 x)) -> (Copy x)
(Com16 (Com16 x)) -> (Copy x)
(Com32 (Com32 x)) -> (Copy x)
(Com64 (Com64 x)) -> (Copy x)
// tear apart slices
// TODO: anything that generates a slice needs to go in here.
(SlicePtr (Load ptr mem)) -> (Load ptr mem)

View File

@ -76,6 +76,82 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
goto end4894dd7b58383fee5f8a92be08437c33
end4894dd7b58383fee5f8a92be08437c33:
;
case OpCom16:
// match: (Com16 (Com16 x))
// cond:
// result: (Copy x)
{
if v.Args[0].Op != OpCom16 {
goto end388d572e5a72fd87a07da5cab243ebdc
}
x := v.Args[0].Args[0]
v.Op = OpCopy
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AddArg(x)
return true
}
goto end388d572e5a72fd87a07da5cab243ebdc
end388d572e5a72fd87a07da5cab243ebdc:
;
case OpCom32:
// match: (Com32 (Com32 x))
// cond:
// result: (Copy x)
{
if v.Args[0].Op != OpCom32 {
goto end5b2b3834acc7313649923604f685e7c5
}
x := v.Args[0].Args[0]
v.Op = OpCopy
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AddArg(x)
return true
}
goto end5b2b3834acc7313649923604f685e7c5
end5b2b3834acc7313649923604f685e7c5:
;
case OpCom64:
// match: (Com64 (Com64 x))
// cond:
// result: (Copy x)
{
if v.Args[0].Op != OpCom64 {
goto end6d6312f25d06a327d92f028b1ce50566
}
x := v.Args[0].Args[0]
v.Op = OpCopy
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AddArg(x)
return true
}
goto end6d6312f25d06a327d92f028b1ce50566
end6d6312f25d06a327d92f028b1ce50566:
;
case OpCom8:
// match: (Com8 (Com8 x))
// cond:
// result: (Copy x)
{
if v.Args[0].Op != OpCom8 {
goto end70cbd85c4b8e82c170dba7c23f8bc0f3
}
x := v.Args[0].Args[0]
v.Op = OpCopy
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AddArg(x)
return true
}
goto end70cbd85c4b8e82c170dba7c23f8bc0f3
end70cbd85c4b8e82c170dba7c23f8bc0f3:
;
case OpConstString:
// match: (ConstString {s})
// cond: