Adding noalias attribute to malloc return

This commit is contained in:
Dmitry Babokin
2013-04-25 20:39:01 +04:00
parent 65ac336211
commit d36ab4cc3c
2 changed files with 19 additions and 5 deletions

14
ctx.cpp
View File

@@ -3285,6 +3285,20 @@ FunctionEmitContext::CallInst(llvm::Value *func, const FunctionType *funcType,
// pointer, so just emit the IR directly.
llvm::Instruction *ci =
llvm::CallInst::Create(func, argVals, name ? name : "", bblock);
// Copy noalias attribute to call instruction, to enable better
// alias analysis.
// TODO: what other attributes needs to be copied?
// TODO: do the same for varing path.
#if defined (LLVM_3_3)
llvm::CallInst *cc = llvm::dyn_cast<llvm::CallInst>(ci);
if (cc &&
cc->getCalledFunction() &&
cc->getCalledFunction()->doesNotAlias(0)) {
cc->addAttribute(0, llvm::Attribute::NoAlias);
}
#endif
AddDebugPos(ci);
return ci;
}