Rob Pieke
2010-Nov-15 13:39 UTC
[LLVMdev] Optimization of calls to functions without side effects (from Kaleidoscope example)
> You need to set attribute ReadOnly on the sin / cos functions, using > Function::addFnAttr(Attribute) for example.Hmm ... I tried setting that right after Function::Create but I still get the same result (though flagged with "readonly") declare double @sin(double) readonly declare double @cos(double) readonly define double @foo(double %x) readonly { entry: %calltmp = call double @sin(double %x) %calltmp1 = call double @sin(double %x) %multmp = fmul double %calltmp, %calltmp1 %calltmp2 = call double @cos(double %x) %calltmp3 = call double @cos(double %x) %multmp4 = fmul double %calltmp2, %calltmp3 %addtmp = fadd double %multmp, %multmp4 ret double %addtmp }
Duncan Sands
2010-Nov-15 14:56 UTC
[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.
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
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] Question on JIT optimizations
- [LLVMdev] Optimization of calls to functions without side effects (from Kaleidoscope example)