From 269906548310445132bbf2f14233485e3875e730 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Tue, 9 Aug 2022 02:55:42 +0700 Subject: [PATCH] cmd/compile: do not write implicit conversion for append in Unified IR Same as CL 418475, but for Unified IR. Updates #53888 Fixes #54337 Change-Id: I31d5a7af04d8e3902ed25db85009d46ea4c38dbe Reviewed-on: https://go-review.googlesource.com/c/go/+/422040 TryBot-Result: Gopher Robot Reviewed-by: Matthew Dempsky Run-TryBot: Cuong Manh Le Reviewed-by: Than McIntosh --- src/cmd/compile/internal/noder/reader.go | 7 +++++++ src/cmd/compile/internal/test/issue53888_test.go | 3 +-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index 668aa201a91..4bdce25ccac 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -1989,6 +1989,13 @@ func (r *reader) expr() (res ir.Node) { case ir.OAPPEND: n := n.(*ir.CallExpr) n.RType = r.rtype(pos) + // For append(a, b...), we don't need the implicit conversion. The typechecker already + // ensured that a and b are both slices with the same base type, or []byte and string. + if n.IsDDD { + if conv, ok := n.Args[1].(*ir.ConvExpr); ok && conv.Op() == ir.OCONVNOP && conv.Implicit() { + n.Args[1] = conv.X + } + } case ir.OCOPY: n := n.(*ir.BinaryExpr) n.RType = r.rtype(pos) diff --git a/src/cmd/compile/internal/test/issue53888_test.go b/src/cmd/compile/internal/test/issue53888_test.go index 89c40eca2b2..0d5b13b5c87 100644 --- a/src/cmd/compile/internal/test/issue53888_test.go +++ b/src/cmd/compile/internal/test/issue53888_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build !race && !goexperiment.unified +//go:build !race package test @@ -11,7 +11,6 @@ import ( "testing" ) -// TODO(cuonglm,mdempsky): figure out why Unifed IR failed? func TestAppendOfMake(t *testing.T) { testenv.SkipIfOptimizationOff(t) for n := 32; n < 33; n++ { // avoid stack allocation of make()