Skip to content

Commit f9c41b3

Browse files
Add LULESH-motivated optimization to gradient utils. (rust-lang#204)
* Add LULESH-motivated optimization to gradient utils. * Fix formatting to comply with formatting guidelines. * Update GradientUtils.cpp Co-authored-by: William Moses <[email protected]>
1 parent 306c387 commit f9c41b3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

enzyme/Enzyme/GradientUtils.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,17 @@ Value *GradientUtils::unwrapM(Value *const val, IRBuilder<> &BuilderM,
10041004
unwrap_cache[blocks[i]] = unwrap_cache[oldB];
10051005
lookup_cache[blocks[i]] = lookup_cache[oldB];
10061006

1007-
vals.push_back(getOpFull(B, phi->getIncomingValueForBlock(PB), PB));
1007+
if (auto inst =
1008+
dyn_cast<Instruction>(phi->getIncomingValueForBlock(PB))) {
1009+
if (inst->mayReadFromMemory())
1010+
vals.push_back(getOpFull(B, phi->getIncomingValueForBlock(PB), PB));
1011+
else
1012+
vals.push_back(
1013+
getOpFull(BuilderM, phi->getIncomingValueForBlock(PB), PB));
1014+
} else
1015+
vals.push_back(
1016+
getOpFull(BuilderM, phi->getIncomingValueForBlock(PB), PB));
1017+
10081018
if (!vals[i]) {
10091019
for (size_t j = 0; j < i; i++) {
10101020
reverseBlocks[fwd].erase(std::find(reverseBlocks[fwd].begin(),

0 commit comments

Comments
 (0)