cmd/compile: allow noop conversions when comparing expressions

Allows mapclear optimization to trigger in more cases, including
some generic instantiations.

Fixes #51699

Change-Id: Ic54f7686e5fcb8fbcad640aa77ed326d7338b938
Reviewed-on: https://go-review.googlesource.com/c/go/+/393434
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Keith Randall 2022-03-16 09:24:06 -07:00
parent ed4db86118
commit e5e638e512

View file

@ -973,6 +973,12 @@ var IsIntrinsicCall = func(*CallExpr) bool { return false }
// lvalue expression is for OSLICE and OAPPEND optimizations, and it // lvalue expression is for OSLICE and OAPPEND optimizations, and it
// is correct in those settings. // is correct in those settings.
func SameSafeExpr(l Node, r Node) bool { func SameSafeExpr(l Node, r Node) bool {
for l.Op() == OCONVNOP {
l = l.(*ConvExpr).X
}
for r.Op() == OCONVNOP {
r = r.(*ConvExpr).X
}
if l.Op() != r.Op() || !types.Identical(l.Type(), r.Type()) { if l.Op() != r.Op() || !types.Identical(l.Type(), r.Type()) {
return false return false
} }
@ -996,11 +1002,6 @@ func SameSafeExpr(l Node, r Node) bool {
r := r.(*UnaryExpr) r := r.(*UnaryExpr)
return SameSafeExpr(l.X, r.X) return SameSafeExpr(l.X, r.X)
case OCONVNOP:
l := l.(*ConvExpr)
r := r.(*ConvExpr)
return SameSafeExpr(l.X, r.X)
case OCONV: case OCONV:
l := l.(*ConvExpr) l := l.(*ConvExpr)
r := r.(*ConvExpr) r := r.(*ConvExpr)