diff --git a/examples/aobench/ao.ispc b/examples/aobench/ao.ispc index 589a98b1..ffd85d29 100644 --- a/examples/aobench/ao.ispc +++ b/examples/aobench/ao.ispc @@ -82,7 +82,7 @@ static inline void vnormalize(vec &v) { } -static inline void +static void ray_plane_intersect(Isect &isect, Ray &ray, Plane &plane) { float d = -dot(plane.p, plane.n); float v = dot(ray.dir, plane.n); @@ -147,7 +147,7 @@ orthoBasis(vec basis[3], vec n) { } -static inline float +static float ambient_occlusion(Isect &isect, Plane &plane, Sphere spheres[3], RNGState &rngstate) { float eps = 0.0001f; diff --git a/opt.cpp b/opt.cpp index ebd6b8e0..b1f5c7a0 100644 --- a/opt.cpp +++ b/opt.cpp @@ -1674,18 +1674,32 @@ llvm::RegisterPass lms("masked-store-lower", comes from an AllocaInst. */ static bool -lIsStackVariablePointer(llvm::Value *lvalue) { +lIsSafeToBlend(llvm::Value *lvalue) { llvm::BitCastInst *bc = llvm::dyn_cast(lvalue); - if (bc) - return lIsStackVariablePointer(bc->getOperand(0)); + if (bc != NULL) + return lIsSafeToBlend(bc->getOperand(0)); else { llvm::AllocaInst *ai = llvm::dyn_cast(lvalue); - if (ai) - return true; + if (ai) { + LLVM_TYPE_CONST llvm::Type *type = ai->getType(); + LLVM_TYPE_CONST llvm::PointerType *pt = + llvm::dyn_cast(type); + assert(pt != NULL); + type = pt->getElementType(); + LLVM_TYPE_CONST llvm::ArrayType *at; + while ((at = llvm::dyn_cast(type))) { + type = at->getElementType(); + } + LLVM_TYPE_CONST llvm::VectorType *vt = + llvm::dyn_cast(type); + return (vt != NULL && + (int)vt->getNumElements() == g->target.vectorWidth); + } else { - llvm::GetElementPtrInst *gep = llvm::dyn_cast(lvalue); - if (gep) - return lIsStackVariablePointer(gep->getOperand(0)); + llvm::GetElementPtrInst *gep = + llvm::dyn_cast(lvalue); + if (gep != NULL) + return lIsSafeToBlend(gep->getOperand(0)); else return false; } @@ -1747,8 +1761,8 @@ LowerMaskedStorePass::runOnBasicBlock(llvm::BasicBlock &bb) { // or serializing the masked store. Even on targets with a native // masked store instruction, this is preferable since it lets us // keep values in registers rather than going out to the stack. - bool doBlend = (!g->opt.disableBlendedMaskedStores || - lIsStackVariablePointer(lvalue)); + bool doBlend = (!g->opt.disableBlendedMaskedStores && + lIsSafeToBlend(lvalue)); // Generate the call to the appropriate masked store function and // replace the __pseudo_* one with it.