[llvm-bugs] [Bug 34282] New: Failure to remove redundant check
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Aug 22 08:52:37 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=34282
Bug ID: 34282
Summary: Failure to remove redundant check
Product: libraries
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Scalar Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: aivchenk at gmail.com
CC: llvm-bugs at lists.llvm.org
For the following function:
int foo(char* C, int a, int b, int c, int d, int e, int f) {
int y1 = C[0] ? a : b;
int y2 = C[0] || C[1] ? c : d;
int y3 = C[0] || (C[1] && C[2]) ? e : f;
return C[0] ? y1 + y2 : C[1] ? y2 : y3;
}
>
.. we generate bad code:
# BB#0:
cmpb $0, (%rdi)
je .LBB0_1
# BB#5:
addl %esi, %ecx
movl %ecx, %eax
retq
.LBB0_1:
movl 8(%rsp), %eax
movb 1(%rdi), %dl
testb %dl, %dl
je .LBB0_3
# BB#2:
cmpb $0, 2(%rdi)
cmovnel %r9d, %eax
.LBB0_3:
testb %dl, %dl
cmovel %eax, %ecx
movl %ecx, %eax
retq
Just for comparison, here is GCC version:
cmpb $0, (%rdi)
leal (%rsi,%rcx), %eax
jne .L1
cmpb $0, 1(%rdi)
movl %ecx, %eax
cmove 8(%rsp), %eax
.L1:
rep ret
The main problem with LLVM code is that we do redundant "cmpb $0, 2(%rdi)"
check (while GCC removed that): C[2] does not influence the function return
value. As far as I can say, all other problems with our code, like doing testb
twice for cmov condition, are the result of not deleting the C[2] check
--
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/20170822/46f1063f/attachment.html>
More information about the llvm-bugs
mailing list