Commit 5548f7d5 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: eliminate some bounds checks from generated rewrite rules

Noticed while looking at #20356.

Cuts 160k (1%) off of the cmd/compile binary.

Change-Id: If2397bc6971d6be9be6975048adecb0b5efa6d66
Reviewed-on: https://go-review.googlesource.com/43501
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarKeith Randall <khr@golang.org>
parent 4b0d74f8
...@@ -442,6 +442,9 @@ func genMatch0(w io.Writer, arch arch, match, v string, m map[string]struct{}, t ...@@ -442,6 +442,9 @@ func genMatch0(w io.Writer, arch arch, match, v string, m map[string]struct{}, t
} }
} }
if n := len(args); n > 1 {
fmt.Fprintf(w, "_ = %s.Args[%d]\n", v, n-1) // combine some bounds checks
}
for i, arg := range args { for i, arg := range args {
if arg == "_" { if arg == "_" {
continue continue
......
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
...@@ -49,6 +49,7 @@ func rewriteValuedec_OpComplexImag_0(v *Value) bool { ...@@ -49,6 +49,7 @@ func rewriteValuedec_OpComplexImag_0(v *Value) bool {
if v_0.Op != OpComplexMake { if v_0.Op != OpComplexMake {
break break
} }
_ = v_0.Args[1]
imag := v_0.Args[1] imag := v_0.Args[1]
v.reset(OpCopy) v.reset(OpCopy)
v.Type = imag.Type v.Type = imag.Type
...@@ -66,6 +67,7 @@ func rewriteValuedec_OpComplexReal_0(v *Value) bool { ...@@ -66,6 +67,7 @@ func rewriteValuedec_OpComplexReal_0(v *Value) bool {
if v_0.Op != OpComplexMake { if v_0.Op != OpComplexMake {
break break
} }
_ = v_0.Args[1]
real := v_0.Args[0] real := v_0.Args[0]
v.reset(OpCopy) v.reset(OpCopy)
v.Type = real.Type v.Type = real.Type
...@@ -83,6 +85,7 @@ func rewriteValuedec_OpIData_0(v *Value) bool { ...@@ -83,6 +85,7 @@ func rewriteValuedec_OpIData_0(v *Value) bool {
if v_0.Op != OpIMake { if v_0.Op != OpIMake {
break break
} }
_ = v_0.Args[1]
data := v_0.Args[1] data := v_0.Args[1]
v.reset(OpCopy) v.reset(OpCopy)
v.Type = data.Type v.Type = data.Type
...@@ -102,6 +105,7 @@ func rewriteValuedec_OpITab_0(v *Value) bool { ...@@ -102,6 +105,7 @@ func rewriteValuedec_OpITab_0(v *Value) bool {
if v_0.Op != OpIMake { if v_0.Op != OpIMake {
break break
} }
_ = v_0.Args[1]
itab := v_0.Args[0] itab := v_0.Args[0]
v.reset(OpCopy) v.reset(OpCopy)
v.Type = itab.Type v.Type = itab.Type
...@@ -122,6 +126,7 @@ func rewriteValuedec_OpLoad_0(v *Value) bool { ...@@ -122,6 +126,7 @@ func rewriteValuedec_OpLoad_0(v *Value) bool {
// result: (ComplexMake (Load <typ.Float32> ptr mem) (Load <typ.Float32> (OffPtr <typ.Float32Ptr> [4] ptr) mem) ) // result: (ComplexMake (Load <typ.Float32> ptr mem) (Load <typ.Float32> (OffPtr <typ.Float32Ptr> [4] ptr) mem) )
for { for {
t := v.Type t := v.Type
_ = v.Args[1]
ptr := v.Args[0] ptr := v.Args[0]
mem := v.Args[1] mem := v.Args[1]
if !(t.IsComplex() && t.Size() == 8) { if !(t.IsComplex() && t.Size() == 8) {
...@@ -146,6 +151,7 @@ func rewriteValuedec_OpLoad_0(v *Value) bool { ...@@ -146,6 +151,7 @@ func rewriteValuedec_OpLoad_0(v *Value) bool {
// result: (ComplexMake (Load <typ.Float64> ptr mem) (Load <typ.Float64> (OffPtr <typ.Float64Ptr> [8] ptr) mem) ) // result: (ComplexMake (Load <typ.Float64> ptr mem) (Load <typ.Float64> (OffPtr <typ.Float64Ptr> [8] ptr) mem) )
for { for {
t := v.Type t := v.Type
_ = v.Args[1]
ptr := v.Args[0] ptr := v.Args[0]
mem := v.Args[1] mem := v.Args[1]
if !(t.IsComplex() && t.Size() == 16) { if !(t.IsComplex() && t.Size() == 16) {
...@@ -170,6 +176,7 @@ func rewriteValuedec_OpLoad_0(v *Value) bool { ...@@ -170,6 +176,7 @@ func rewriteValuedec_OpLoad_0(v *Value) bool {
// result: (StringMake (Load <typ.BytePtr> ptr mem) (Load <typ.Int> (OffPtr <typ.IntPtr> [config.PtrSize] ptr) mem)) // result: (StringMake (Load <typ.BytePtr> ptr mem) (Load <typ.Int> (OffPtr <typ.IntPtr> [config.PtrSize] ptr) mem))
for { for {
t := v.Type t := v.Type
_ = v.Args[1]
ptr := v.Args[0] ptr := v.Args[0]
mem := v.Args[1] mem := v.Args[1]
if !(t.IsString()) { if !(t.IsString()) {
...@@ -194,6 +201,7 @@ func rewriteValuedec_OpLoad_0(v *Value) bool { ...@@ -194,6 +201,7 @@ func rewriteValuedec_OpLoad_0(v *Value) bool {
// result: (SliceMake (Load <t.ElemType().PtrTo()> ptr mem) (Load <typ.Int> (OffPtr <typ.IntPtr> [config.PtrSize] ptr) mem) (Load <typ.Int> (OffPtr <typ.IntPtr> [2*config.PtrSize] ptr) mem)) // result: (SliceMake (Load <t.ElemType().PtrTo()> ptr mem) (Load <typ.Int> (OffPtr <typ.IntPtr> [config.PtrSize] ptr) mem) (Load <typ.Int> (OffPtr <typ.IntPtr> [2*config.PtrSize] ptr) mem))
for { for {
t := v.Type t := v.Type
_ = v.Args[1]
ptr := v.Args[0] ptr := v.Args[0]
mem := v.Args[1] mem := v.Args[1]
if !(t.IsSlice()) { if !(t.IsSlice()) {
...@@ -225,6 +233,7 @@ func rewriteValuedec_OpLoad_0(v *Value) bool { ...@@ -225,6 +233,7 @@ func rewriteValuedec_OpLoad_0(v *Value) bool {
// result: (IMake (Load <typ.BytePtr> ptr mem) (Load <typ.BytePtr> (OffPtr <typ.BytePtrPtr> [config.PtrSize] ptr) mem)) // result: (IMake (Load <typ.BytePtr> ptr mem) (Load <typ.BytePtr> (OffPtr <typ.BytePtrPtr> [config.PtrSize] ptr) mem))
for { for {
t := v.Type t := v.Type
_ = v.Args[1]
ptr := v.Args[0] ptr := v.Args[0]
mem := v.Args[1] mem := v.Args[1]
if !(t.IsInterface()) { if !(t.IsInterface()) {
...@@ -255,6 +264,7 @@ func rewriteValuedec_OpSliceCap_0(v *Value) bool { ...@@ -255,6 +264,7 @@ func rewriteValuedec_OpSliceCap_0(v *Value) bool {
if v_0.Op != OpSliceMake { if v_0.Op != OpSliceMake {
break break
} }
_ = v_0.Args[2]
cap := v_0.Args[2] cap := v_0.Args[2]
v.reset(OpCopy) v.reset(OpCopy)
v.Type = cap.Type v.Type = cap.Type
...@@ -272,6 +282,7 @@ func rewriteValuedec_OpSliceLen_0(v *Value) bool { ...@@ -272,6 +282,7 @@ func rewriteValuedec_OpSliceLen_0(v *Value) bool {
if v_0.Op != OpSliceMake { if v_0.Op != OpSliceMake {
break break
} }
_ = v_0.Args[2]
len := v_0.Args[1] len := v_0.Args[1]
v.reset(OpCopy) v.reset(OpCopy)
v.Type = len.Type v.Type = len.Type
...@@ -289,6 +300,7 @@ func rewriteValuedec_OpSlicePtr_0(v *Value) bool { ...@@ -289,6 +300,7 @@ func rewriteValuedec_OpSlicePtr_0(v *Value) bool {
if v_0.Op != OpSliceMake { if v_0.Op != OpSliceMake {
break break
} }
_ = v_0.Args[2]
ptr := v_0.Args[0] ptr := v_0.Args[0]
v.reset(OpCopy) v.reset(OpCopy)
v.Type = ptr.Type v.Type = ptr.Type
...@@ -309,11 +321,13 @@ func rewriteValuedec_OpStore_0(v *Value) bool { ...@@ -309,11 +321,13 @@ func rewriteValuedec_OpStore_0(v *Value) bool {
// result: (Store {typ.Float32} (OffPtr <typ.Float32Ptr> [4] dst) imag (Store {typ.Float32} dst real mem)) // result: (Store {typ.Float32} (OffPtr <typ.Float32Ptr> [4] dst) imag (Store {typ.Float32} dst real mem))
for { for {
t := v.Aux t := v.Aux
_ = v.Args[2]
dst := v.Args[0] dst := v.Args[0]
v_1 := v.Args[1] v_1 := v.Args[1]
if v_1.Op != OpComplexMake { if v_1.Op != OpComplexMake {
break break
} }
_ = v_1.Args[1]
real := v_1.Args[0] real := v_1.Args[0]
imag := v_1.Args[1] imag := v_1.Args[1]
mem := v.Args[2] mem := v.Args[2]
...@@ -340,11 +354,13 @@ func rewriteValuedec_OpStore_0(v *Value) bool { ...@@ -340,11 +354,13 @@ func rewriteValuedec_OpStore_0(v *Value) bool {
// result: (Store {typ.Float64} (OffPtr <typ.Float64Ptr> [8] dst) imag (Store {typ.Float64} dst real mem)) // result: (Store {typ.Float64} (OffPtr <typ.Float64Ptr> [8] dst) imag (Store {typ.Float64} dst real mem))
for { for {
t := v.Aux t := v.Aux
_ = v.Args[2]
dst := v.Args[0] dst := v.Args[0]
v_1 := v.Args[1] v_1 := v.Args[1]
if v_1.Op != OpComplexMake { if v_1.Op != OpComplexMake {
break break
} }
_ = v_1.Args[1]
real := v_1.Args[0] real := v_1.Args[0]
imag := v_1.Args[1] imag := v_1.Args[1]
mem := v.Args[2] mem := v.Args[2]
...@@ -370,11 +386,13 @@ func rewriteValuedec_OpStore_0(v *Value) bool { ...@@ -370,11 +386,13 @@ func rewriteValuedec_OpStore_0(v *Value) bool {
// cond: // cond:
// result: (Store {typ.Int} (OffPtr <typ.IntPtr> [config.PtrSize] dst) len (Store {typ.BytePtr} dst ptr mem)) // result: (Store {typ.Int} (OffPtr <typ.IntPtr> [config.PtrSize] dst) len (Store {typ.BytePtr} dst ptr mem))
for { for {
_ = v.Args[2]
dst := v.Args[0] dst := v.Args[0]
v_1 := v.Args[1] v_1 := v.Args[1]
if v_1.Op != OpStringMake { if v_1.Op != OpStringMake {
break break
} }
_ = v_1.Args[1]
ptr := v_1.Args[0] ptr := v_1.Args[0]
len := v_1.Args[1] len := v_1.Args[1]
mem := v.Args[2] mem := v.Args[2]
...@@ -397,11 +415,13 @@ func rewriteValuedec_OpStore_0(v *Value) bool { ...@@ -397,11 +415,13 @@ func rewriteValuedec_OpStore_0(v *Value) bool {
// cond: // cond:
// result: (Store {typ.Int} (OffPtr <typ.IntPtr> [2*config.PtrSize] dst) cap (Store {typ.Int} (OffPtr <typ.IntPtr> [config.PtrSize] dst) len (Store {typ.BytePtr} dst ptr mem))) // result: (Store {typ.Int} (OffPtr <typ.IntPtr> [2*config.PtrSize] dst) cap (Store {typ.Int} (OffPtr <typ.IntPtr> [config.PtrSize] dst) len (Store {typ.BytePtr} dst ptr mem)))
for { for {
_ = v.Args[2]
dst := v.Args[0] dst := v.Args[0]
v_1 := v.Args[1] v_1 := v.Args[1]
if v_1.Op != OpSliceMake { if v_1.Op != OpSliceMake {
break break
} }
_ = v_1.Args[2]
ptr := v_1.Args[0] ptr := v_1.Args[0]
len := v_1.Args[1] len := v_1.Args[1]
cap := v_1.Args[2] cap := v_1.Args[2]
...@@ -433,11 +453,13 @@ func rewriteValuedec_OpStore_0(v *Value) bool { ...@@ -433,11 +453,13 @@ func rewriteValuedec_OpStore_0(v *Value) bool {
// cond: // cond:
// result: (Store {typ.BytePtr} (OffPtr <typ.BytePtrPtr> [config.PtrSize] dst) data (Store {typ.Uintptr} dst itab mem)) // result: (Store {typ.BytePtr} (OffPtr <typ.BytePtrPtr> [config.PtrSize] dst) data (Store {typ.Uintptr} dst itab mem))
for { for {
_ = v.Args[2]
dst := v.Args[0] dst := v.Args[0]
v_1 := v.Args[1] v_1 := v.Args[1]
if v_1.Op != OpIMake { if v_1.Op != OpIMake {
break break
} }
_ = v_1.Args[1]
itab := v_1.Args[0] itab := v_1.Args[0]
data := v_1.Args[1] data := v_1.Args[1]
mem := v.Args[2] mem := v.Args[2]
...@@ -467,6 +489,7 @@ func rewriteValuedec_OpStringLen_0(v *Value) bool { ...@@ -467,6 +489,7 @@ func rewriteValuedec_OpStringLen_0(v *Value) bool {
if v_0.Op != OpStringMake { if v_0.Op != OpStringMake {
break break
} }
_ = v_0.Args[1]
len := v_0.Args[1] len := v_0.Args[1]
v.reset(OpCopy) v.reset(OpCopy)
v.Type = len.Type v.Type = len.Type
...@@ -484,6 +507,7 @@ func rewriteValuedec_OpStringPtr_0(v *Value) bool { ...@@ -484,6 +507,7 @@ func rewriteValuedec_OpStringPtr_0(v *Value) bool {
if v_0.Op != OpStringMake { if v_0.Op != OpStringMake {
break break
} }
_ = v_0.Args[1]
ptr := v_0.Args[0] ptr := v_0.Args[0]
v.reset(OpCopy) v.reset(OpCopy)
v.Type = ptr.Type v.Type = ptr.Type
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment