From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29962 invoked by alias); 24 Mar 2014 20:59:13 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 29935 invoked by uid 48); 24 Mar 2014 20:59:09 -0000 From: "akruppa at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/60641] New: Converting ushort to offset on x86_64 generates double movzwl Date: Mon, 24 Mar 2014 20:59:00 -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: 4.7.3 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: akruppa at gmail dot com X-Bugzilla-Status: UNCONFIRMED 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 Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-03/txt/msg02189.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60641 Bug ID: 60641 Summary: Converting ushort to offset on x86_64 generates double movzwl Product: gcc Version: 4.7.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: akruppa at gmail dot com The following test cases produce sub-optimal assembly output. This was verified with these three versions of gcc: gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 gcc (SUSE Linux) 4.7.3 gcc (Debian 4.8.2-16) 4.8.2 #include unsigned short foo (const unsigned short *start, const unsigned char *mask) { unsigned short r = 0; unsigned short ux = *start; if (mask[ux]) r = ux; return r; } void bar(unsigned int *s, unsigned short a) { s[a] = a; } Compile with, e.g., gcc -std=c99 -g -W -Wall -O3 -c movzwl.c The effect also occurs when using -O2 instead. The foo() function contains: 0x0000000000000000 <+0>: movzwl (%rdi),%edx 0x0000000000000003 <+3>: xor %eax,%eax 0x0000000000000005 <+5>: movzwl %dx,%ecx 0x0000000000000008 <+8>: cmpb $0x0,(%rsi,%rcx,1) The foo() function is: 0x0000000000000010 <+0>: movzwl %si,%eax 0x0000000000000013 <+3>: movzwl %si,%esi 0x0000000000000016 <+6>: mov %esi,(%rdi,%rax,4) 0x0000000000000019 <+9>: retq In both cases, an unnecessary movzwl instruction is generated. This may be the same issue as #36873, which was rejected because the test cases used volatile accesses. These test cases here show that the duplicate movzwl occurs without volatile as well.