1
0
mirror of https://github.com/golang/go synced 2024-11-17 08:04:46 -07:00

cmd/compile: optimise x ^ ^x

This commit is contained in:
Jorropo 2022-04-18 19:44:25 +02:00
parent 4e3ac1190c
commit ce35ff2efd
2 changed files with 69 additions and 0 deletions

View File

@ -526,6 +526,7 @@
(Xor(64|32|16|8) x x) => (Const(64|32|16|8) [0]) (Xor(64|32|16|8) x x) => (Const(64|32|16|8) [0])
(Xor(64|32|16|8) (Const(64|32|16|8) [0]) x) => x (Xor(64|32|16|8) (Const(64|32|16|8) [0]) x) => x
(Xor(64|32|16|8) (Com(64|32|16|8) x) x) => (Const(64|32|16|8) [-1])
(Add(64|32|16|8) (Const(64|32|16|8) [0]) x) => x (Add(64|32|16|8) (Const(64|32|16|8) [0]) x) => x
(Sub(64|32|16|8) x x) => (Const(64|32|16|8) [0]) (Sub(64|32|16|8) x x) => (Const(64|32|16|8) [0])

View File

@ -25090,6 +25090,23 @@ func rewriteValuegeneric_OpXor16(v *Value) bool {
} }
break break
} }
// match: (Xor16 (Com16 x) x)
// result: (Const16 [-1])
for {
for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 {
if v_0.Op != OpCom16 {
continue
}
x := v_0.Args[0]
if x != v_1 {
continue
}
v.reset(OpConst16)
v.AuxInt = int16ToAuxInt(-1)
return true
}
break
}
// match: (Xor16 (Const16 [-1]) x) // match: (Xor16 (Const16 [-1]) x)
// result: (Com16 x) // result: (Com16 x)
for { for {
@ -25235,6 +25252,23 @@ func rewriteValuegeneric_OpXor32(v *Value) bool {
} }
break break
} }
// match: (Xor32 (Com32 x) x)
// result: (Const32 [-1])
for {
for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 {
if v_0.Op != OpCom32 {
continue
}
x := v_0.Args[0]
if x != v_1 {
continue
}
v.reset(OpConst32)
v.AuxInt = int32ToAuxInt(-1)
return true
}
break
}
// match: (Xor32 (Const32 [-1]) x) // match: (Xor32 (Const32 [-1]) x)
// result: (Com32 x) // result: (Com32 x)
for { for {
@ -25380,6 +25414,23 @@ func rewriteValuegeneric_OpXor64(v *Value) bool {
} }
break break
} }
// match: (Xor64 (Com64 x) x)
// result: (Const64 [-1])
for {
for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 {
if v_0.Op != OpCom64 {
continue
}
x := v_0.Args[0]
if x != v_1 {
continue
}
v.reset(OpConst64)
v.AuxInt = int64ToAuxInt(-1)
return true
}
break
}
// match: (Xor64 (Const64 [-1]) x) // match: (Xor64 (Const64 [-1]) x)
// result: (Com64 x) // result: (Com64 x)
for { for {
@ -25525,6 +25576,23 @@ func rewriteValuegeneric_OpXor8(v *Value) bool {
} }
break break
} }
// match: (Xor8 (Com8 x) x)
// result: (Const8 [-1])
for {
for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 {
if v_0.Op != OpCom8 {
continue
}
x := v_0.Args[0]
if x != v_1 {
continue
}
v.reset(OpConst8)
v.AuxInt = int8ToAuxInt(-1)
return true
}
break
}
// match: (Xor8 (Const8 [-1]) x) // match: (Xor8 (Const8 [-1]) x)
// result: (Com8 x) // result: (Com8 x)
for { for {