mirror of
https://github.com/golang/go
synced 2024-10-14 03:43:28 +00:00
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:
parent
2d89bec2de
commit
2addbf3f2a
|
@ -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)
|
vmin = parent.NewValue0I(parent.Pos, OpConst32, parent.Func.Config.Types.Int32, min)
|
||||||
vmax = parent.NewValue0I(parent.Pos, OpConst32, parent.Func.Config.Types.Int32, max)
|
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:
|
default:
|
||||||
panic("unimplemented")
|
panic("unimplemented")
|
||||||
}
|
}
|
||||||
|
@ -1520,16 +1534,20 @@ func isConstDelta(v *Value) (w *Value, delta int64) {
|
||||||
switch v.Op {
|
switch v.Op {
|
||||||
case OpAdd32, OpSub32:
|
case OpAdd32, OpSub32:
|
||||||
cop = OpConst32
|
cop = OpConst32
|
||||||
|
case OpAdd16, OpSub16:
|
||||||
|
cop = OpConst16
|
||||||
|
case OpAdd8, OpSub8:
|
||||||
|
cop = OpConst8
|
||||||
}
|
}
|
||||||
switch v.Op {
|
switch v.Op {
|
||||||
case OpAdd64, OpAdd32:
|
case OpAdd64, OpAdd32, OpAdd16, OpAdd8:
|
||||||
if v.Args[0].Op == cop {
|
if v.Args[0].Op == cop {
|
||||||
return v.Args[1], v.Args[0].AuxInt
|
return v.Args[1], v.Args[0].AuxInt
|
||||||
}
|
}
|
||||||
if v.Args[1].Op == cop {
|
if v.Args[1].Op == cop {
|
||||||
return v.Args[0], v.Args[1].AuxInt
|
return v.Args[0], v.Args[1].AuxInt
|
||||||
}
|
}
|
||||||
case OpSub64, OpSub32:
|
case OpSub64, OpSub32, OpSub16, OpSub8:
|
||||||
if v.Args[1].Op == cop {
|
if v.Args[1].Op == cop {
|
||||||
aux := v.Args[1].AuxInt
|
aux := v.Args[1].AuxInt
|
||||||
if aux != -aux { // Overflow; too bad
|
if aux != -aux { // Overflow; too bad
|
||||||
|
|
Loading…
Reference in a new issue