diff options
author | Nikita Popov <npopov@redhat.com> | 2022-07-13 16:53:11 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2022-08-31 11:10:24 +0200 |
commit | 8f3fd26b74a7f5eb9892556511bae8f70a3597dc (patch) | |
tree | c3e88ec98beabf2b0c24e3baca97b448363a170a /llvm/lib/Transforms/Scalar/Reassociate.cpp | |
parent | 0e5fe1cdacdca65edc84c89cc7a6de27f406de61 (diff) | |
download | llvm-8f3fd26b74a7f5eb9892556511bae8f70a3597dc.zip llvm-8f3fd26b74a7f5eb9892556511bae8f70a3597dc.tar.gz llvm-8f3fd26b74a7f5eb9892556511bae8f70a3597dc.tar.bz2 |
[Reassociate] Use getInsertionPointerAfterDef()
This simplifies the code and fixes handling for the callbr case,
where the instruction needs to be inserted in the normal
destination, rather than after the terminator.
Originally part of D129660.
Diffstat (limited to 'llvm/lib/Transforms/Scalar/Reassociate.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/Reassociate.cpp | 36 |
1 files changed, 6 insertions, 30 deletions
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp index 87546a7..3bd1234 100644 --- a/llvm/lib/Transforms/Scalar/Reassociate.cpp +++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp @@ -886,40 +886,16 @@ static Value *NegateValue(Value *V, Instruction *BI, if (TheNeg->getParent()->getParent() != BI->getParent()->getParent()) continue; - bool FoundCatchSwitch = false; - - BasicBlock::iterator InsertPt; + Instruction *InsertPt; if (Instruction *InstInput = dyn_cast<Instruction>(V)) { - if (InvokeInst *II = dyn_cast<InvokeInst>(InstInput)) { - InsertPt = II->getNormalDest()->begin(); - } else { - InsertPt = ++InstInput->getIterator(); - } - - const BasicBlock *BB = InsertPt->getParent(); - - // Make sure we don't move anything before PHIs or exception - // handling pads. - while (InsertPt != BB->end() && (isa<PHINode>(InsertPt) || - InsertPt->isEHPad())) { - if (isa<CatchSwitchInst>(InsertPt)) - // A catchswitch cannot have anything in the block except - // itself and PHIs. We'll bail out below. - FoundCatchSwitch = true; - ++InsertPt; - } + InsertPt = InstInput->getInsertionPointAfterDef(); + if (!InsertPt) + continue; } else { - InsertPt = TheNeg->getParent()->getParent()->getEntryBlock().begin(); + InsertPt = &*TheNeg->getFunction()->getEntryBlock().begin(); } - // We found a catchswitch in the block where we want to move the - // neg. We cannot move anything into that block. Bail and just - // create the neg before BI, as if we hadn't found an existing - // neg. - if (FoundCatchSwitch) - break; - - TheNeg->moveBefore(&*InsertPt); + TheNeg->moveBefore(InsertPt); if (TheNeg->getOpcode() == Instruction::Sub) { TheNeg->setHasNoUnsignedWrap(false); TheNeg->setHasNoSignedWrap(false); |