[Attributor] Identify dead uses in PHIs (almost) based on dead edges
As an approximation to a dead edge we can check if the terminator is
dead. If so, the corresponding operand use in a PHI node is dead even if
the PHI node itself is not.
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 4c0185d..877557a 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -6489,14 +6489,27 @@
const Use *U = Worklist.pop_back_val();
if (!Visited.insert(U).second)
continue;
- LLVM_DEBUG(dbgs() << "[Attributor] Check use: " << **U << "\n");
- if (Instruction *UserI = dyn_cast<Instruction>(U->getUser()))
- if (LivenessAA && LivenessAA->isAssumedDead(UserI)) {
- LLVM_DEBUG(dbgs() << "[Attributor] Dead user: " << *UserI << ": "
- << *LivenessAA << "\n");
- AnyDead = true;
- continue;
+ LLVM_DEBUG(dbgs() << "[Attributor] Check use: " << **U << " [" << LivenessAA
+ << "]\n");
+ if (LivenessAA) {
+ if (Instruction *UserI = dyn_cast<Instruction>(U->getUser())) {
+ if (LivenessAA->isAssumedDead(UserI)) {
+ LLVM_DEBUG(dbgs() << "[Attributor] Dead user: " << *UserI << ": "
+ << *LivenessAA << "\n");
+ AnyDead = true;
+ continue;
+ }
+ if (PHINode *PHI = dyn_cast<PHINode>(UserI)) {
+ BasicBlock *IncomingBB = PHI->getIncomingBlock(*U);
+ if (LivenessAA->isAssumedDead(IncomingBB->getTerminator())) {
+ LLVM_DEBUG(dbgs() << "[Attributor] Dead user: " << *UserI << ": "
+ << *LivenessAA << "\n");
+ AnyDead = true;
+ continue;
+ }
+ }
}
+ }
bool Follow = false;
if (!Pred(*U, Follow))