Commit 1be8870b by Olli Etuaho

Avoid precision emulation overhead on unused values

Avoid rounding intermediate values when the intermediate value is not consumed. For example, this avoids rounding the return value of assignment, so "b = a;" becomes "b = frm(a);" instead of "frm(b = frm(a))". BUG=angle:874 TEST=compiler_tests Change-Id: Ifcdb53fb1d07a2cf24e429cc237c2d0262dc32f8 Reviewed-on: https://chromium-review.googlesource.com/241852Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent c51113d0
...@@ -228,6 +228,28 @@ TIntermAggregate *createCompoundAssignmentFunctionCallNode(TIntermTyped *left, T ...@@ -228,6 +228,28 @@ TIntermAggregate *createCompoundAssignmentFunctionCallNode(TIntermTyped *left, T
return callNode; return callNode;
} }
bool parentUsesResult(TIntermNode* parent, TIntermNode* node)
{
if (!parent)
{
return false;
}
TIntermAggregate *aggParent = parent->getAsAggregate();
// If the parent's op is EOpSequence, the result is not assigned anywhere,
// so rounding it is not needed. In particular, this can avoid a lot of
// unnecessary rounding of unused return values of assignment.
if (aggParent && aggParent->getOp() == EOpSequence)
{
return false;
}
if (aggParent && aggParent->getOp() == EOpComma && (aggParent->getSequence()->back() != node))
{
return false;
}
return true;
}
} // namespace anonymous } // namespace anonymous
EmulatePrecision::EmulatePrecision() EmulatePrecision::EmulatePrecision()
...@@ -293,6 +315,10 @@ bool EmulatePrecision::visitBinary(Visit visit, TIntermBinary *node) ...@@ -293,6 +315,10 @@ bool EmulatePrecision::visitBinary(Visit visit, TIntermBinary *node)
case EOpMatrixTimesMatrix: case EOpMatrixTimesMatrix:
{ {
TIntermNode *parent = getParentNode(); TIntermNode *parent = getParentNode();
if (!parentUsesResult(parent, node))
{
break;
}
TIntermNode *replacement = createRoundingFunctionCallNode(node); TIntermNode *replacement = createRoundingFunctionCallNode(node);
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, true)); mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, true));
break; break;
...@@ -395,8 +421,11 @@ bool EmulatePrecision::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -395,8 +421,11 @@ bool EmulatePrecision::visitAggregate(Visit visit, TIntermAggregate *node)
bool inFunctionMap = (mFunctionMap.find(node->getName()) != mFunctionMap.end()); bool inFunctionMap = (mFunctionMap.find(node->getName()) != mFunctionMap.end());
if (visit == PreVisit) if (visit == PreVisit)
{ {
if (canRoundFloat(node->getType()) && !inFunctionMap) { // User-defined function return values are not rounded, this relies on that
TIntermNode *parent = getParentNode(); // calculations producing the value were rounded.
TIntermNode *parent = getParentNode();
if (canRoundFloat(node->getType()) && !inFunctionMap && parentUsesResult(parent, node))
{
TIntermNode *replacement = createRoundingFunctionCallNode(node); TIntermNode *replacement = createRoundingFunctionCallNode(node);
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, true)); mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, true));
} }
...@@ -437,9 +466,9 @@ bool EmulatePrecision::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -437,9 +466,9 @@ bool EmulatePrecision::visitAggregate(Visit visit, TIntermAggregate *node)
break; break;
} }
default: default:
if (canRoundFloat(node->getType()) && visit == PreVisit) TIntermNode *parent = getParentNode();
if (canRoundFloat(node->getType()) && visit == PreVisit && parentUsesResult(parent, node))
{ {
TIntermNode *parent = getParentNode();
TIntermNode *replacement = createRoundingFunctionCallNode(node); TIntermNode *replacement = createRoundingFunctionCallNode(node);
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, true)); mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, true));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment