This is a continuation to #30810, once the rewrite has been merged. A number of ideas will be proposed below. The purpose of this is to:
- Produce less lines of code, reducing the size of diffs and files on disk
- Produce simpler code, making it more readable to humans
- Hopefully reduce compile time of the generated code slightly
Here are my ideas so far:
-
Simplifying of boolean expressions. For example, turn !(d == 32-c) into d != 32-c.
-
Joining of contiguous break conditions, such as:
// verbose
if v_0.Op != OpAMD64SHLLconst {
break
}
if v_0.AuxInt != 3 {
break
}
// simpler
if v_0.Op != OpAMD64SHLLconst || v_0.AuxInt != 3 {
break
}
- Removing of uninteresting lines, such as the
cond line here:
// match: (ADDL x (SHLLconst [3] y))
// cond:
// result: (LEAL8 x y)
- Move declarations closer to their uses, reducing the number of variables in scope in some cases, such as:
for {
carry := v.Args[2]
x := v.Args[0] // Not actually used until the very end!
v_1 := v.Args[1]
if v_1.Op != OpAMD64MOVQconst {
break
}
c := v_1.AuxInt
if !(is32Bit(c)) {
break
}
v.reset(OpAMD64ADCQconst)
v.AuxInt = c
v.AddArg(x)
v.AddArg(carry)
return true
}
- Reorder slice accesses to reduce the amount of manual bounds checks speed-ups:
// verbose
_ = v.Args[1]
x := v.Args[0]
v_1 := v.Args[1]
// simpler
v_1 := v.Args[1]
x := v.Args[0]
These are the ideas I have so far. If we think any of them would reduce readability, they can be dropped. I'm also open to more ideas and suggestions, of course. I'd send these as separate CLs so we can measure their impact on the generated code separately.
/cc @josharian @randall77 @laboger @mundaym @cherrymui
This is a continuation to #30810, once the rewrite has been merged. A number of ideas will be proposed below. The purpose of this is to:
Here are my ideas so far:
Simplifying of boolean expressions. For example, turn
!(d == 32-c)intod != 32-c.Joining of contiguous break conditions, such as:
condline here:These are the ideas I have so far. If we think any of them would reduce readability, they can be dropped. I'm also open to more ideas and suggestions, of course. I'd send these as separate CLs so we can measure their impact on the generated code separately.
/cc @josharian @randall77 @laboger @mundaym @cherrymui