On 01/08/2010 02:10 PM, John McCall wrote:> 'llc' is an IR-to-assembly compiler; at -O3 it does some pretty neat > machine-code and object-file optimizations, but it does not apply > high-level optimizations like CSE or inlining. 'opt' is the tool > which does IR-to-IR optimization.A vital clue, but I'm still not getting it: --- gemini:~/Projects/Nil/nil(0)$ make testInline.optdis.ll llvm-as testInline.ll opt -always-inline testInline.bc -o testInline.optbc llvm-dis -f testInline.optbc -o testInline.optdis.ll rm testInline.bc testInline.optbc gemini:~/Projects/Nil/nil(0)$ cat testInline.optdis.ll ; ModuleID = 'testInline.optbc' define linkonce fastcc i32 @foo(i32 %arg) alwaysinline { %result = mul i32 %arg, 7 ; <i32> [#uses=1] ret i32 %result } define i32 @main(i32 %argc, i8** %argv) { %retVal = call fastcc i32 @foo(i32 6) alwaysinline ; <i32> [#uses=1] ret i32 %retVal } gemini:~/Projects/Nil/nil(0)$ --- Perhaps the -always-inline pass has a prerequisite pass? I also tried it with "-O3 -always-inline", which got halfway there: --- ; ModuleID = 'testInline.optbc' define linkonce fastcc i32 @foo(i32 %arg) alwaysinline { %result = mul i32 %arg, 7 ; <i32> [#uses=1] ret i32 %result } define i32 @main(i32 %argc, i8** nocapture %argv) { %retVal = tail call fastcc i32 @foo(i32 6) alwaysinline ; <i32> [#uses=1] ret i32 %retVal } --- I'm pleased to get the tailcall optimization, but in this case was looking for the 'no call at all' optimization. :-) Dustin
On Jan 8, 2010, at 3:08 PM, Dustin Laurence wrote:> On 01/08/2010 02:10 PM, John McCall wrote: > >> 'llc' is an IR-to-assembly compiler; at -O3 it does some pretty neat >> machine-code and object-file optimizations, but it does not apply >> high-level optimizations like CSE or inlining. 'opt' is the tool >> which does IR-to-IR optimization. > > A vital clue, but I'm still not getting it:Try opt -O3. -Chris
Dustin Laurence wrote:> On 01/08/2010 02:10 PM, John McCall wrote: > > >> 'llc' is an IR-to-assembly compiler; at -O3 it does some pretty neat >> machine-code and object-file optimizations, but it does not apply >> high-level optimizations like CSE or inlining. 'opt' is the tool >> which does IR-to-IR optimization. >> > > A vital clue, but I'm still not getting it: > > --- > gemini:~/Projects/Nil/nil(0)$ make testInline.optdis.ll > llvm-as testInline.ll > opt -always-inline testInline.bc -o testInline.optbc > llvm-dis -f testInline.optbc -o testInline.optdis.ll > rm testInline.bc testInline.optbc > gemini:~/Projects/Nil/nil(0)$ cat testInline.optdis.ll > ; ModuleID = 'testInline.optbc' > > define linkonce fastcc i32 @foo(i32 %arg) alwaysinline { >Try using 'internal' linkage instead of 'linkonce'. If you're sure you really want linkonce then you'd need to use linkonce_odr to get inlining here. Also, drop the alwaysinline attribute and '-always-inline' flag. The normal inliner (aka. "opt -inline" which is run as part of "opt -O3") should inline it. Nick> %result = mul i32 %arg, 7 ; <i32> [#uses=1] > ret i32 %result > } > > define i32 @main(i32 %argc, i8** %argv) { > %retVal = call fastcc i32 @foo(i32 6) alwaysinline ; <i32> [#uses=1] > ret i32 %retVal > } > gemini:~/Projects/Nil/nil(0)$ > --- > > Perhaps the -always-inline pass has a prerequisite pass? I also tried > it with "-O3 -always-inline", which got halfway there: > > --- > ; ModuleID = 'testInline.optbc' > > define linkonce fastcc i32 @foo(i32 %arg) alwaysinline { > %result = mul i32 %arg, 7 ; <i32> [#uses=1] > ret i32 %result > } > > define i32 @main(i32 %argc, i8** nocapture %argv) { > %retVal = tail call fastcc i32 @foo(i32 6) alwaysinline ; <i32> [#uses=1] > ret i32 %retVal > } > --- > > I'm pleased to get the tailcall optimization, but in this case was > looking for the 'no call at all' optimization. :-) > > Dustin > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
On 01/08/2010 04:36 PM, Chris Lattner wrote:> > On Jan 8, 2010, at 3:08 PM, Dustin Laurence wrote:>> A vital clue, but I'm still not getting it: > > Try opt -O3.I actually had, but as Nick Lewycky noticed the 'linkonce' linkage specification was preventing the inlining. Dustin
On 01/08/2010 09:17 PM, Nick Lewycky wrote:> Try using 'internal' linkage instead of 'linkonce'.That did it, thanks. --- gemini:~/Projects/LLVM/Tests/Inline(0)$ cat testInline.optdis.ll ; ModuleID = 'testInline.optbc' define i32 @main(i32 %argc, i8** nocapture %argv) nounwind readnone { ret i32 42 } gemini:~/Projects/LLVM/Tests/Inline(0)$ ---> If you're sure you > really want linkonce then you'd need to use linkonce_odr to get inlining > here.I'm sure of nothing. I only used it because the IR Reference says linkonce: Globals with "linkonce" linkage are merged with other globals of the same name when linkage occurs. This is typically used to implement inline functions, templates, or other code which must be generated in each translation unit that uses it. Unreferenced linkonce globals are allowed to be discarded. So I thought it was telling me to use linkonce for inline functions.+ A bit more experimentation shows that it still inlines with the default linkage, the only difference being it retains a non-inlined version as well. With 'internal' it omits the non-inlined version. I think I see why that's true.> Also, drop the alwaysinline attribute and '-always-inline' flag. The > normal inliner (aka. "opt -inline" which is run as part of "opt -O3") > should inline it.Yes, it still did after I removed them. Since I'm clearly not guessing well here, when would one want to use "alwaysinline"? Dustin