From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4C0BB3857C4F; Sat, 24 Jul 2021 07:15:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C0BB3857C4F From: "Hi-Angel at yandex dot ru" To: gcc-bugs@gcc.gnu.org Subject: =?UTF-8?B?W0J1ZyBjKysvOTI1NTldIFJldHVybmluZyBzdGTiiLdtYXAgYnJl?= =?UTF-8?B?YWtzIHRhaWwtcmVjdXJzaW9uIG9wdGltaXphdGlvbg==?= Date: Sat, 24 Jul 2021 07:15:33 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 9.2.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: Hi-Angel at yandex dot ru X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Jul 2021 07:15:33 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D92559 --- Comment #3 from Konstantin Kharlamov --- (In reply to Andrew Pinski from comment #2) > I don't think this can ever be optimized. Mainly because there are copies > happening due to passing via value and returning by value. Please correct me if I'm wrong, but it seems like, given the code in questi= on: MyMap foo(MyMap m) { if (m[0] =3D=3D 0) return m; else { m[0] -=3D 1; return foo(m); } } When tail-recursion optimization applied, it should be analogous to this co= de: MyMap foo(MyMap m) { while(m[0] > 0) { m[0] -=3D 1; m =3D MyMap(m); } return m; } Doesn't look impossible to me, unless of course I am missing something.=