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 return left
} }
func max(a, b int8) int8 {
if a > b {
return a
}
return b
}
func (t *node32) copy() *node32 { func (t *node32) copy() *node32 {
u := *t u := *t
return &u return &u

View file

@ -703,10 +703,10 @@
(CMP(W|WU) (MOVDconst [c]) x) => (InvertFlags (CMP(W|WU)const x [int32(c)])) (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]'. // 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]'. // 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]'. // 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)}) (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 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 ( const (
blDEFAULT = 0 blDEFAULT = 0
blMin = blDEFAULT blMin = blDEFAULT
@ -143,7 +129,7 @@ func likelyadjust(f *Func) {
// and less influential than inferences from loop structure. // and less influential than inferences from loop structure.
case BlockDefer: case BlockDefer:
local[b.ID] = blCALL 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: default:
if len(b.Succs) == 1 { 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. // tagged with call cost. Net effect is that loop entry is favored.
b0 := b.Succs[0].b.ID b0 := b.Succs[0].b.ID
b1 := b.Succs[1].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] l := b2l[b.ID]
l0 := b2l[b0] l0 := b2l[b0]
@ -223,7 +209,7 @@ func likelyadjust(f *Func) {
for _, v := range b.Values { for _, v := range b.Values {
if opcodeTable[v.Op].call { if opcodeTable[v.Op].call {
local[b.ID] = blCALL 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 break
} }
} }

View file

@ -1737,13 +1737,13 @@ func (ft *factsTable) flowLimit(v *Value) bool {
// AND can only make the value smaller. // AND can only make the value smaller.
a := ft.limits[v.Args[0].ID] a := ft.limits[v.Args[0].ID]
b := ft.limits[v.Args[1].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: case OpOr64, OpOr32, OpOr16, OpOr8:
// OR can only make the value bigger and can't flip bits proved to be zero in both inputs. // 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] a := ft.limits[v.Args[0].ID]
b := ft.limits[v.Args[1].ID] b := ft.limits[v.Args[1].ID]
return ft.unsignedMinMax(v, return ft.unsignedMinMax(v,
maxU(a.umin, b.umin), max(a.umin, b.umin),
1<<bits.Len64(a.umax|b.umax)-1) 1<<bits.Len64(a.umax|b.umax)-1)
case OpXor64, OpXor32, OpXor16, OpXor8: case OpXor64, OpXor32, OpXor16, OpXor8:
// XOR can't flip bits that are proved to be zero in both inputs. // 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] a := ft.limits[v.Args[0].ID]
b := ft.limits[v.Args[1].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. // 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: case OpDiv64, OpDiv32, OpDiv16, OpDiv8:
a := ft.limits[v.Args[0].ID] a := ft.limits[v.Args[0].ID]
b := ft.limits[v.Args[1].ID] b := ft.limits[v.Args[1].ID]
@ -1871,8 +1871,8 @@ func (ft *factsTable) flowLimit(v *Value) bool {
l2 := ft.limits[a.ID] l2 := ft.limits[a.ID]
l.min = min(l.min, l2.min) l.min = min(l.min, l2.min)
l.max = max(l.max, l2.max) l.max = max(l.max, l2.max)
l.umin = minU(l.umin, l2.umin) l.umin = min(l.umin, l2.umin)
l.umax = maxU(l.umax, l2.umax) l.umax = max(l.umax, l2.umax)
} }
return ft.newLimit(v, l) 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] vi := &s.values[v.ID]
if vi.spill != nil { if vi.spill != nil {
// Final block not known - keep track of subtree where restores reside. // Final block not known - keep track of subtree where restores reside.
vi.restoreMin = min32(vi.restoreMin, s.sdom[b.ID].entry) vi.restoreMin = min(vi.restoreMin, s.sdom[b.ID].entry)
vi.restoreMax = max32(vi.restoreMax, s.sdom[b.ID].exit) vi.restoreMax = max(vi.restoreMax, s.sdom[b.ID].exit)
return vi.spill return vi.spill
} }
// Make a spill for v. We don't know where we want // 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) 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 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 { func isConstZero(v *Value) bool {
switch v.Op { switch v.Op {
case OpConstNil: case OpConstNil:

View file

@ -12118,7 +12118,7 @@ func rewriteValueS390X_OpS390XSLD(v *Value) bool {
func rewriteValueS390X_OpS390XSLDconst(v *Value) bool { func rewriteValueS390X_OpS390XSLDconst(v *Value) bool {
v_0 := v.Args[0] v_0 := v.Args[0]
// match: (SLDconst (SRDconst x [c]) [d]) // 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 { for {
d := auxIntToUint8(v.AuxInt) d := auxIntToUint8(v.AuxInt)
if v_0.Op != OpS390XSRDconst { if v_0.Op != OpS390XSRDconst {
@ -12127,7 +12127,7 @@ func rewriteValueS390X_OpS390XSLDconst(v *Value) bool {
c := auxIntToUint8(v_0.AuxInt) c := auxIntToUint8(v_0.AuxInt)
x := v_0.Args[0] x := v_0.Args[0]
v.reset(OpS390XRISBGZ) 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) v.AddArg(x)
return true return true
} }
@ -12874,7 +12874,7 @@ func rewriteValueS390X_OpS390XSRD(v *Value) bool {
func rewriteValueS390X_OpS390XSRDconst(v *Value) bool { func rewriteValueS390X_OpS390XSRDconst(v *Value) bool {
v_0 := v.Args[0] v_0 := v.Args[0]
// match: (SRDconst (SLDconst x [c]) [d]) // 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 { for {
d := auxIntToUint8(v.AuxInt) d := auxIntToUint8(v.AuxInt)
if v_0.Op != OpS390XSLDconst { if v_0.Op != OpS390XSLDconst {
@ -12883,7 +12883,7 @@ func rewriteValueS390X_OpS390XSRDconst(v *Value) bool {
c := auxIntToUint8(v_0.AuxInt) c := auxIntToUint8(v_0.AuxInt)
x := v_0.Args[0] x := v_0.Args[0]
v.reset(OpS390XRISBGZ) 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) v.AddArg(x)
return true 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) cond := cond.(*ir.LogicalExpr)
mid := s.f.NewBlock(ssa.BlockPlain) mid := s.f.NewBlock(ssa.BlockPlain)
s.stmtList(cond.Init()) 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.startBlock(mid)
s.condBranch(cond.Y, yes, no, likely) s.condBranch(cond.Y, yes, no, likely)
return return
@ -3877,7 +3877,7 @@ func (s *state) condBranch(cond ir.Node, yes, no *ssa.Block, likely int8) {
cond := cond.(*ir.LogicalExpr) cond := cond.(*ir.LogicalExpr)
mid := s.f.NewBlock(ssa.BlockPlain) mid := s.f.NewBlock(ssa.BlockPlain)
s.stmtList(cond.Init()) 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.startBlock(mid)
s.condBranch(cond.Y, yes, no, likely) s.condBranch(cond.Y, yes, no, likely)
return return
@ -7401,20 +7401,6 @@ func callTargetLSym(callee *ir.Name) *obj.LSym {
return callee.LinksymABI(callee.Func.ABI) 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. // deferStructFnField is the field index of _defer.fn.
const deferStructFnField = 4 const deferStructFnField = 4

View file

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