Align stack-allocated arrays of uniform types to the target vector alignment (they will often be accessed in programCount-sized chunks and this should make that a bit more efficient in the common case). Fixes issue #15

This commit is contained in:
Matt Pharr
2011-06-28 20:42:18 -07:00
parent 7aec7486f8
commit ce7978ae74

10
ctx.cpp
View File

@@ -1482,6 +1482,16 @@ FunctionEmitContext::AllocaInst(const llvm::Type *llvmType, const char *name,
// current basic block
inst = new llvm::AllocaInst(llvmType, name ? name : "", bblock);
// If no alignment was specified but we have an array of a uniform
// type, then align it to 4 * the native vector width; it's not
// unlikely that this array will be loaded into varying variables with
// what will be aligned accesses if the uniform -> varying load is done
// in regular chunks.
const llvm::ArrayType *arrayType = llvm::dyn_cast<const llvm::ArrayType>(llvmType);
if (align == 0 && arrayType != NULL &&
!llvm::isa<const llvm::VectorType>(arrayType->getElementType()))
align = 4 * g->target.nativeVectorWidth;
if (align != 0)
inst->setAlignment(align);
// Don't add debugging info to alloca instructions