Fix significant bug in mask management in code generated for 'foreach'.

In particular, we 1. weren't setting the function mask to 'all on', such that
any mixed function mask would in turn apply inside the foreach loop, and 2.
weren't always setting the internal mask to 'all on' before doing any additional
masking based on the iteration variables.
This commit is contained in:
Matt Pharr
2012-03-19 15:06:35 -07:00
parent 777343331e
commit d74cc6397b
3 changed files with 52 additions and 0 deletions

View File

@@ -1336,10 +1336,14 @@ ForeachStmt::EmitCode(FunctionEmitContext *ctx) const {
llvm::BasicBlock *bbExit = ctx->CreateBasicBlock("foreach_exit");
llvm::Value *oldMask = ctx->GetInternalMask();
llvm::Value *oldFunctionMask = ctx->GetFunctionMask();
ctx->SetDebugPos(pos);
ctx->StartScope();
ctx->SetInternalMask(LLVMMaskAllOn);
ctx->SetFunctionMask(LLVMMaskAllOn);
// This should be caught during typechecking
Assert(startExprs.size() == dimVariables.size() &&
endExprs.size() == dimVariables.size());
@@ -1765,7 +1769,9 @@ ForeachStmt::EmitCode(FunctionEmitContext *ctx) const {
///////////////////////////////////////////////////////////////////////////
// foreach_exit: All done. Restore the old mask and clean up
ctx->SetCurrentBasicBlock(bbExit);
ctx->SetInternalMask(oldMask);
ctx->SetFunctionMask(oldFunctionMask);
ctx->EndForeach();
ctx->EndScope();