aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2024-08-26 10:14:43 +0200
committerGitHub <noreply@github.com>2024-08-26 10:14:43 +0200
commit84497c6f4f6c79b0d8c38da666724eed7e9e8db5 (patch)
tree8024a43cd8762ac7a8e80e4b67f0d2d5f5fcc8aa /llvm/lib/Transforms/Utils/SimplifyCFG.cpp
parent28fe6ddd9b9af0167d355ceb5b9eace53c7f162b (diff)
downloadllvm-84497c6f4f6c79b0d8c38da666724eed7e9e8db5.zip
llvm-84497c6f4f6c79b0d8c38da666724eed7e9e8db5.tar.gz
llvm-84497c6f4f6c79b0d8c38da666724eed7e9e8db5.tar.bz2
[SimplifyCFG] Remove limitation on sinking of load/store of alloca (#104788)
This is a followup to https://github.com/llvm/llvm-project/pull/104579 to remove the limitation on sinking loads/stores of allocas entirely, even if this would introduce a phi node. Nowadays, SROA supports speculating load/store over select/phi. Additionally, SimplifyCFG with sinking only runs at the end of the function simplification pipeline, after SROA. I checked that the two tests modified here still successfully SROA after the SimplifyCFG transform. We should, however, keep the limitation on lifetime intrinsics. SROA does not have speculation support for these, and I've also found that the way these are handled in the backend is very problematic (https://github.com/llvm/llvm-project/issues/104776), so I think we should leave them alone.
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp19
1 files changed, 4 insertions, 15 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index da4d57f..92e2d18 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2051,21 +2051,10 @@ static bool canSinkInstructions(
return I->getOperand(OI) == I0->getOperand(OI);
};
if (!all_of(Insts, SameAsI0)) {
- // Because SROA historically couldn't handle speculating stores of
- // selects, we try not to sink loads, stores or lifetime markers of
- // allocas when we'd have to create a PHI for the address operand.
- // TODO: SROA supports speculation for loads and stores now -- remove
- // this hack?
- if (isa<StoreInst>(I0) && OI == 1 &&
- any_of(Insts, [](const Instruction *I) {
- return isa<AllocaInst>(I->getOperand(1)->stripPointerCasts());
- }))
- return false;
- if (isa<LoadInst>(I0) && OI == 0 &&
- any_of(Insts, [](const Instruction *I) {
- return isa<AllocaInst>(I->getOperand(0)->stripPointerCasts());
- }))
- return false;
+ // 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 (isLifeTimeMarker(I0) && OI == 1 &&
any_of(Insts, [](const Instruction *I) {
return isa<AllocaInst>(I->getOperand(1)->stripPointerCasts());