Skip to content

Commit 2addbf3

Browse files
jake-ciolekgopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Than McIntosh <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 2d89bec commit 2addbf3

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,20 @@ func (ft *factsTable) update(parent *Block, v, w *Value, d domain, r relation) {
516516
vmin = parent.NewValue0I(parent.Pos, OpConst32, parent.Func.Config.Types.Int32, min)
517517
vmax = parent.NewValue0I(parent.Pos, OpConst32, parent.Func.Config.Types.Int32, max)
518518

519+
case 2:
520+
min = int64(int16(w.AuxInt) - int16(delta))
521+
max = int64(int16(^uint16(0)>>1) - int16(delta))
522+
523+
vmin = parent.NewValue0I(parent.Pos, OpConst16, parent.Func.Config.Types.Int16, min)
524+
vmax = parent.NewValue0I(parent.Pos, OpConst16, parent.Func.Config.Types.Int16, max)
525+
526+
case 1:
527+
min = int64(int8(w.AuxInt) - int8(delta))
528+
max = int64(int8(^uint8(0)>>1) - int8(delta))
529+
530+
vmin = parent.NewValue0I(parent.Pos, OpConst8, parent.Func.Config.Types.Int8, min)
531+
vmax = parent.NewValue0I(parent.Pos, OpConst8, parent.Func.Config.Types.Int8, max)
532+
519533
default:
520534
panic("unimplemented")
521535
}
@@ -1520,16 +1534,20 @@ func isConstDelta(v *Value) (w *Value, delta int64) {
15201534
switch v.Op {
15211535
case OpAdd32, OpSub32:
15221536
cop = OpConst32
1537+
case OpAdd16, OpSub16:
1538+
cop = OpConst16
1539+
case OpAdd8, OpSub8:
1540+
cop = OpConst8
15231541
}
15241542
switch v.Op {
1525-
case OpAdd64, OpAdd32:
1543+
case OpAdd64, OpAdd32, OpAdd16, OpAdd8:
15261544
if v.Args[0].Op == cop {
15271545
return v.Args[1], v.Args[0].AuxInt
15281546
}
15291547
if v.Args[1].Op == cop {
15301548
return v.Args[0], v.Args[1].AuxInt
15311549
}
1532-
case OpSub64, OpSub32:
1550+
case OpSub64, OpSub32, OpSub16, OpSub8:
15331551
if v.Args[1].Op == cop {
15341552
aux := v.Args[1].AuxInt
15351553
if aux != -aux { // Overflow; too bad

0 commit comments

Comments
 (0)