[llvm-dev] How can I make llvm intrinsic functions declarations survive from optimizations.

Zhengyang Liu via llvm-dev llvm-dev at lists.llvm.org
Wed Jun 22 23:46:05 PDT 2016

Dear LLVM community.

I have a function pass. This pass will insert a llvm intrinsic function 
prototype (llvm.memset.p0i8.i32) to the module at the doInitialize 
stage. Then at runOnFunction Stage, this pass will find the insert 
points and insert calls of this intrinsic function. However, when the 
-O2 flag is turned on, the strip unused function optimization will 
automatically delete this intrinsic function because there's no use of 
this function found. (Strip unused function happens before runOnFunction 
of my pass).

I used to solve this kind of problems on non-intrinsic functions by 
inserting a record to llvm.compiler.used. However, after I append this 
intrinsic function to llvm.compiler.used global, I got a fatal error

Invalid user of intrinsic instruction!
i8* bitcast (void (i8*, i8, i32, i32, i1)* @llvm.memset.p0i8.i32 to i8*)
fatal error: error in backend: Broken module found, compilation aborted!

I noticed that, only user of direct call/invokes are allowed for 
intrinsic functions. So is it impossible to solve this problem by 
inserting intrinsic function prototype?

Could you please give me some ideas on this , to make these intrinsic 
functions prototypes survive from llvm optimizations?

Thank you.

Best regards,

More information about the llvm-dev mailing list