[LLVMdev] Get Different Result for ScalarEvolution through ModulePass and FunctionPass

CC Y yechencheng at gmail.com
Wed Oct 30 21:22:11 PDT 2013


Hi there,

I write two pass, a module pass, named "MP", and a FunctionPass, "FP".
Then I use this pass to print the scalar evolution information in two ways:
1.employ FP to process function directly
2.call MP, iterate on functions, then call FP on them

sample code is that:
*MP:*
*bool runOnModule(Module &M)*
*{*

*for(Module::iterator itr = M.begin(); itr != M.end(); itr++)*

*{*

*    FP &t = getAnalysis< FP >(*itr);*

*    (t.SE)->print(errs());         // SE represent for scalar evolution
pass.*
*}*

*}*

*FP:*
*bool runOnFunction(Function &F)*
*{*

*SE = &getAnalysis<ScalarEvolution>();*
*SE->print(errs());*

*}*

But when processing 'getelementptr' instruction, these two ways return
different result.

*MP:*

*  %lsr.iv1 = getelementptr inbounds [1024 x i32]* %lsr.iv, i64 0, i64 0*

*  -->  {@A,+,sizeof(i32)}<%8> Exits: (((zext i32 (0 smax %N) to i64) *
sizeof(i32)) + @A)*


*FP:*

*%lsr.iv1 = getelementptr inbounds [1024 x i32]* %lsr.iv, i64 0, i64 0*

*  -->  {@A,+,4}<%8> Exits: ((4 * (zext i32 (0 smax %N) to i64)) + @A)*


*Then the problem comes:*

In MP, sizeof(i32) seems to be treated as a variable, not a constant. On
the other hand, the constant 4 for sizeof(i32) in FP seems more friendly.

What can I do if I want to translate sizeof(i32) to 4?

Any reply is appreciated.


Regards.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131031/e34dbd0b/attachment.html>


More information about the llvm-dev mailing list