[llvm-bugs] [Bug 31703] New: DCE optimization lost after manual inlining
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Jan 20 03:22:11 PST 2017
https://llvm.org/bugs/show_bug.cgi?id=31703
Bug ID: 31703
Summary: DCE optimization lost after manual inlining
Product: clang
Version: 3.9
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: skvadrik at gmail.com
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
Classification: Unclassified
Created attachment 17870
--> https://llvm.org/bugs/attachment.cgi?id=17870&action=edit
a.c, b.c
Consider the following two snippets, a.c and b.c (in attach):
// a.c:
static void f(const char *s)
{
for (; *s++ == '0'; );
}
int main(int argc, char **argv)
{
const char *s0 = argv[1];
for (int x = 0; x < 1000000000; ++x) f(s0);
return 0;
}
// b.c is the same as a.c with 'f' inlined:
int main(int argc, char **argv)
{
const char *s0 = argv[1];
for (int x = 0; x < 1000000000; ++x) {
for (const char *s = s0; *s++ == '0'; );
}
return 0;
}
Clang manages to optimize a.c to just 'return 0':
$ clang++-3.9 -c -O2 a.c -oa.o && objdump -d a.o
clang-3.9: warning: treating 'c' input as 'c++' when in C++ mode, this behavior
is deprecated
a.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <main>:
0: 31 c0 xor %eax,%eax
2: c3 retq
However, after manual inlining of 'f' this optimization fails:
$ clang++-3.9 -c -O2 b.c -ob.o && objdump -d b.o
clang-3.9: warning: treating 'c' input as 'c++' when in C++ mode, this behavior
is deprecated
b.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <main>:
0: 48 8b 46 08 mov 0x8(%rsi),%rax
4: 31 c9 xor %ecx,%ecx
6: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
d: 00 00 00
10: 48 89 c2 mov %rax,%rdx
13: 66 66 66 66 2e 0f 1f data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
1a: 84 00 00 00 00 00
20: 80 3a 30 cmpb $0x30,(%rdx)
23: 48 8d 52 01 lea 0x1(%rdx),%rdx
27: 74 f7 je 20 <main+0x20>
29: 48 89 c2 mov %rax,%rdx
2c: 0f 1f 40 00 nopl 0x0(%rax)
30: 80 3a 30 cmpb $0x30,(%rdx)
33: 48 8d 52 01 lea 0x1(%rdx),%rdx
37: 74 f7 je 30 <main+0x30>
39: 48 89 c2 mov %rax,%rdx
3c: 0f 1f 40 00 nopl 0x0(%rax)
40: 80 3a 30 cmpb $0x30,(%rdx)
43: 48 8d 52 01 lea 0x1(%rdx),%rdx
47: 74 f7 je 40 <main+0x40>
49: 48 89 c2 mov %rax,%rdx
4c: 0f 1f 40 00 nopl 0x0(%rax)
50: 80 3a 30 cmpb $0x30,(%rdx)
53: 48 8d 52 01 lea 0x1(%rdx),%rdx
57: 74 f7 je 50 <main+0x50>
59: 48 89 c2 mov %rax,%rdx
5c: 0f 1f 40 00 nopl 0x0(%rax)
60: 80 3a 30 cmpb $0x30,(%rdx)
63: 48 8d 52 01 lea 0x1(%rdx),%rdx
67: 74 f7 je 60 <main+0x60>
69: 83 c1 05 add $0x5,%ecx
6c: 81 f9 00 ca 9a 3b cmp $0x3b9aca00,%ecx
72: 75 9c jne 10 <main+0x10>
74: 31 c0 xor %eax,%eax
76: c3 retq
--
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/20170120/cf0a8a0d/attachment.html>
More information about the llvm-bugs
mailing list