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:
6
stmt.cpp
6
stmt.cpp
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user