Don't issue gather/scatter warnigns in the 'extra' bits of foreach loops.

With AOS data, we can often coalesce the accesses into gathers for the main
part of foreach loops but only fail on the last bits where the mask is not
all on (since the coalescing code doesn't handle mixed masks, yet.) Before,
we'd report success with coalescing and then also report that gathers were needed
for the same accesses that were coalesced, which was a) confusing, and b)
didn't accurately represent what was going on for the majority of the loop
iterations.
This commit is contained in:
Matt Pharr
2012-03-19 15:08:35 -07:00
parent d74cc6397b
commit 7e954e4248
4 changed files with 45 additions and 17 deletions

22
ctx.cpp
View File

@@ -245,6 +245,8 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym,
StoreInst(llvm::Constant::getNullValue(LLVMTypes::VoidPointerType),
launchGroupHandlePtr);
disableGSWarningCount = 0;
const Type *returnType = function->GetReturnType();
if (!returnType || Type::Equal(returnType, AtomicType::Void))
returnValuePtr = NULL;
@@ -1106,6 +1108,19 @@ FunctionEmitContext::InForeachLoop() const {
}
void
FunctionEmitContext::DisableGatherScatterWarnings() {
++disableGSWarningCount;
}
void
FunctionEmitContext::EnableGatherScatterWarnings() {
--disableGSWarningCount;
}
bool
FunctionEmitContext::initLabelBBlocks(ASTNode *node, void *data) {
LabeledStmt *ls = dynamic_cast<LabeledStmt *>(node);
@@ -2492,7 +2507,8 @@ FunctionEmitContext::gather(llvm::Value *ptr, const PointerType *ptrType,
// Add metadata about the source file location so that the
// optimization passes can print useful performance warnings if we
// can't optimize out this gather
addGSMetadata(call, currentPos);
if (disableGSWarningCount == 0)
addGSMetadata(call, currentPos);
return BitCastInst(call, llvmReturnType, "gather_bitcast");
}
@@ -2801,7 +2817,9 @@ FunctionEmitContext::scatter(llvm::Value *value, llvm::Value *ptr,
args.push_back(value);
args.push_back(mask);
llvm::Value *inst = CallInst(scatterFunc, NULL, args);
addGSMetadata(inst, currentPos);
if (disableGSWarningCount == 0)
addGSMetadata(inst, currentPos);
}

11
ctx.h
View File

@@ -230,6 +230,13 @@ public:
bool InForeachLoop() const;
/** Temporarily disables emission of performance warnings from gathers
and scatters from subsequent code. */
void DisableGatherScatterWarnings();
/** Reenables emission of gather/scatter performance warnings. */
void EnableGatherScatterWarnings();
void SetContinueTarget(llvm::BasicBlock *bb) { continueTarget = bb; }
/** Step through the code and find label statements; create a basic
@@ -644,6 +651,10 @@ private:
tasks launched from the current function. */
llvm::Value *launchGroupHandlePtr;
/** Nesting count of the number of times calling code has disabled (and
not yet reenabled) gather/scatter performance warnings. */
int disableGSWarningCount;
std::map<std::string, llvm::BasicBlock *> labelMap;
static bool initLabelBBlocks(ASTNode *node, void *data);

27
opt.cpp
View File

@@ -2382,8 +2382,7 @@ GSToLoadStorePass::runOnBasicBlock(llvm::BasicBlock &bb) {
continue;
SourcePos pos;
bool ok = lGetSourcePosFromMetadata(callInst, &pos);
Assert(ok);
lGetSourcePosFromMetadata(callInst, &pos);
llvm::Value *base = callInst->getArgOperand(0);
llvm::Value *varyingOffsets = callInst->getArgOperand(1);
@@ -2742,8 +2741,7 @@ static void
lCoalescePerfInfo(const std::vector<llvm::CallInst *> &coalesceGroup,
const std::vector<CoalescedLoadOp> &loadOps) {
SourcePos pos;
bool ok = lGetSourcePosFromMetadata(coalesceGroup[0], &pos);
Assert(ok);
lGetSourcePosFromMetadata(coalesceGroup[0], &pos);
// Create a string that indicates the line numbers of the subsequent
// gathers from the first one that were coalesced here.
@@ -2758,12 +2756,13 @@ lCoalescePerfInfo(const std::vector<llvm::CallInst *> &coalesceGroup,
for (int i = 1; i < (int)coalesceGroup.size(); ++i) {
SourcePos p;
bool ok = lGetSourcePosFromMetadata(coalesceGroup[i], &p);
Assert(ok);
char buf[32];
sprintf(buf, "%d", p.first_line);
strcat(otherPositions, buf);
if (i < (int)coalesceGroup.size() - 1)
strcat(otherPositions, ", ");
if (ok) {
char buf[32];
sprintf(buf, "%d", p.first_line);
strcat(otherPositions, buf);
if (i < (int)coalesceGroup.size() - 1)
strcat(otherPositions, ", ");
}
}
strcat(otherPositions, ") ");
}
@@ -3460,8 +3459,7 @@ GatherCoalescePass::runOnBasicBlock(llvm::BasicBlock &bb) {
continue;
SourcePos pos;
bool ok = lGetSourcePosFromMetadata(callInst, &pos);
Assert(ok);
lGetSourcePosFromMetadata(callInst, &pos);
Debug(pos, "Checking for coalescable gathers starting here...");
llvm::Value *base = callInst->getArgOperand(0);
@@ -3680,11 +3678,10 @@ PseudoGSToGSPass::runOnBasicBlock(llvm::BasicBlock &bb) {
// Get the source position from the metadata attached to the call
// instruction so that we can issue PerformanceWarning()s below.
SourcePos pos;
bool ok = lGetSourcePosFromMetadata(callInst, &pos);
Assert(ok);
bool gotPosition = lGetSourcePosFromMetadata(callInst, &pos);
callInst->setCalledFunction(info->actualFunc);
if (g->target.vectorWidth > 1) {
if (gotPosition && g->target.vectorWidth > 1) {
if (info->isGather)
PerformanceWarning(pos, "Gather required to compute value in expression.");
else

View File

@@ -1745,7 +1745,9 @@ ForeachStmt::EmitCode(FunctionEmitContext *ctx) const {
ctx->SetCurrentBasicBlock(bbMaskedBody); {
ctx->AddInstrumentationPoint("foreach loop body (masked)");
ctx->SetContinueTarget(bbMaskedBodyContinue);
ctx->DisableGatherScatterWarnings();
stmts->EmitCode(ctx);
ctx->EnableGatherScatterWarnings();
ctx->BranchInst(bbMaskedBodyContinue);
}
ctx->SetCurrentBasicBlock(bbMaskedBodyContinue); {