[LLVMbugs] [Bug 19758] New: Missed optimization opportunity in 3-way unsigned integer comparison case
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Thu May 15 10:46:00 PDT 2014
http://llvm.org/bugs/show_bug.cgi?id=19758
Bug ID: 19758
Summary: Missed optimization opportunity in 3-way unsigned
integer comparison case
Product: libraries
Version: 3.3
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Common Code Generator Code
Assignee: unassignedbugs at nondot.org
Reporter: yuri at tsoft.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
>From testcases for int and unsigned comparisons it is obvious that llvm uses
two cmpl instructions in unsigned case, and only one in signed case. unsigned
comparision can also be done with only one cmpl instruction, see the procedure
below.
rev.208525
--- testcase: int comparison ---
int mycmp (int i1, int i2) {
if (i1<i2)
return -1;
else if (i1>i2)
return 1;
return 0;
}
.text
.file "cmpi.c"
.globl mycmp
.align 16, 0x90
.type mycmp, at function
mycmp:
pushq %rbp
movq %rsp, %rbp
movl $-1, %eax
cmpl %esi, %edi
jl .LBB0_2
setg %al
movzbl %al, %eax
.LBB0_2:
popq %rbp
retq
.Ltmp3:
.size mycmp, .Ltmp3-mycmp
--- testcase: unsigned comparison ---
int mycmp (unsigned i1, unsigned i2) {
if (i1<i2)
return -1;
else if (i1>i2)
return 1;
return 0;
}
.text
.file "cmpu.c"
.globl mycmp
.align 16, 0x90
.type mycmp, at function
mycmp:
pushq %rbp
movq %rsp, %rbp
movl $-1, %eax
cmpl %esi, %edi
jb .LBB0_2
cmpl %edi, %esi
sbbl %eax, %eax
andl $1, %eax
.LBB0_2:
popq %rbp
retq
.Ltmp3:
.size mycmp, .Ltmp3-mycmp
--- the correct way to do an unsigned comparison ---
.text
.file "cmp.c"
.globl mycmp
.align 16, 0x90
.type mycmp, at function
mycmp:
pushq %rbp
movq %rsp, %rbp
movl $-1, %eax
cmpl %edi, %esi
ja .LBB0_2
sbbl %eax, %eax
andl $1, %eax
.LBB0_2:
popq %rbp
retq
.Ltmp3:
.size mycmp, .Ltmp3-mycmp
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140515/b3f20369/attachment.html>
More information about the llvm-bugs
mailing list