Skip to content

Commit c1892b9

Browse files
Alexandru Moșoibrtzsnr
Alexandru Moșoi
authored andcommitted
cmd/compile: don't simplify nilchecks in loops
khr: Lifting the nil check out of the loop altogether is an admirable goal, and this rewrite is one step on the way. But without lifting it out of the loop, the rewrite is just hurting us. Fixes #14917 Change-Id: Idb917f37d89f50f8e046d5ebd7c092b1e0eb0633 Reviewed-on: https://go-review.googlesource.com/21040 Reviewed-by: Keith Randall <[email protected]> Run-TryBot: Alexandru Moșoi <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent baec148 commit c1892b9

File tree

2 files changed

+0
-42
lines changed

2 files changed

+0
-42
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
// succ* fields must be variables
2020
// For now, the generated successors must be a permutation of the matched successors.
2121

22-
// Simplify nil checks.
23-
// These are inserted by for _, e := range a {}
24-
(NilCheck z:(Phi x (Add64 (Const64 [c]) y)) mem) && c > 0 && z == y -> (NilCheck x mem)
25-
2622
// constant folding
2723
(Trunc16to8 (Const16 [c])) -> (Const8 [int64(int8(c))])
2824
(Trunc32to8 (Const32 [c])) -> (Const8 [int64(int8(c))])

src/cmd/compile/internal/ssa/rewritegeneric.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
220220
return rewriteValuegeneric_OpNeqPtr(v, config)
221221
case OpNeqSlice:
222222
return rewriteValuegeneric_OpNeqSlice(v, config)
223-
case OpNilCheck:
224-
return rewriteValuegeneric_OpNilCheck(v, config)
225223
case OpOffPtr:
226224
return rewriteValuegeneric_OpOffPtr(v, config)
227225
case OpOr16:
@@ -5604,42 +5602,6 @@ func rewriteValuegeneric_OpNeqSlice(v *Value, config *Config) bool {
56045602
}
56055603
return false
56065604
}
5607-
func rewriteValuegeneric_OpNilCheck(v *Value, config *Config) bool {
5608-
b := v.Block
5609-
_ = b
5610-
// match: (NilCheck z:(Phi x (Add64 (Const64 [c]) y)) mem)
5611-
// cond: c > 0 && z == y
5612-
// result: (NilCheck x mem)
5613-
for {
5614-
z := v.Args[0]
5615-
if z.Op != OpPhi {
5616-
break
5617-
}
5618-
x := z.Args[0]
5619-
z_1 := z.Args[1]
5620-
if z_1.Op != OpAdd64 {
5621-
break
5622-
}
5623-
z_1_0 := z_1.Args[0]
5624-
if z_1_0.Op != OpConst64 {
5625-
break
5626-
}
5627-
c := z_1_0.AuxInt
5628-
y := z_1.Args[1]
5629-
if len(z.Args) != 2 {
5630-
break
5631-
}
5632-
mem := v.Args[1]
5633-
if !(c > 0 && z == y) {
5634-
break
5635-
}
5636-
v.reset(OpNilCheck)
5637-
v.AddArg(x)
5638-
v.AddArg(mem)
5639-
return true
5640-
}
5641-
return false
5642-
}
56435605
func rewriteValuegeneric_OpOffPtr(v *Value, config *Config) bool {
56445606
b := v.Block
56455607
_ = b

0 commit comments

Comments
 (0)