cmd: use built-in min/max instead of bespoke versions

Now that we're bootstrapping from a toolchain that has min/max builtins.

Update #64751

Change-Id: I63eedf3cca00f56f62ca092949cb2dc61db03361
Reviewed-on: https://go-review.googlesource.com/c/go/+/610355
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Keith Randall 2024-09-03 13:29:42 -07:00
parent 820f58a27f
commit f90f7e90b3
9 changed files with 18 additions and 100 deletions

View file

@ -819,13 +819,6 @@ func (t *node32) leftToRoot() *node32 {
return left
}
func max(a, b int8) int8 {
if a > b {
return a
}
return b
}
func (t *node32) copy() *node32 {
u := *t
return &u

View file

@ -703,10 +703,10 @@
(CMP(W|WU) (MOVDconst [c]) x) => (InvertFlags (CMP(W|WU)const x [int32(c)]))
// Match (x >> c) << d to 'rotate then insert selected bits [into zero]'.
(SLDconst (SRDconst x [c]) [d]) => (RISBGZ x {s390x.NewRotateParams(uint8(max8(0, int8(c-d))), 63-d, uint8(int8(d-c)&63))})
(SLDconst (SRDconst x [c]) [d]) => (RISBGZ x {s390x.NewRotateParams(uint8(max(0, int8(c-d))), 63-d, uint8(int8(d-c)&63))})
// Match (x << c) >> d to 'rotate then insert selected bits [into zero]'.
(SRDconst (SLDconst x [c]) [d]) => (RISBGZ x {s390x.NewRotateParams(d, uint8(min8(63, int8(63-c+d))), uint8(int8(c-d)&63))})
(SRDconst (SLDconst x [c]) [d]) => (RISBGZ x {s390x.NewRotateParams(d, uint8(min(63, int8(63-c+d))), uint8(int8(c-d)&63))})
// Absorb input zero extension into 'rotate then insert selected bits [into zero]'.
(RISBGZ (MOVWZreg x) {r}) && r.InMerge(0xffffffff) != nil => (RISBGZ x {*r.InMerge(0xffffffff)})

View file

@ -73,20 +73,6 @@ type loopnest struct {
initializedChildren, initializedDepth, initializedExits bool
}
func min8(a, b int8) int8 {
if a < b {
return a
}
return b
}
func max8(a, b int8) int8 {
if a > b {
return a
}
return b
}
const (
blDEFAULT = 0
blMin = blDEFAULT
@ -143,7 +129,7 @@ func likelyadjust(f *Func) {
// and less influential than inferences from loop structure.
case BlockDefer:
local[b.ID] = blCALL
certain[b.ID] = max8(blCALL, certain[b.Succs[0].b.ID])
certain[b.ID] = max(blCALL, certain[b.Succs[0].b.ID])
default:
if len(b.Succs) == 1 {
@ -157,7 +143,7 @@ func likelyadjust(f *Func) {
// tagged with call cost. Net effect is that loop entry is favored.
b0 := b.Succs[0].b.ID
b1 := b.Succs[1].b.ID
certain[b.ID] = min8(certain[b0], certain[b1])
certain[b.ID] = min(certain[b0], certain[b1])
l := b2l[b.ID]
l0 := b2l[b0]
@ -223,7 +209,7 @@ func likelyadjust(f *Func) {
for _, v := range b.Values {
if opcodeTable[v.Op].call {
local[b.ID] = blCALL
certain[b.ID] = max8(blCALL, certain[b.Succs[0].b.ID])
certain[b.ID] = max(blCALL, certain[b.Succs[0].b.ID])
break
}
}

View file

@ -1737,13 +1737,13 @@ func (ft *factsTable) flowLimit(v *Value) bool {
// AND can only make the value smaller.
a := ft.limits[v.Args[0].ID]
b := ft.limits[v.Args[1].ID]
return ft.unsignedMax(v, minU(a.umax, b.umax))
return ft.unsignedMax(v, min(a.umax, b.umax))
case OpOr64, OpOr32, OpOr16, OpOr8:
// OR can only make the value bigger and can't flip bits proved to be zero in both inputs.
a := ft.limits[v.Args[0].ID]
b := ft.limits[v.Args[1].ID]
return ft.unsignedMinMax(v,
maxU(a.umin, b.umin),
max(a.umin, b.umin),
1<<bits.Len64(a.umax|b.umax)-1)
case OpXor64, OpXor32, OpXor16, OpXor8:
// XOR can't flip bits that are proved to be zero in both inputs.
@ -1835,7 +1835,7 @@ func (ft *factsTable) flowLimit(v *Value) bool {
a := ft.limits[v.Args[0].ID]
b := ft.limits[v.Args[1].ID]
// Underflow in the arithmetic below is ok, it gives to MaxUint64 which does nothing to the limit.
return ft.unsignedMax(v, minU(a.umax, b.umax-1))
return ft.unsignedMax(v, min(a.umax, b.umax-1))
case OpDiv64, OpDiv32, OpDiv16, OpDiv8:
a := ft.limits[v.Args[0].ID]
b := ft.limits[v.Args[1].ID]
@ -1871,8 +1871,8 @@ func (ft *factsTable) flowLimit(v *Value) bool {
l2 := ft.limits[a.ID]
l.min = min(l.min, l2.min)
l.max = max(l.max, l2.max)
l.umin = minU(l.umin, l2.umin)
l.umax = maxU(l.umax, l2.umax)
l.umin = min(l.umin, l2.umin)
l.umax = max(l.umax, l2.umax)
}
return ft.newLimit(v, l)
}

View file

@ -511,8 +511,8 @@ func (s *regAllocState) makeSpill(v *Value, b *Block) *Value {
vi := &s.values[v.ID]
if vi.spill != nil {
// Final block not known - keep track of subtree where restores reside.
vi.restoreMin = min32(vi.restoreMin, s.sdom[b.ID].entry)
vi.restoreMax = max32(vi.restoreMax, s.sdom[b.ID].exit)
vi.restoreMin = min(vi.restoreMin, s.sdom[b.ID].entry)
vi.restoreMax = max(vi.restoreMax, s.sdom[b.ID].exit)
return vi.spill
}
// Make a spill for v. We don't know where we want
@ -2987,16 +2987,3 @@ func (d *desiredState) merge(x *desiredState) {
d.addList(e.ID, e.regs)
}
}
func min32(x, y int32) int32 {
if x < y {
return x
}
return y
}
func max32(x, y int32) int32 {
if x > y {
return x
}
return y
}

View file

@ -1188,33 +1188,6 @@ func logRule(s string) {
var ruleFile io.Writer
// TODO: replace these with the built-in min/max once they are available
// during bootstrap (when bootstrapping with 1.21 or later).
func min(x, y int64) int64 {
if x < y {
return x
}
return y
}
func max(x, y int64) int64 {
if x > y {
return x
}
return y
}
func minU(x, y uint64) uint64 {
if x < y {
return x
}
return y
}
func maxU(x, y uint64) uint64 {
if x > y {
return x
}
return y
}
func isConstZero(v *Value) bool {
switch v.Op {
case OpConstNil:

View file

@ -12118,7 +12118,7 @@ func rewriteValueS390X_OpS390XSLD(v *Value) bool {
func rewriteValueS390X_OpS390XSLDconst(v *Value) bool {
v_0 := v.Args[0]
// match: (SLDconst (SRDconst x [c]) [d])
// result: (RISBGZ x {s390x.NewRotateParams(uint8(max8(0, int8(c-d))), 63-d, uint8(int8(d-c)&63))})
// result: (RISBGZ x {s390x.NewRotateParams(uint8(max(0, int8(c-d))), 63-d, uint8(int8(d-c)&63))})
for {
d := auxIntToUint8(v.AuxInt)
if v_0.Op != OpS390XSRDconst {
@ -12127,7 +12127,7 @@ func rewriteValueS390X_OpS390XSLDconst(v *Value) bool {
c := auxIntToUint8(v_0.AuxInt)
x := v_0.Args[0]
v.reset(OpS390XRISBGZ)
v.Aux = s390xRotateParamsToAux(s390x.NewRotateParams(uint8(max8(0, int8(c-d))), 63-d, uint8(int8(d-c)&63)))
v.Aux = s390xRotateParamsToAux(s390x.NewRotateParams(uint8(max(0, int8(c-d))), 63-d, uint8(int8(d-c)&63)))
v.AddArg(x)
return true
}
@ -12874,7 +12874,7 @@ func rewriteValueS390X_OpS390XSRD(v *Value) bool {
func rewriteValueS390X_OpS390XSRDconst(v *Value) bool {
v_0 := v.Args[0]
// match: (SRDconst (SLDconst x [c]) [d])
// result: (RISBGZ x {s390x.NewRotateParams(d, uint8(min8(63, int8(63-c+d))), uint8(int8(c-d)&63))})
// result: (RISBGZ x {s390x.NewRotateParams(d, uint8(min(63, int8(63-c+d))), uint8(int8(c-d)&63))})
for {
d := auxIntToUint8(v.AuxInt)
if v_0.Op != OpS390XSLDconst {
@ -12883,7 +12883,7 @@ func rewriteValueS390X_OpS390XSRDconst(v *Value) bool {
c := auxIntToUint8(v_0.AuxInt)
x := v_0.Args[0]
v.reset(OpS390XRISBGZ)
v.Aux = s390xRotateParamsToAux(s390x.NewRotateParams(d, uint8(min8(63, int8(63-c+d))), uint8(int8(c-d)&63)))
v.Aux = s390xRotateParamsToAux(s390x.NewRotateParams(d, uint8(min(63, int8(63-c+d))), uint8(int8(c-d)&63)))
v.AddArg(x)
return true
}

View file

@ -3863,7 +3863,7 @@ func (s *state) condBranch(cond ir.Node, yes, no *ssa.Block, likely int8) {
cond := cond.(*ir.LogicalExpr)
mid := s.f.NewBlock(ssa.BlockPlain)
s.stmtList(cond.Init())
s.condBranch(cond.X, mid, no, max8(likely, 0))
s.condBranch(cond.X, mid, no, max(likely, 0))
s.startBlock(mid)
s.condBranch(cond.Y, yes, no, likely)
return
@ -3877,7 +3877,7 @@ func (s *state) condBranch(cond ir.Node, yes, no *ssa.Block, likely int8) {
cond := cond.(*ir.LogicalExpr)
mid := s.f.NewBlock(ssa.BlockPlain)
s.stmtList(cond.Init())
s.condBranch(cond.X, yes, mid, min8(likely, 0))
s.condBranch(cond.X, yes, mid, min(likely, 0))
s.startBlock(mid)
s.condBranch(cond.Y, yes, no, likely)
return
@ -7401,20 +7401,6 @@ func callTargetLSym(callee *ir.Name) *obj.LSym {
return callee.LinksymABI(callee.Func.ABI)
}
func min8(a, b int8) int8 {
if a < b {
return a
}
return b
}
func max8(a, b int8) int8 {
if a > b {
return a
}
return b
}
// deferStructFnField is the field index of _defer.fn.
const deferStructFnField = 4

View file

@ -405,13 +405,6 @@ func xgetgoarm() string {
return "7"
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
// elfIsLittleEndian detects if the ELF file is little endian.
func elfIsLittleEndian(fn string) bool {
// read the ELF file header to determine the endianness without using the