Skip to content

Commit 974f4b7

Browse files
authored
Add runtime activity for fwd mode loads (rust-lang#744)
1 parent 9aff64d commit 974f4b7

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

enzyme/Enzyme/ActivityAnalysis.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,11 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) {
16501650
}
16511651
}
16521652

1653+
if (auto CB = dyn_cast<CallInst>(I)) {
1654+
if (CB->onlyAccessesInaccessibleMemory())
1655+
AARes = ModRefInfo::NoModRef;
1656+
}
1657+
16531658
// TODO this aliasing information is too conservative, the question
16541659
// isn't merely aliasing but whether there is a path for THIS value to
16551660
// eventually be loaded by it not simply because there isnt aliasing

enzyme/Enzyme/AdjointGenerator.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,17 @@ class AdjointGenerator
530530
}
531531
} else {
532532
Value *newip = gutils->invertPointerM(&I, BuilderZ);
533+
if (EnzymeRuntimeActivityCheck && TR.query(&I)[{-1}].isFloat()) {
534+
Value *shadow = BuilderZ.CreateICmpNE(
535+
gutils->getNewFromOriginal(I.getOperand(0)),
536+
gutils->invertPointerM(I.getOperand(0), BuilderZ));
537+
newip = BuilderZ.CreateSelect(
538+
shadow, newip, Constant::getNullValue(newip->getType()));
539+
}
533540
assert(newip->getType() == type);
534541
placeholder->replaceAllUsesWith(newip);
535542
gutils->erase(placeholder);
543+
gutils->invertedPointers.erase(&I);
536544
gutils->invertedPointers.insert(std::make_pair(
537545
(const Value *)&I, InvertedPointerVH(gutils, newip)));
538546
}

0 commit comments

Comments
 (0)