aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-09-20 10:46:25 +0200
committerNikita Popov <npopov@redhat.com>2023-09-20 10:48:05 +0200
commitafd7db48c55cb87566758e961f1ebac8af16b8bc (patch)
treea9a3dbaead4cd4fa36130b23090dc58e159591ec /llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
parent7b8130c2c38b54e93af6c9aeacd954f2085abd33 (diff)
downloadllvm-afd7db48c55cb87566758e961f1ebac8af16b8bc.zip
llvm-afd7db48c55cb87566758e961f1ebac8af16b8bc.tar.gz
llvm-afd7db48c55cb87566758e961f1ebac8af16b8bc.tar.bz2
[SimpleLoopUnswitch] Fix reversed branch during condition injection
The in-loop successor is only on the left after a potential condition inversion. As we re-use the old condition as-is, we should also reuse the old successors as-is. Fixes https://github.com/llvm/llvm-project/issues/63962.
Diffstat (limited to 'llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
index 769a4e9..cad026f 100644
--- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -3061,7 +3061,6 @@ injectPendingInvariantConditions(NonTrivialUnswitchCandidate Candidate, Loop &L,
auto *InjectedCond =
ICmpInst::Create(Instruction::ICmp, Pred, LHS, RHS, "injected.cond",
Preheader->getTerminator());
- auto *OldCond = TI->getCondition();
BasicBlock *CheckBlock = BasicBlock::Create(Ctx, BB->getName() + ".check",
BB->getParent(), InLoopSucc);
@@ -3070,7 +3069,8 @@ injectPendingInvariantConditions(NonTrivialUnswitchCandidate Candidate, Loop &L,
Builder.CreateCondBr(InjectedCond, InLoopSucc, CheckBlock);
Builder.SetInsertPoint(CheckBlock);
- auto *NewTerm = Builder.CreateCondBr(OldCond, InLoopSucc, OutOfLoopSucc);
+ auto *NewTerm = Builder.CreateCondBr(TI->getCondition(), TI->getSuccessor(0),
+ TI->getSuccessor(1));
TI->eraseFromParent();
// Prevent infinite unswitching.