From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BBB3F385BF84; Fri, 20 Aug 2021 02:35:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBB3F385BF84 From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/101991] New: bit_and or bit_ior with an invariant inside loop is not pulled out of the loop Date: Fri, 20 Aug 2021 02:35:48 +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: 12.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: pinskia at gcc dot gnu.org 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 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: Fri, 20 Aug 2021 02:35:48 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101991 Bug ID: 101991 Summary: bit_and or bit_ior with an invariant inside loop is not pulled out of the loop Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take these two functions: int f(int t, int d, int e) { int r =3D d; for(int i =3D 0; i < t; i++) r &=3D e; return r; } int f1(int t, int d, int e) { int r =3D d; if (0 < t) r &=3D e; return r; } They should produce the same code. Right now f still has a loop in it. The same is true with bit_ior. Note the code is really bad when the vectorizer comes around really. I forgot how I found this either. Note clang/ICC also vectorize this code crappily. clang on the trunk almost gets there but still has a loop: movl %esi, %eax xorl %esi, %esi testl %edi, %edi cmovgl %edi, %esi jle .LBB0_6 # %bb.1: leal -1(%rsi), %edi movl %esi, %ecx andl $7, %ecx cmpl $7, %edi jb .LBB0_4 # %bb.2: andl $-8, %esi negl %esi .p2align 4, 0x90 .LBB0_3: # =3D>This Inner Loop Header: Depth= =3D1 addl $8, %esi jne .LBB0_3 .LBB0_4: andl %edx, %eax testl %ecx, %ecx je .LBB0_6 .p2align 4, 0x90 .LBB0_5: # =3D>This Inner Loop Header: Depth= =3D1 addl $-1, %ecx jne .LBB0_5 .LBB0_6: retq=