public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/101200] New: Unneeded AND after shift
@ 2021-06-24 20:19 steinar+gcc at gunderson dot no
  2021-06-24 20:37 ` [Bug rtl-optimization/101200] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: steinar+gcc at gunderson dot no @ 2021-06-24 20:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101200

            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 = d >> 4, f = d & 15;
  c.b[a] = 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 VRP
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) 

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)

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-06-29 17:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-24 20:19 [Bug tree-optimization/101200] New: Unneeded AND after shift steinar+gcc at gunderson dot no
2021-06-24 20:37 ` [Bug rtl-optimization/101200] " pinskia at gcc dot gnu.org
2021-06-24 20:45 ` pinskia at gcc dot gnu.org
2021-06-24 20:50 ` pinskia at gcc dot gnu.org
2021-06-25  9:34 ` [Bug target/101200] " jakub at gcc dot gnu.org
2021-06-25  9:38 ` jakub at gcc dot gnu.org
2021-06-25 10:38 ` steinar+gcc at gunderson dot no
2021-06-29 17:40 ` law at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).