From ce7978ae740fb0630a712488d19537d835cb6af2 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Tue, 28 Jun 2011 20:42:18 -0700 Subject: [PATCH] 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 --- ctx.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ctx.cpp b/ctx.cpp index 12199dcb..90cbe106 100644 --- a/ctx.cpp +++ b/ctx.cpp @@ -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(llvmType); + if (align == 0 && arrayType != NULL && + !llvm::isa(arrayType->getElementType())) + align = 4 * g->target.nativeVectorWidth; + if (align != 0) inst->setAlignment(align); // Don't add debugging info to alloca instructions