From 15b7f5b72d2ae3dae37a42caa8d3259cfafc70c6 Mon Sep 17 00:00:00 2001 From: Whitney Tsang Date: Mon, 17 Jun 2019 14:38:56 +0000 Subject: PHINode: introduce setIncomingValueForBlock() function, and use it. Summary: There is PHINode::getBasicBlockIndex() and PHINode::setIncomingValue() but no function to replace incoming value for a specified BasicBlock* predecessor. Clearly, there are a lot of places that could use that functionality. Reviewer: craig.topper, lebedev.ri, Meinersbur, kbarton, fhahn Reviewed By: Meinersbur, fhahn Subscribers: fhahn, hiraditya, zzheng, jsji, llvm-commits Tag: LLVM Differential Revision: https://reviews.llvm.org/D63338 llvm-svn: 363566 --- llvm/lib/CodeGen/SafeStack.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'llvm/lib/CodeGen/SafeStack.cpp') diff --git a/llvm/lib/CodeGen/SafeStack.cpp b/llvm/lib/CodeGen/SafeStack.cpp index b73a22133a7..6ee5df42407 100644 --- a/llvm/lib/CodeGen/SafeStack.cpp +++ b/llvm/lib/CodeGen/SafeStack.cpp @@ -613,16 +613,12 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack( ConstantInt::get(Int32Ty, -Offset)); Value *Replacement = IRBUser.CreateBitCast(Off, AI->getType(), Name); - if (auto *PHI = dyn_cast(User)) { + if (auto *PHI = dyn_cast(User)) // PHI nodes may have multiple incoming edges from the same BB (why??), // all must be updated at once with the same incoming value. - auto *BB = PHI->getIncomingBlock(U); - for (unsigned I = 0; I < PHI->getNumIncomingValues(); ++I) - if (PHI->getIncomingBlock(I) == BB) - PHI->setIncomingValue(I, Replacement); - } else { + PHI->setIncomingValueForBlock(PHI->getIncomingBlock(U), Replacement); + else U.set(Replacement); - } } AI->eraseFromParent(); -- cgit v1.2.3