diff --git a/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp b/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp index ffac6ef7c06..4a39e3f1495 100644 --- a/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp +++ b/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp @@ -1031,24 +1031,38 @@ void TypeAnalyzer::updateAnalysis(Value *Val, TypeTree Data, Value *Origin) { } assert(fntypeinfo.Function == I->getParent()->getParent()); assert(Origin); - if (!EnzymeStrictAliasing) { - if (auto OI = dyn_cast(Origin)) { - if (OI->getParent() != I->getParent() && - !PDT.dominates(OI->getParent(), I->getParent())) { - bool allocationWithAllUsersInBlock = false; - if (auto AI = dyn_cast(I)) { - allocationWithAllUsersInBlock = true; - for (auto U : AI->users()) { - auto P = cast(U)->getParent(); - if (P == OI->getParent()) - continue; - if (PDT.dominates(OI->getParent(), P)) - continue; - allocationWithAllUsersInBlock = false; - break; + if (auto OI = dyn_cast(Origin)) { + if (OI->getParent() != I->getParent()) { + if (!EnzymeStrictAliasing) { + if (!PDT.dominates(OI->getParent(), I->getParent())) { + bool allocationWithAllUsersInBlock = false; + if (auto AI = dyn_cast(I)) { + allocationWithAllUsersInBlock = true; + for (auto U : AI->users()) { + auto P = cast(U)->getParent(); + if (P == OI->getParent()) + continue; + if (PDT.dominates(OI->getParent(), P)) + continue; + allocationWithAllUsersInBlock = false; + break; + } + } + if (!allocationWithAllUsersInBlock) { + if (EnzymePrintType) { + llvm::errs() << " skipping update into "; + I->print(llvm::errs(), *MST); + llvm::errs() << " of " << Data.str() << " from "; + OI->print(llvm::errs(), *MST); + llvm::errs() << "\n"; + } + return; } } - if (!allocationWithAllUsersInBlock) { + } else { + if (OI->getParent()->hasNPredecessors(1) && + hasMetadata(OI->getParent()->getTerminator(), + "enzyme_notypeprop")) { if (EnzymePrintType) { llvm::errs() << " skipping update into "; I->print(llvm::errs(), *MST); @@ -1063,21 +1077,36 @@ void TypeAnalyzer::updateAnalysis(Value *Val, TypeTree Data, Value *Origin) { } } else if (auto Arg = dyn_cast(Val)) { assert(fntypeinfo.Function == Arg->getParent()); - if (!EnzymeStrictAliasing) - if (auto OI = dyn_cast(Origin)) { - auto I = &*fntypeinfo.Function->getEntryBlock().begin(); - if (OI->getParent() != I->getParent() && - !PDT.dominates(OI->getParent(), I->getParent())) { - if (EnzymePrintType) { - llvm::errs() << " skipping update into "; - Arg->print(llvm::errs(), *MST); - llvm::errs() << " of " << Data.str() << " from "; - OI->print(llvm::errs(), *MST); - llvm::errs() << "\n"; + if (auto OI = dyn_cast(Origin)) { + auto I = &*fntypeinfo.Function->getEntryBlock().begin(); + if (OI->getParent() != I->getParent()) { + if (!EnzymeStrictAliasing) { + if (!PDT.dominates(OI->getParent(), I->getParent())) { + if (EnzymePrintType) { + llvm::errs() << " skipping update into "; + Arg->print(llvm::errs(), *MST); + llvm::errs() << " of " << Data.str() << " from "; + OI->print(llvm::errs(), *MST); + llvm::errs() << "\n"; + } + return; + } + } else { + if (OI->getParent()->hasNPredecessors(1) && + hasMetadata(OI->getParent()->getTerminator(), + "enzyme_notypeprop")) { + if (EnzymePrintType) { + llvm::errs() << " skipping update into "; + I->print(llvm::errs(), *MST); + llvm::errs() << " of " << Data.str() << " from "; + OI->print(llvm::errs(), *MST); + llvm::errs() << "\n"; + } + return; } - return; } } + } } // Attempt to update the underlying analysis