[LLVMdev] Optimization of calls to functions without side effects (from Kaleidoscope example)

Rob Pieke rob-p at moving-picture.com
Mon Nov 15 07:27:17 PST 2010


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




More information about the llvm-dev mailing list