[llvm-dev] Why LLVM cannot optimize this?
Hongbin Zheng via llvm-dev
llvm-dev at lists.llvm.org
Tue Mar 1 23:31:51 PST 2016
if you replace "zero *= a;" by "zero += a;", you get:
; Function Attrs: norecurse nounwind readnone uwtable
define i32 @foo(i32 %a) #0 {
entry:
%0 = mul i32 %a, 10000
ret i32 %0
}
I think the problem is ScalarEvolution only have "SCEVAddRecExpr" for zero
+= a, but no corresponding expression to represent and optimize zero *= a;
On Wed, Mar 2, 2016 at 3:24 PM, zet via llvm-dev <llvm-dev at lists.llvm.org>
wrote:
> 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
>
>
> --
> 业精于勤,荒于嬉..
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160302/606c2416/attachment.html>
More information about the llvm-dev
mailing list