Syoyo Fujita
2009-Jan-08 12:36 UTC
[LLVMdev] Loop elimination with floating point counter.
Hi LLVM-ers, I'd like to eliminate dead loop with floating point counter using LLVM, but the following loop wasn't optimized by opt. void func() { float i; for (i = 0.0f; i < 1000.0f; i += 1.2f) { } } $ clang -emit-llvm-bc floop.c $ opt -std-compile-opts floop.bc | llvm-dis define void @func(...) nounwind { entry: br label %forinc forinc: ; preds = %forinc, %entry %i.0.reg2mem.0 = phi float [ 0.000000e+00, %entry ], [ %add, %forinc ] ; <float> [#uses=1] %add = add float %i.0.reg2mem.0, 0x3FF3333340000000 ; <float> [#uses=2] %cmp = fcmp olt float %add, 1.000000e+03 ; <i1> [#uses=1] br i1 %cmp, label %forinc, label %afterfor afterfor: ; preds = %forinc ret void } What I expected is just one instruction "ret void" in function "func". Should I specify some specific optimizer pass for opt? If so, what is the right optimization pass to specify for opt to remove dead loop with floating point counter? I've tested some loop optimization pass, e.g. -licm, -loop-deletion, but nothing takes effect. FYI, gcc -O3 also can't optimize such a loop, but icc -O3 can. LLVM and clang used are recent version from svn. Thanks in advance. -- Syoyo
Devang Patel
2009-Jan-08 15:42 UTC
[LLVMdev] Loop elimination with floating point counter.
On Jan 8, 2009, at 4:36 AM, Syoyo Fujita wrote:> Hi LLVM-ers, > > I'd like to eliminate dead loop with floating point counter using > LLVM, but the following loop wasn't optimized by opt. > > void > func() { > float i; > for (i = 0.0f; i < 1000.0f; i += 1.2f) { > } > }FWIW, LLVM optimizer can eliminate this loop if i is incremented by 1.0f Pl. file a bugzilla report. Thanks, - Devang> > > $ clang -emit-llvm-bc floop.c > $ opt -std-compile-opts floop.bc | llvm-dis > > define void @func(...) nounwind { > entry: > br label %forinc > > forinc: ; preds = %forinc, %entry > %i.0.reg2mem.0 = phi float [ 0.000000e+00, %entry ], [ %add, %forinc > ] ; <float> [#uses=1] > %add = add float %i.0.reg2mem.0, 0x3FF3333340000000 ; <float> > [#uses=2] > %cmp = fcmp olt float %add, 1.000000e+03 ; <i1> [#uses=1] > br i1 %cmp, label %forinc, label %afterfor > > afterfor: ; preds = %forinc > ret void > } > > What I expected is just one instruction "ret void" in function "func". > > Should I specify some specific optimizer pass for opt? > If so, what is the right optimization pass to specify for opt to > remove dead loop with floating point counter? > > I've tested some loop optimization pass, e.g. -licm, -loop-deletion, > but nothing takes effect. > > FYI, gcc -O3 also can't optimize such a loop, but icc -O3 can. > > LLVM and clang used are recent version from svn. > > Thanks in advance. > > -- > Syoyo > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Syoyo Fujita
2009-Jan-08 17:22 UTC
[LLVMdev] Loop elimination with floating point counter.
Hi Devang, Thanks. Yes, in the case variable i incremented by 1.0f is optimized. I don't know why... Anyway, I've filed this problem into bugzilla(Bug 3299) -- Syoyo On Fri, Jan 9, 2009 at 12:42 AM, Devang Patel <dpatel at apple.com> wrote:> > On Jan 8, 2009, at 4:36 AM, Syoyo Fujita wrote: > >> Hi LLVM-ers, >> >> I'd like to eliminate dead loop with floating point counter using >> LLVM, but the following loop wasn't optimized by opt. >> >> void >> func() { >> float i; >> for (i = 0.0f; i < 1000.0f; i += 1.2f) { >> } >> } > > FWIW, LLVM optimizer can eliminate this loop if i is incremented by 1.0f > > Pl. file a bugzilla report. > Thanks, > - > Devang >> >> >> $ clang -emit-llvm-bc floop.c >> $ opt -std-compile-opts floop.bc | llvm-dis >> >> define void @func(...) nounwind { >> entry: >> br label %forinc >> >> forinc: ; preds = %forinc, %entry >> %i.0.reg2mem.0 = phi float [ 0.000000e+00, %entry ], [ %add, %forinc >> ] ; <float> [#uses=1] >> %add = add float %i.0.reg2mem.0, 0x3FF3333340000000 ; <float> >> [#uses=2] >> %cmp = fcmp olt float %add, 1.000000e+03 ; <i1> [#uses=1] >> br i1 %cmp, label %forinc, label %afterfor >> >> afterfor: ; preds = %forinc >> ret void >> } >> >> What I expected is just one instruction "ret void" in function "func". >> >> Should I specify some specific optimizer pass for opt? >> If so, what is the right optimization pass to specify for opt to >> remove dead loop with floating point counter? >> >> I've tested some loop optimization pass, e.g. -licm, -loop-deletion, >> but nothing takes effect. >> >> FYI, gcc -O3 also can't optimize such a loop, but icc -O3 can. >> >> LLVM and clang used are recent version from svn. >> >> Thanks in advance. >> >> -- >> Syoyo >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Maybe Matching Threads
- [LLVMdev] Loop elimination with floating point counter.
- [LLVMdev] Loop elimination with floating point counter.
- [LLVMdev] Loop elimination with floating point counter.
- [LLVMdev] Loop elimination with floating point counter.
- [LLVMdev] Loop elimination with floating point counter.