]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: handle min/max correctly in mayCall
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 28 Jun 2023 16:15:35 +0000 (23:15 +0700)
committerGopher Robot <gobot@golang.org>
Wed, 28 Jun 2023 21:18:31 +0000 (21:18 +0000)
CL 500575 changed mayCall to return "false" for min/max builtin.

However, with string or float, min/max requires runtime call, so mayCall
should return true instead. This's probably not a big problem, because
CL 506115 makes order pass handle min/max correctly. But it's still
better to do it the right way.

Updates #60582

Change-Id: I9779ca62bebd0f95e52ad5fa55b9160dc35b33aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/506855
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/compile/internal/walk/walk.go

index 265066200c6f8441831dfb6b8fbbc575d227bb9a..778b95d5473569350d7baf58a772384f6d514d28 100644 (file)
@@ -337,10 +337,14 @@ func mayCall(n ir.Node) bool {
                        n := n.(*ir.ConvExpr)
                        return ssagen.Arch.SoftFloat && (isSoftFloat(n.Type()) || isSoftFloat(n.X.Type()))
 
+               case ir.OMIN, ir.OMAX:
+                       // string or float requires runtime call, see (*ssagen.state).minmax method.
+                       return n.Type().IsString() || n.Type().IsFloat()
+
                case ir.OLITERAL, ir.ONIL, ir.ONAME, ir.OLINKSYMOFFSET, ir.OMETHEXPR,
                        ir.OAND, ir.OANDNOT, ir.OLSH, ir.OOR, ir.ORSH, ir.OXOR, ir.OCOMPLEX, ir.OEFACE,
                        ir.OADDR, ir.OBITNOT, ir.ONOT, ir.OPLUS,
-                       ir.OCAP, ir.OIMAG, ir.OLEN, ir.OREAL, ir.OMIN, ir.OMAX,
+                       ir.OCAP, ir.OIMAG, ir.OLEN, ir.OREAL,
                        ir.OCONVNOP, ir.ODOT,
                        ir.OCFUNC, ir.OIDATA, ir.OITAB, ir.OSPTR,
                        ir.OBYTES2STRTMP, ir.OGETG, ir.OGETCALLERPC, ir.OGETCALLERSP, ir.OSLICEHEADER, ir.OSTRINGHEADER: