From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7EA803861810; Thu, 24 Jun 2021 20:19:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7EA803861810 From: "steinar+gcc at gunderson dot no" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/101200] New: Unneeded AND after shift Date: Thu, 24 Jun 2021 20:19:04 +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: 11.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: steinar+gcc at gunderson dot no 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 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: Thu, 24 Jun 2021 20:19:04 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101200 Bug ID: 101200 Summary: Unneeded AND after shift Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: steinar+gcc at gunderson dot no Target Milestone: --- The code after reduction is: struct { int b[6]; } c; unsigned char d; void e() { unsigned char a =3D d >> 4, f =3D d & 15; c.b[a] =3D c.b[f]; } with g++-11 -O2, this produces movzbl d(%rip), %eax movq %rax, %rdx shrq $4, %rax andl $15, %edx andl $15, %eax movl c(,%rdx,4), %edx movl %edx, c(,%rax,4) ret The second AND with 15 is unneeded and should have been optimized away by V= RP as I understand it. I can't reproduce it with ARM, though, so maybe there's something x86-specific? Compiler is gcc version 11.1.0 (Debian 11.1.0-3)=20 The same code is generated back to at least 4.9. Also present in gcc version 12.0.0 20210527 (experimental) [master revision 262e75d22c3:7bb6b9b2f47:9d3a953ec4d2695e9a6bfa5f22655e2aea47a973] (Debian 20210527-1)=