From d36ab4cc3c3cc66ca9511cc37dfbb320ce260031 Mon Sep 17 00:00:00 2001 From: Dmitry Babokin Date: Thu, 25 Apr 2013 20:39:01 +0400 Subject: [PATCH] Adding noalias attribute to malloc return --- builtins/util.m4 | 10 +++++----- ctx.cpp | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/builtins/util.m4 b/builtins/util.m4 index 765b5587..87a1fd68 100644 --- a/builtins/util.m4 +++ b/builtins/util.m4 @@ -2536,11 +2536,11 @@ ok: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; new/delete -declare i8 * @malloc(i64) +declare noalias i8 * @malloc(i64) declare void @free(i8 *) -define i8 * @__new_uniform(i64 %size) { - %a = call i8 * @malloc(i64 %size) +define noalias i8 * @__new_uniform(i64 %size) { + %a = call noalias i8 * @malloc(i64 %size) ret i8 * %a } @@ -2552,7 +2552,7 @@ define @__new_varying32( %size, %mask) per_lane(WIDTH, %mask, ` %sz_LANE_ID = extractelement %size, i32 LANE %sz64_LANE_ID = zext i32 %sz_LANE_ID to i64 - %ptr_LANE_ID = call i8 * @malloc(i64 %sz64_LANE_ID) + %ptr_LANE_ID = call noalias i8 * @malloc(i64 %sz64_LANE_ID) %ptr_int_LANE_ID = ptrtoint i8 * %ptr_LANE_ID to i64 %store_LANE_ID = getelementptr i64 * %ret64, i32 LANE store i64 %ptr_int_LANE_ID, i64 * %store_LANE_ID') @@ -2568,7 +2568,7 @@ define @__new_varying64( %size, %mask) per_lane(WIDTH, %mask, ` %sz_LANE_ID = extractelement %size, i32 LANE - %ptr_LANE_ID = call i8 * @malloc(i64 %sz_LANE_ID) + %ptr_LANE_ID = call noalias i8 * @malloc(i64 %sz_LANE_ID) %ptr_int_LANE_ID = ptrtoint i8 * %ptr_LANE_ID to i64 %store_LANE_ID = getelementptr i64 * %ret64, i32 LANE store i64 %ptr_int_LANE_ID, i64 * %store_LANE_ID') diff --git a/ctx.cpp b/ctx.cpp index 11e25492..4d207ee2 100644 --- a/ctx.cpp +++ b/ctx.cpp @@ -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(ci); + if (cc && + cc->getCalledFunction() && + cc->getCalledFunction()->doesNotAlias(0)) { + cc->addAttribute(0, llvm::Attribute::NoAlias); + } +#endif + AddDebugPos(ci); return ci; }