[llvm-dev] Why LLVM cannot optimize this?

zet via llvm-dev llvm-dev at lists.llvm.org
Tue Mar 1 23:24:10 PST 2016


test.c :
-----------------------------------------------------------------------
int foo(int a)
{
  int zero = 0;
  for (int i = 0; i < 10000; i++)
    zero *= a;
  return zero;
}
-------------------------------------------------------------------------

run clang : clang -O2 -S test.c -o test.s

My clang version is 3.7.1.
We will get a horrible assembly output.

Why constant propagation and other optimization skills can not find out
that variable zero is initialized 0, and the only statement in for loop
(i.e. zero *= a) always get a 0?

I can read the clang/llvm source, Please tell me more details.

THX


-- 
业精于勤,荒于嬉..
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160302/f15da086/attachment.html>


More information about the llvm-dev mailing list