From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 165D23882100; Fri, 14 Jun 2024 00:49:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 165D23882100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1718326197; bh=gd7QYGXx4cmfe/LzsZNQx+yGn+pGiPtKojWmP1xx75E=; h=From:To:Subject:Date:From; b=iv/nZr3sO+OYlYNl1KehhDCBO9vcnuPT1PkWaiHUeVKfjAmsk3CNK3BnWjuhlciBp oqrXdxg/PpYf9XFS72e0YJyb8+jasapS/6rWnwUbkxBOcFsAr+IF8POSlWHy/3ChOV Bpdk2mYKUc8642ku+mgx6n2ch9rNAAuRkzdGLHJs= From: "zhiwuyazhe154 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/115483] New: Missed optimization for loop invariant code Date: Fri, 14 Jun 2024 00:49:56 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 15.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: zhiwuyazhe154 at gmail dot com X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone Message-ID: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D115483 Bug ID: 115483 Summary: Missed optimization for loop invariant code Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: zhiwuyazhe154 at gmail dot com Target Milestone: --- Godbolt example: https://godbolt.org/z/s75d4GfTT code example: unsigned m,n; unsigned func(unsigned a, unsigned b,=20 unsigned c, unsigned d) { for(unsigned i=3D0; i<100; i++) { m +=3D 1024; b +=3D c/n + (c + d) + m; m +=3D m; } return b; }=20 In this case, c/n + (c + d) is loop invariant code. It seems that reassociate breaks the optimization of licm. There are a few other issues that mention the shortcomings of reassociate, = but there doesn't seem to be an issue that shows its negative impact. GCC -O3: func(unsigned int, unsigned int, unsigned int, unsigned int): mov eax, edx mov r9d, edx xor edx, edx mov r8d, esi div DWORD PTR n[rip] mov esi, DWORD PTR m[rip] mov edi, 100 .L2: add esi, 1024 lea edx, [rsi+rcx] add esi, esi add edx, r9d add edx, eax add r8d, edx sub edi, 1 jne .L2 mov DWORD PTR m[rip], esi mov eax, r8d ret=