Skip to content

Commit a7e5456

Browse files
committed
Enzyme fix for scev usage
1 parent 375a641 commit a7e5456

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

enzyme/Enzyme/GradientUtils.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8552,15 +8552,22 @@ bool GradientUtils::getContext(llvm::BasicBlock *BB, LoopContext &lc) {
85528552
void GradientUtils::forceAugmentedReturns() {
85538553
assert(TR.getFunction() == oldFunc);
85548554

8555-
for (BasicBlock &oBB : *oldFunc) {
8556-
// Don't create derivatives for code that results in termination
8557-
if (notForAnalysis.find(&oBB) != notForAnalysis.end())
8555+
// Pass 1: create BB-level contexts for the whole loop/function
8556+
for (BasicBlock &oBBRef : *oldFunc) {
8557+
BasicBlock *oBB = &oBBRef;
8558+
if (notForAnalysis.find(oBB) != notForAnalysis.end())
85588559
continue;
8560+
LoopContext LC;
8561+
getContext(cast<BasicBlock>(getNewFromOriginal(oBB)), LC);
8562+
}
85598563

8560-
LoopContext loopContext;
8561-
getContext(cast<BasicBlock>(getNewFromOriginal(&oBB)), loopContext);
8564+
// Pass 2: instruction processing (unchanged semantics)
8565+
for (BasicBlock &oBBRef : *oldFunc) {
8566+
BasicBlock *oBB = &oBBRef;
8567+
if (notForAnalysis.find(oBB) != notForAnalysis.end())
8568+
continue;
85628569

8563-
for (Instruction &I : oBB) {
8570+
for (Instruction &I : *oBB) {
85648571
Instruction *inst = &I;
85658572

85668573
if (inst->getType()->isEmptyTy() || inst->getType()->isVoidTy())

0 commit comments

Comments
 (0)