aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2025-07-22 09:44:03 +0200
committerGitHub <noreply@github.com>2025-07-22 09:44:03 +0200
commit307256ecbd858bc2df5fa9342c67a8205691ade9 (patch)
tree36345870f2bbc008803befffabf22536a7728ea1 /llvm/lib
parent314ce691df0d699234c871a1772470b5e4aed892 (diff)
downloadllvm-307256ecbd858bc2df5fa9342c67a8205691ade9.zip
llvm-307256ecbd858bc2df5fa9342c67a8205691ade9.tar.gz
llvm-307256ecbd858bc2df5fa9342c67a8205691ade9.tar.bz2
[GVNSink] Do not sink lifetimes of different allocas (#149818)
This was always undesirable, and after #149310 it is illegal and will result in a verifier error. Fix this by moving SimplifyCFG's check for this into canReplaceOperandWithVariable(), so it's shared with GVNSink.
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp4
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp10
2 files changed, 4 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 1e3ef68..f89d36f 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -3857,6 +3857,10 @@ bool llvm::canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx) {
if (Op->isSwiftError())
return false;
+ // Cannot replace alloca argument with phi/select.
+ if (I->isLifetimeStartOrEnd())
+ return false;
+
// Early exit.
if (!isa<Constant, InlineAsm>(Op))
return true;
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 75c9650..94b0ab8 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2227,16 +2227,6 @@ static bool canSinkInstructions(
return I->getOperand(OI) == I0->getOperand(OI);
};
if (!all_of(Insts, SameAsI0)) {
- // SROA can't speculate lifetime markers of selects/phis, and the
- // backend may handle such lifetimes incorrectly as well (#104776).
- // Don't sink lifetimes if it would introduce a phi on the pointer
- // argument.
- if (isa<LifetimeIntrinsic>(I0) && OI == 1 &&
- any_of(Insts, [](const Instruction *I) {
- return isa<AllocaInst>(I->getOperand(1)->stripPointerCasts());
- }))
- return false;
-
if ((isa<Constant>(Op) && !replacingOperandWithVariableIsCheap(I0, OI)) ||
!canReplaceOperandWithVariable(I0, OI))
// We can't create a PHI from this GEP.