cmd/compile: make isConstDelta compute delta for 8 and 16 bit arithmetic

Use the delta for computing min and max values. This elides a few bounds checks:

compilecmp linux/amd64:

regexp/syntax
regexp/syntax.Op.String 271 -> 249  (-8.12%)

compress/bzip2
compress/bzip2.(*reader).readBlock 2991 -> 2973  (-0.60%)

cmd/internal/objabi
cmd/internal/objabi.RelocType.String 240 -> 220  (-8.33%)

cmd/vendor/golang.org/x/arch/ppc64/ppc64asm
cmd/vendor/golang.org/x/arch/ppc64/ppc64asm.CondReg.String 421 -> 400  (-4.99%)
cmd/vendor/golang.org/x/arch/ppc64/ppc64asm.gnuArg changed
cmd/vendor/golang.org/x/arch/ppc64/ppc64asm.plan9Arg 1868 -> 1836  (-1.71%)

cmd/internal/objfile
cmd/internal/objfile.(*machoFile).symbols 1457 -> 1423  (-2.33%)
cmd/internal/objfile.loadPETable changed

cmd/internal/obj/wasm
cmd/internal/obj/wasm.assemble changed

cmd/internal/obj/ppc64
cmd/internal/obj/ppc64.type_vsrdbi changed
cmd/internal/obj/ppc64.type_vmsumcud changed

cmd/link/internal/loadpe
cmd/link/internal/loadpe.Load 10634 -> 10602  (-0.30%)
cmd/link/internal/loadpe.(*peLoaderState).readpesym changed

Change-Id: I439facd13e3d2695abadfe1d3f7faebfd0d7df74
Reviewed-on: https://go-review.googlesource.com/c/go/+/431237
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Jakub Ciolek 2022-09-16 12:16:00 +02:00 committed by Gopher Robot
parent 2d89bec2de
commit 2addbf3f2a

View file

@ -516,6 +516,20 @@ func (ft *factsTable) update(parent *Block, v, w *Value, d domain, r relation) {
vmin = parent.NewValue0I(parent.Pos, OpConst32, parent.Func.Config.Types.Int32, min)
vmax = parent.NewValue0I(parent.Pos, OpConst32, parent.Func.Config.Types.Int32, max)
case 2:
min = int64(int16(w.AuxInt) - int16(delta))
max = int64(int16(^uint16(0)>>1) - int16(delta))
vmin = parent.NewValue0I(parent.Pos, OpConst16, parent.Func.Config.Types.Int16, min)
vmax = parent.NewValue0I(parent.Pos, OpConst16, parent.Func.Config.Types.Int16, max)
case 1:
min = int64(int8(w.AuxInt) - int8(delta))
max = int64(int8(^uint8(0)>>1) - int8(delta))
vmin = parent.NewValue0I(parent.Pos, OpConst8, parent.Func.Config.Types.Int8, min)
vmax = parent.NewValue0I(parent.Pos, OpConst8, parent.Func.Config.Types.Int8, max)
default:
panic("unimplemented")
}
@ -1520,16 +1534,20 @@ func isConstDelta(v *Value) (w *Value, delta int64) {
switch v.Op {
case OpAdd32, OpSub32:
cop = OpConst32
case OpAdd16, OpSub16:
cop = OpConst16
case OpAdd8, OpSub8:
cop = OpConst8
}
switch v.Op {
case OpAdd64, OpAdd32:
case OpAdd64, OpAdd32, OpAdd16, OpAdd8:
if v.Args[0].Op == cop {
return v.Args[1], v.Args[0].AuxInt
}
if v.Args[1].Op == cop {
return v.Args[0], v.Args[1].AuxInt
}
case OpSub64, OpSub32:
case OpSub64, OpSub32, OpSub16, OpSub8:
if v.Args[1].Op == cop {
aux := v.Args[1].AuxInt
if aux != -aux { // Overflow; too bad