This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/54579] New: missed optimization: ASR idiom
- From: "rearnsha at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 14 Sep 2012 13:34:04 +0000
- Subject: [Bug tree-optimization/54579] New: missed optimization: ASR idiom
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54579
Bug #: 54579
Summary: missed optimization: ASR idiom
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: rearnsha@gcc.gnu.org
The idiom
int asr(int a, int b)
{
return a < 0 ? -(-a - 1 >> b) - 1 : a >> b;
}
is equivalent to a portable form of arithmetic right shift. However, at -O2
GCC currently generates something like
cmp r0, #0
mvnlt r0, r0
mvnlt r0, r0, asr r1
movge r0, r0, asr r1
on ARM, or
testl %edi, %edi
movl %esi, %ecx
js .L7
movl %edi, %eax
sarl %cl, %eax
ret
.p2align 4,,7
.L7:
movl %edi, %eax
notl %eax
sarl %cl, %eax
notl %eax
ret
on x86.
On ARM this should just be:
asr r0, r0, r1