cmd/compile: name change isDirect -> isDirectAndComparable

Now that it also restricts to comparable types. Followon to CL 713840.

Change-Id: Idd975c3fd16fb51f55360f2fa0b89ab0bf1d00ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/715700
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Mateusz Poliwczak <mpoliwczak34@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Keith Randall 2025-10-28 10:07:48 -07:00 committed by Gopher Robot
parent bd4dc413cd
commit ea50d61b66
3 changed files with 21 additions and 21 deletions

View file

@ -2927,7 +2927,7 @@
// we know the underlying type is pointer-ish.
(StaticLECall {f} typ_ x y mem)
&& isSameCall(f, "runtime.efaceeq")
&& isDirectType(typ_)
&& isDirectAndComparableType(typ_)
&& clobber(v)
=> (MakeResult (EqPtr x y) mem)
@ -2935,7 +2935,7 @@
// we know the underlying type is pointer-ish.
(StaticLECall {f} itab x y mem)
&& isSameCall(f, "runtime.ifaceeq")
&& isDirectIface(itab)
&& isDirectAndComparableIface(itab)
&& clobber(v)
=> (MakeResult (EqPtr x y) mem)

View file

@ -2624,18 +2624,18 @@ func rewriteStructStore(v *Value) *Value {
return mem
}
// isDirectType reports whether v represents a type
// isDirectAndComparableType reports whether v represents a type
// (a *runtime._type) whose value is stored directly in an
// interface (i.e., is pointer or pointer-like) and is comparable.
func isDirectType(v *Value) bool {
return isDirectType1(v)
func isDirectAndComparableType(v *Value) bool {
return isDirectAndComparableType1(v)
}
// v is a type
func isDirectType1(v *Value) bool {
func isDirectAndComparableType1(v *Value) bool {
switch v.Op {
case OpITab:
return isDirectType2(v.Args[0])
return isDirectAndComparableType2(v.Args[0])
case OpAddr:
lsym := v.Aux.(*obj.LSym)
if ti := lsym.TypeInfo(); ti != nil {
@ -2647,29 +2647,29 @@ func isDirectType1(v *Value) bool {
}
// v is an empty interface
func isDirectType2(v *Value) bool {
func isDirectAndComparableType2(v *Value) bool {
switch v.Op {
case OpIMake:
return isDirectType1(v.Args[0])
return isDirectAndComparableType1(v.Args[0])
}
return false
}
// isDirectIface reports whether v represents an itab
// isDirectAndComparableIface reports whether v represents an itab
// (a *runtime._itab) for a type whose value is stored directly
// in an interface (i.e., is pointer or pointer-like) and is comparable.
func isDirectIface(v *Value) bool {
return isDirectIface1(v, 9)
func isDirectAndComparableIface(v *Value) bool {
return isDirectAndComparableIface1(v, 9)
}
// v is an itab
func isDirectIface1(v *Value, depth int) bool {
func isDirectAndComparableIface1(v *Value, depth int) bool {
if depth == 0 {
return false
}
switch v.Op {
case OpITab:
return isDirectIface2(v.Args[0], depth-1)
return isDirectAndComparableIface2(v.Args[0], depth-1)
case OpAddr:
lsym := v.Aux.(*obj.LSym)
if ii := lsym.ItabInfo(); ii != nil {
@ -2685,16 +2685,16 @@ func isDirectIface1(v *Value, depth int) bool {
}
// v is an interface
func isDirectIface2(v *Value, depth int) bool {
func isDirectAndComparableIface2(v *Value, depth int) bool {
if depth == 0 {
return false
}
switch v.Op {
case OpIMake:
return isDirectIface1(v.Args[0], depth-1)
return isDirectAndComparableIface1(v.Args[0], depth-1)
case OpPhi:
for _, a := range v.Args {
if !isDirectIface2(a, depth-1) {
if !isDirectAndComparableIface2(a, depth-1) {
return false
}
}

View file

@ -32612,7 +32612,7 @@ func rewriteValuegeneric_OpStaticLECall(v *Value) bool {
return true
}
// match: (StaticLECall {f} typ_ x y mem)
// cond: isSameCall(f, "runtime.efaceeq") && isDirectType(typ_) && clobber(v)
// cond: isSameCall(f, "runtime.efaceeq") && isDirectAndComparableType(typ_) && clobber(v)
// result: (MakeResult (EqPtr x y) mem)
for {
if len(v.Args) != 4 {
@ -32623,7 +32623,7 @@ func rewriteValuegeneric_OpStaticLECall(v *Value) bool {
typ_ := v.Args[0]
x := v.Args[1]
y := v.Args[2]
if !(isSameCall(f, "runtime.efaceeq") && isDirectType(typ_) && clobber(v)) {
if !(isSameCall(f, "runtime.efaceeq") && isDirectAndComparableType(typ_) && clobber(v)) {
break
}
v.reset(OpMakeResult)
@ -32633,7 +32633,7 @@ func rewriteValuegeneric_OpStaticLECall(v *Value) bool {
return true
}
// match: (StaticLECall {f} itab x y mem)
// cond: isSameCall(f, "runtime.ifaceeq") && isDirectIface(itab) && clobber(v)
// cond: isSameCall(f, "runtime.ifaceeq") && isDirectAndComparableIface(itab) && clobber(v)
// result: (MakeResult (EqPtr x y) mem)
for {
if len(v.Args) != 4 {
@ -32644,7 +32644,7 @@ func rewriteValuegeneric_OpStaticLECall(v *Value) bool {
itab := v.Args[0]
x := v.Args[1]
y := v.Args[2]
if !(isSameCall(f, "runtime.ifaceeq") && isDirectIface(itab) && clobber(v)) {
if !(isSameCall(f, "runtime.ifaceeq") && isDirectAndComparableIface(itab) && clobber(v)) {
break
}
v.reset(OpMakeResult)