Rob Pieke
2010-Nov-15 15:27 UTC
[LLVMdev] Optimization of calls to functions without side effects (from Kaleidoscope example)
I'm using the gvn pass, not sure about basic-aa. I've copied the code as-is from http://llvm.org/docs/tutorial/LangImpl4.html#code and added "F->addFnAttr( Attribute::ReadOnly )" after "Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule)". The passes it sets up are: // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData())); // Do simple "peephole" optimizations and bit-twiddling optzns. OurFPM.add(createInstructionCombiningPass()); // Reassociate expressions. OurFPM.add(createReassociatePass()); // Eliminate Common SubExpressions. OurFPM.add(createGVNPass()); // Simplify the control flow graph (deleting unreachable blocks, etc). OurFPM.add(createCFGSimplificationPass()); It does simplify _some_ things. For example: ready> def simplifyThis(x) (x*2)+(2*x); Read function definition: define double @simplifyThis(double %x) readonly { entry: %multmp = fmul double %x, 2.000000e+00 %addtmp = fadd double %multmp, %multmp ret double %addtmp }> -----Original Message----- > From: Duncan Sands [mailto:baldrick at free.fr] > Sent: Monday, November 15, 2010 2:57 PM > To: llvmdev at cs.uiuc.edu > Subject: Re: [LLVMdev] Optimization of calls to functions without side > effects (from Kaleidoscope example) > > Hi Rob, > > > Hmm ... I tried setting that right after Function::Create but I still > get the same result (though flagged with "readonly") > > did you run the gvn pass (preceded by basic-aa)? > > Ciao, > > Duncan. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Arnaud Allard de Grandmaison
2010-Nov-15 15:47 UTC
[LLVMdev] Optimization of calls to functions without side effects (from Kaleidoscope example)
Rob, I can reproduce the behaviour you observe using llvm top-of-tree. I will try to look into it. Best regards, -- Arnaud de Grandmaison -----Original Message----- From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Rob Pieke Sent: Monday, November 15, 2010 4:27 PM To: Duncan Sands; llvmdev at cs.uiuc.edu Subject: Re: [LLVMdev] Optimization of calls to functions without side effects (from Kaleidoscope example) I'm using the gvn pass, not sure about basic-aa. I've copied the code as-is from http://llvm.org/docs/tutorial/LangImpl4.html#code and added "F->addFnAttr( Attribute::ReadOnly )" after "Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule)". The passes it sets up are: // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData())); // Do simple "peephole" optimizations and bit-twiddling optzns. OurFPM.add(createInstructionCombiningPass()); // Reassociate expressions. OurFPM.add(createReassociatePass()); // Eliminate Common SubExpressions. OurFPM.add(createGVNPass()); // Simplify the control flow graph (deleting unreachable blocks, etc). OurFPM.add(createCFGSimplificationPass()); It does simplify _some_ things. For example: ready> def simplifyThis(x) (x*2)+(2*x); Read function definition: define double @simplifyThis(double %x) readonly { entry: %multmp = fmul double %x, 2.000000e+00 %addtmp = fadd double %multmp, %multmp ret double %addtmp }> -----Original Message----- > From: Duncan Sands [mailto:baldrick at free.fr] > Sent: Monday, November 15, 2010 2:57 PM > To: llvmdev at cs.uiuc.edu > Subject: Re: [LLVMdev] Optimization of calls to functions without side > effects (from Kaleidoscope example) > > Hi Rob, > > > Hmm ... I tried setting that right after Function::Create but I still > get the same result (though flagged with "readonly") > > did you run the gvn pass (preceded by basic-aa)? > > Ciao, > > Duncan. > _______________________________________________ > 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
Rob Pieke
2010-Nov-15 15:56 UTC
[LLVMdev] Optimization of calls to functions without sideeffects (from Kaleidoscope example)
Thanks! I'm brand-new to LLVM, so it's probably something pretty basic that I haven't learned yet :)> -----Original Message----- > From: Arnaud Allard de Grandmaison > [mailto:Arnaud.AllardDeGrandMaison at dibcom.com] > Sent: Monday, November 15, 2010 3:47 PM > To: Rob Pieke; Duncan Sands; llvmdev at cs.uiuc.edu > Subject: RE: Re: [LLVMdev] Optimization of calls to functions without > sideeffects (from Kaleidoscope example) > > Rob, > > I can reproduce the behaviour you observe using llvm top-of-tree. > > I will try to look into it. > > Best regards, > -- > Arnaud de Grandmaison
Duncan Sands
2010-Nov-15 16:32 UTC
[LLVMdev] Optimization of calls to functions without side effects (from Kaleidoscope example)
Hi Rob,> I'm using the gvn pass, not sure about basic-aa.if you are using LLVM from svn then you need to specify the basic-aa analysis, otherwise gvn won't unify calls to readonly/readnone functions. This is new behaviour introduced by Dan; probably the tutorial should be updated. Ciao, Duncan.> > I've copied the code as-is from http://llvm.org/docs/tutorial/LangImpl4.html#code and added "F->addFnAttr( Attribute::ReadOnly )" after "Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule)". > > The passes it sets up are: > > // Set up the optimizer pipeline. Start with registering info about how the > // target lays out data structures. > OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData())); > // Do simple "peephole" optimizations and bit-twiddling optzns. > OurFPM.add(createInstructionCombiningPass()); > // Reassociate expressions. > OurFPM.add(createReassociatePass()); > // Eliminate Common SubExpressions. > OurFPM.add(createGVNPass()); > // Simplify the control flow graph (deleting unreachable blocks, etc). > OurFPM.add(createCFGSimplificationPass()); > > It does simplify _some_ things. For example: > > ready> def simplifyThis(x) (x*2)+(2*x); > Read function definition: > define double @simplifyThis(double %x) readonly { > entry: > %multmp = fmul double %x, 2.000000e+00 > %addtmp = fadd double %multmp, %multmp > ret double %addtmp > } > > >> -----Original Message----- >> From: Duncan Sands [mailto:baldrick at free.fr] >> Sent: Monday, November 15, 2010 2:57 PM >> To: llvmdev at cs.uiuc.edu >> Subject: Re: [LLVMdev] Optimization of calls to functions without side >> effects (from Kaleidoscope example) >> >> Hi Rob, >> >>> Hmm ... I tried setting that right after Function::Create but I still >> get the same result (though flagged with "readonly") >> >> did you run the gvn pass (preceded by basic-aa)? >> >> Ciao, >> >> Duncan. >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Rob Pieke
2010-Nov-15 16:39 UTC
[LLVMdev] Optimization of calls to functions without side effects (from Kaleidoscope example)
Still no luck after switching to: theFPM->add( new llvm::TargetData( *theExecutionEngine->getTargetData() ) ); theFPM->add( llvm::createBasicAliasAnalysisPass() ); theFPM->add( llvm::createInstructionCombiningPass() ); theFPM->add( llvm::createReassociatePass() ); theFPM->add( llvm::createGVNPass() ); theFPM->add( llvm::createCFGSimplificationPass() ); Based on output from "llvm-ld -version" and "clang -v" I'm using: llvm version 2.9svn clang version 2.9 (trunk 118171)> -----Original Message----- > From: Duncan Sands [mailto:baldrick at free.fr] > Sent: Monday, November 15, 2010 4:32 PM > To: Rob Pieke > Cc: llvmdev at cs.uiuc.edu; Dan Gohman > Subject: Re: [LLVMdev] Optimization of calls to functions without side > effects (from Kaleidoscope example) > > Hi Rob, > > > I'm using the gvn pass, not sure about basic-aa. > > if you are using LLVM from svn then you need to specify the basic-aa > analysis, > otherwise gvn won't unify calls to readonly/readnone functions. This > is new > behaviour introduced by Dan; probably the tutorial should be updated. > > Ciao, > > Duncan.
Rob Pieke
2010-Nov-15 16:42 UTC
[LLVMdev] Optimization of calls to functions without side effects (from Kaleidoscope example)
SUCCESS! Sorry, I had removed the addFnAttr() call by accident. Using the basicAA pass and ReadOnly, as you suggested, works like a charm! :)> -----Original Message----- > From: Rob Pieke > Sent: Monday, November 15, 2010 4:40 PM > To: 'Duncan Sands' > Cc: 'llvmdev at cs.uiuc.edu'; 'Dan Gohman' > Subject: RE: [LLVMdev] Optimization of calls to functions without side > effects (from Kaleidoscope example) > > Still no luck after switching to: > > theFPM->add( new llvm::TargetData( *theExecutionEngine- > >getTargetData() ) ); > theFPM->add( llvm::createBasicAliasAnalysisPass() ); > theFPM->add( llvm::createInstructionCombiningPass() ); > theFPM->add( llvm::createReassociatePass() ); > theFPM->add( llvm::createGVNPass() ); > theFPM->add( llvm::createCFGSimplificationPass() ); > > Based on output from "llvm-ld -version" and "clang -v" I'm using: > > llvm version 2.9svn > clang version 2.9 (trunk 118171) > > > > > -----Original Message----- > > From: Duncan Sands [mailto:baldrick at free.fr] > > Sent: Monday, November 15, 2010 4:32 PM > > To: Rob Pieke > > Cc: llvmdev at cs.uiuc.edu; Dan Gohman > > Subject: Re: [LLVMdev] Optimization of calls to functions without > side > > effects (from Kaleidoscope example) > > > > Hi Rob, > > > > > I'm using the gvn pass, not sure about basic-aa. > > > > if you are using LLVM from svn then you need to specify the basic-aa > > analysis, > > otherwise gvn won't unify calls to readonly/readnone functions. This > > is new > > behaviour introduced by Dan; probably the tutorial should be updated. > > > > Ciao, > > > > Duncan.
Dan Gohman
2010-Nov-15 18:45 UTC
[LLVMdev] Optimization of calls to functions without side effects (from Kaleidoscope example)
On Nov 15, 2010, at 8:42 AM, Rob Pieke wrote:> SUCCESS! > > Sorry, I had removed the addFnAttr() call by accident. Using the basicAA pass and ReadOnly, as you suggested, works like a charm! > > :)Thanks. I've updated the documentation and examples in r119169. I didn't update the OCaml documentation or examples yet. It looks like the OCaml bindings don't expose basicaa yet, though it should be easy to add for someone familiar with the bindings. Dan
Apparently Analagous Threads
- [LLVMdev] Optimization of calls to functions without side effects (from Kaleidoscope example)
- [LLVMdev] Optimization of calls to functions without side effects (from Kaleidoscope example)
- [LLVMdev] Optimization of calls to functions without side effects (from Kaleidoscope example)
- [LLVMdev] Optimization of calls to functions without side effects (from Kaleidoscope example)
- [LLVMdev] Optimization of calls to functions without side effects (from Kaleidoscope example)