<div>What optimization level are you using? </div><div>-O0 is not interesting, and at -O1 the optimizer nukes all the code</div><div><br></div>In your example, the stack variable and the stack accesses are optimized away: <div>
<br></div><div>% ./build/Release+Asserts/bin/clang -O1 -S -emit-llvm -o - stack.c</div><div><div><div>define void @canary() nounwind uwtable readnone {</div><div>entry:</div><div> ret void</div><div>}</div><div><br></div>
<div>define i32 @main() nounwind uwtable readnone {</div><div>for.end:</div><div> ret i32 0</div><div>}</div></div></div><div><br></div><div>You need to prepare a more optimizer-resistant benchmark. </div><div><br></div>
<div>--kcc </div><div><br><br><div class="gmail_quote">On Fri, Mar 9, 2012 at 2:52 AM, Job Noorman <span dir="ltr"><<a href="mailto:jobnoorman@gmail.com">jobnoorman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I have a question about the performance of the implementation of the stack<br>
protector in LLVM.<br>
<br>
Consider the following C program:<br>
=====<br>
void canary()<br>
{<br>
char buf[20];<br>
buf[0]++;<br>
}<br>
<br>
int main()<br>
{<br>
int i;<br>
for (i = 0; i < 1000000000; ++i)<br>
canary();<br>
return 0;<br>
}<br>
=====<br>
<br>
This should definately run slower when stack protection is enabled, right?<br>
<br>
I have measured the runtime of this program on two different systems compiled<br>
with GCC and LLVM. Here are the results (percentages are the difference with<br>
the unprotected version of the program):<br>
<br>
| Desktop | Laptop |<br>
-----+---------+--------+<br>
GCC | +13% | +277% |<br>
LLVM | -3%(!) | +330% |<br>
<br>
(These measurements are the median values of 10 runs.)<br>
<br>
So the obvious question is: can anybody explain how it is possible that using<br>
the stack protector causes the program to run 3% faster on my desktop?<br>
<br>
I have tried profiling the program using valgrind (cachegrind & callgrind) but<br>
the results show absolutely no reason at all for these measurements.<br>
<br>
I have attached an archive with the source code and compiled binaries.<br>
<br>
Here are the specs of the two systems:<br>
* Desktop<br>
- Ubuntu 11.10<br>
- Linux 3.0.0-16-generic-pae<br>
- Intel(R) Core(TM)2 Duo CPU E4500 @ 2.20GHz (2048K cache)<br>
* Laptop<br>
- Ubuntu 11.10<br>
- Linux 3.0.0-16-generic<br>
- Intel(R) Atom(TM) CPU N450 @ 1.66GHz (512K cache)<br>
<br>
Kind regards,<br>
Job<br>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>