Skip to content

Commit f6c6781

Browse files
ALTreebradfitz
authored andcommitted
cmd/compile: use | in the last repetitive generic rules
This change or-ifies the last low-hanging rules in generic. Again, this is limited at short and repetitive rules, where the use or ors does not impact readability. Ran rulegen, no change in the actual compiler code. Change-Id: I972b523bc08532f173a3645b47d6936b6e1218c8 Reviewed-on: https://go-review.googlesource.com/96335 Reviewed-by: Giovanni Bajo <rasky@develer.com>
1 parent 5b3cd56 commit f6c6781

File tree

1 file changed

+20
-42
lines changed

1 file changed

+20
-42
lines changed

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

+20-42
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,10 @@
153153
(Not (ConstBool [c])) -> (ConstBool [1-c])
154154

155155
// Convert x * 1 to x.
156-
(Mul8 (Const8 [1]) x) -> x
157-
(Mul16 (Const16 [1]) x) -> x
158-
(Mul32 (Const32 [1]) x) -> x
159-
(Mul64 (Const64 [1]) x) -> x
156+
(Mul(8|16|32|64) (Const(8|16|32|64) [1]) x) -> x
160157

161158
// Convert x * -1 to -x.
162-
(Mul8 (Const8 [-1]) x) -> (Neg8 x)
163-
(Mul16 (Const16 [-1]) x) -> (Neg16 x)
164-
(Mul32 (Const32 [-1]) x) -> (Neg32 x)
165-
(Mul64 (Const64 [-1]) x) -> (Neg64 x)
159+
(Mul(8|16|32|64) (Const(8|16|32|64) [-1]) x) -> (Neg(8|16|32|64) x)
166160

167161
// Convert multiplication by a power of two to a shift.
168162
(Mul8 <t> n (Const8 [c])) && isPowerOfTwo(c) -> (Lsh8x64 <t> n (Const64 <typ.UInt64> [log2(c)]))
@@ -457,39 +451,24 @@
457451
// simplifications
458452
(Or(64|32|16|8) x x) -> x
459453
(Or(64|32|16|8) (Const(64|32|16|8) [0]) x) -> x
460-
(Or64 (Const64 [-1]) _) -> (Const64 [-1])
461-
(Or32 (Const32 [-1]) _) -> (Const32 [-1])
462-
(Or16 (Const16 [-1]) _) -> (Const16 [-1])
463-
(Or8 (Const8 [-1]) _) -> (Const8 [-1])
454+
(Or(64|32|16|8) (Const(64|32|16|8) [-1]) _) -> (Const(64|32|16|8) [-1])
455+
464456
(And(64|32|16|8) x x) -> x
465457
(And(64|32|16|8) (Const(64|32|16|8) [-1]) x) -> x
466-
(And64 (Const64 [0]) _) -> (Const64 [0])
467-
(And32 (Const32 [0]) _) -> (Const32 [0])
468-
(And16 (Const16 [0]) _) -> (Const16 [0])
469-
(And8 (Const8 [0]) _) -> (Const8 [0])
470-
(Xor64 x x) -> (Const64 [0])
471-
(Xor32 x x) -> (Const32 [0])
472-
(Xor16 x x) -> (Const16 [0])
473-
(Xor8 x x) -> (Const8 [0])
458+
(And(64|32|16|8) (Const(64|32|16|8) [0]) _) -> (Const(64|32|16|8) [0])
459+
460+
(Xor(64|32|16|8) x x) -> (Const(64|32|16|8) [0])
474461
(Xor(64|32|16|8) (Const(64|32|16|8) [0]) x) -> x
462+
475463
(Add(64|32|16|8) (Const(64|32|16|8) [0]) x) -> x
476-
(Sub64 x x) -> (Const64 [0])
477-
(Sub32 x x) -> (Const32 [0])
478-
(Sub16 x x) -> (Const16 [0])
479-
(Sub8 x x) -> (Const8 [0])
480-
(Mul64 (Const64 [0]) _) -> (Const64 [0])
481-
(Mul32 (Const32 [0]) _) -> (Const32 [0])
482-
(Mul16 (Const16 [0]) _) -> (Const16 [0])
483-
(Mul8 (Const8 [0]) _) -> (Const8 [0])
464+
(Sub(64|32|16|8) x x) -> (Const(64|32|16|8) [0])
465+
(Mul(64|32|16|8) (Const(64|32|16|8) [0]) _) -> (Const(64|32|16|8) [0])
466+
484467
(Com(64|32|16|8) (Com(64|32|16|8) x)) -> x
485-
(Com8 (Const8 [c])) -> (Const8 [^c])
486-
(Com16 (Const16 [c])) -> (Const16 [^c])
487-
(Com32 (Const32 [c])) -> (Const32 [^c])
488-
(Com64 (Const64 [c])) -> (Const64 [^c])
489-
(Neg8 (Sub8 x y)) -> (Sub8 y x)
490-
(Neg16 (Sub16 x y)) -> (Sub16 y x)
491-
(Neg32 (Sub32 x y)) -> (Sub32 y x)
492-
(Neg64 (Sub64 x y)) -> (Sub64 y x)
468+
(Com(64|32|16|8) (Const(64|32|16|8) [c])) -> (Const(64|32|16|8) [^c])
469+
470+
(Neg(64|32|16|8) (Sub(64|32|16|8) x y)) -> (Sub(64|32|16|8) y x)
471+
493472
(Add8 (Const8 [1]) (Com8 x)) -> (Neg8 x)
494473
(Add16 (Const16 [1]) (Com16 x)) -> (Neg16 x)
495474
(Add32 (Const32 [1]) (Com32 x)) -> (Neg32 x)
@@ -1229,16 +1208,15 @@
12291208
(Mul8 (Const8 <t> [c]) (Mul8 (Const8 <t> [d]) x)) -> (Mul8 (Const8 <t> [int64(int8(c*d))]) x)
12301209

12311210
// floating point optimizations
1232-
(Add32F x (Const32F [0])) -> x
1233-
(Add64F x (Const64F [0])) -> x
1234-
(Sub32F x (Const32F [0])) -> x
1235-
(Sub64F x (Const64F [0])) -> x
1236-
(Mul32F x (Const32F [f2i(1)])) -> x
1237-
(Mul64F x (Const64F [f2i(1)])) -> x
1211+
(Add(32|64)F x (Const(32|64)F [0])) -> x
1212+
(Sub(32|64)F x (Const(32|64)F [0])) -> x
1213+
1214+
(Mul(32|64)F x (Const(32|64)F [f2i(1)])) -> x
12381215
(Mul32F x (Const32F [f2i(-1)])) -> (Neg32F x)
12391216
(Mul64F x (Const64F [f2i(-1)])) -> (Neg64F x)
12401217
(Mul32F x (Const32F [f2i(2)])) -> (Add32F x x)
12411218
(Mul64F x (Const64F [f2i(2)])) -> (Add64F x x)
1219+
12421220
(Div32F x (Const32F <t> [c])) && reciprocalExact32(float32(i2f(c))) -> (Mul32F x (Const32F <t> [f2i(1/i2f(c))]))
12431221
(Div64F x (Const64F <t> [c])) && reciprocalExact64(i2f(c)) -> (Mul64F x (Const64F <t> [f2i(1/i2f(c))]))
12441222

0 commit comments

Comments
 (0)