aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2022-07-04 19:20:19 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-02-08 19:02:26 +0000
commit81ad626541db97eb356e2c1d4a20eb2a26a766ab (patch)
tree311b6a8987c32b1e1dcbab65c54cfac3fdb56175 /contrib/llvm-project/llvm/lib/Transforms/Utils/Local.cpp
parent5fff09660e06a66bed6482da9c70df328e16bbb6 (diff)
parent145449b1e420787bb99721a429341fa6be3adfb6 (diff)
downloadsrc-81ad626541db97eb356e2c1d4a20eb2a26a766ab.tar.gz
src-81ad626541db97eb356e2c1d4a20eb2a26a766ab.zip
Merge llvm-project main llvmorg-15-init-15358-g53dc0f10787
This updates llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp to llvmorg-15-init-15358-g53dc0f10787. PR: 265425 MFC after: 2 weeks
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Transforms/Utils/Local.cpp77
1 files changed, 47 insertions, 30 deletions
diff --git a/contrib/llvm-project/llvm/lib/Transforms/Utils/Local.cpp b/contrib/llvm-project/llvm/lib/Transforms/Utils/Local.cpp
index 1c350a2585d0..b203259db1c6 100644
--- a/contrib/llvm-project/llvm/lib/Transforms/Utils/Local.cpp
+++ b/contrib/llvm-project/llvm/lib/Transforms/Utils/Local.cpp
@@ -29,7 +29,6 @@
#include "llvm/Analysis/DomTreeUpdater.h"
#include "llvm/Analysis/EHPersonalities.h"
#include "llvm/Analysis/InstructionSimplify.h"
-#include "llvm/Analysis/LazyValueInfo.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/MemorySSAUpdater.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
@@ -63,9 +62,7 @@
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
-#include "llvm/IR/Operator.h"
#include "llvm/IR/PatternMatch.h"
-#include "llvm/IR/PseudoProbe.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Use.h"
#include "llvm/IR/User.h"
@@ -80,7 +77,6 @@
#include "llvm/Transforms/Utils/ValueMapper.h"
#include <algorithm>
#include <cassert>
-#include <climits>
#include <cstdint>
#include <iterator>
#include <map>
@@ -489,7 +485,7 @@ bool llvm::wouldInstructionBeTriviallyDead(Instruction *I,
if (auto *FPI = dyn_cast<ConstrainedFPIntrinsic>(I)) {
Optional<fp::ExceptionBehavior> ExBehavior = FPI->getExceptionBehavior();
- return ExBehavior.getValue() != fp::ebStrict;
+ return *ExBehavior != fp::ebStrict;
}
}
@@ -504,15 +500,12 @@ bool llvm::wouldInstructionBeTriviallyDead(Instruction *I,
if (isMathLibCallNoop(Call, TLI))
return true;
- // To express possible interaction with floating point environment constrained
- // intrinsics are described as if they access memory. So they look like having
- // side effect but actually do not have it unless they raise floating point
- // exception. If FP exceptions are ignored, the intrinsic may be deleted.
- if (auto *CI = dyn_cast<ConstrainedFPIntrinsic>(I)) {
- Optional<fp::ExceptionBehavior> EB = CI->getExceptionBehavior();
- if (!EB || *EB == fp::ExceptionBehavior::ebIgnore)
- return true;
- }
+ // Non-volatile atomic loads from constants can be removed.
+ if (auto *LI = dyn_cast<LoadInst>(I))
+ if (auto *GV = dyn_cast<GlobalVariable>(
+ LI->getPointerOperand()->stripPointerCasts()))
+ if (!LI->isVolatile() && GV->isConstant())
+ return true;
return false;
}
@@ -682,7 +675,7 @@ simplifyAndDCEInstruction(Instruction *I,
return true;
}
- if (Value *SimpleV = SimplifyInstruction(I, DL)) {
+ if (Value *SimpleV = simplifyInstruction(I, DL)) {
// Add the users to the worklist. CAREFUL: an instruction can use itself,
// in the case of a phi node.
for (User *U : I->users()) {
@@ -1133,7 +1126,7 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
// If there is more than one pred of succ, and there are PHI nodes in
// the successor, then we need to add incoming edges for the PHI nodes
//
- const PredBlockVector BBPreds(pred_begin(BB), pred_end(BB));
+ const PredBlockVector BBPreds(predecessors(BB));
// Loop over all of the PHI nodes in the successor of BB.
for (BasicBlock::iterator I = Succ->begin(); isa<PHINode>(I); ++I) {
@@ -1393,7 +1386,7 @@ Align llvm::getOrEnforceKnownAlignment(Value *V, MaybeAlign PrefAlign,
static bool PhiHasDebugValue(DILocalVariable *DIVar,
DIExpression *DIExpr,
PHINode *APN) {
- // Since we can't guarantee that the original dbg.declare instrinsic
+ // Since we can't guarantee that the original dbg.declare intrinsic
// is removed by LowerDbgDeclare(), we need to make sure that we are
// not inserting the same dbg.value intrinsic over and over.
SmallVector<DbgValueInst *, 1> DbgValues;
@@ -1472,7 +1465,7 @@ void llvm::ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
LLVM_DEBUG(dbgs() << "Failed to convert dbg.declare to dbg.value: "
<< *DII << '\n');
// For now, when there is a store to parts of the variable (but we do not
- // know which part) we insert an dbg.value instrinsic to indicate that we
+ // know which part) we insert an dbg.value intrinsic to indicate that we
// know nothing about the variable's content.
DV = UndefValue::get(DV->getType());
Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc, SI);
@@ -2240,6 +2233,7 @@ BasicBlock *llvm::changeToInvokeAndSplitBasicBlock(CallInst *CI,
II->setDebugLoc(CI->getDebugLoc());
II->setCallingConv(CI->getCallingConv());
II->setAttributes(CI->getAttributes());
+ II->setMetadata(LLVMContext::MD_prof, CI->getMetadata(LLVMContext::MD_prof));
if (DTU)
DTU->applyUpdates({{DominatorTree::Insert, BB, UnwindEdge}});
@@ -2349,19 +2343,42 @@ static bool markAliveBlocks(Function &F,
isa<UndefValue>(Callee)) {
changeToUnreachable(II, false, DTU);
Changed = true;
- } else if (II->doesNotThrow() && canSimplifyInvokeNoUnwind(&F)) {
- if (II->use_empty() && !II->mayHaveSideEffects()) {
- // jump to the normal destination branch.
- BasicBlock *NormalDestBB = II->getNormalDest();
- BasicBlock *UnwindDestBB = II->getUnwindDest();
- BranchInst::Create(NormalDestBB, II);
- UnwindDestBB->removePredecessor(II->getParent());
- II->eraseFromParent();
+ } else {
+ if (II->doesNotReturn() &&
+ !isa<UnreachableInst>(II->getNormalDest()->front())) {
+ // If we found an invoke of a no-return function,
+ // create a new empty basic block with an `unreachable` terminator,
+ // and set it as the normal destination for the invoke,
+ // unless that is already the case.
+ // Note that the original normal destination could have other uses.
+ BasicBlock *OrigNormalDest = II->getNormalDest();
+ OrigNormalDest->removePredecessor(II->getParent());
+ LLVMContext &Ctx = II->getContext();
+ BasicBlock *UnreachableNormalDest = BasicBlock::Create(
+ Ctx, OrigNormalDest->getName() + ".unreachable",
+ II->getFunction(), OrigNormalDest);
+ new UnreachableInst(Ctx, UnreachableNormalDest);
+ II->setNormalDest(UnreachableNormalDest);
if (DTU)
- DTU->applyUpdates({{DominatorTree::Delete, BB, UnwindDestBB}});
- } else
- changeToCall(II, DTU);
- Changed = true;
+ DTU->applyUpdates(
+ {{DominatorTree::Delete, BB, OrigNormalDest},
+ {DominatorTree::Insert, BB, UnreachableNormalDest}});
+ Changed = true;
+ }
+ if (II->doesNotThrow() && canSimplifyInvokeNoUnwind(&F)) {
+ if (II->use_empty() && !II->mayHaveSideEffects()) {
+ // jump to the normal destination branch.
+ BasicBlock *NormalDestBB = II->getNormalDest();
+ BasicBlock *UnwindDestBB = II->getUnwindDest();
+ BranchInst::Create(NormalDestBB, II);
+ UnwindDestBB->removePredecessor(II->getParent());
+ II->eraseFromParent();
+ if (DTU)
+ DTU->applyUpdates({{DominatorTree::Delete, BB, UnwindDestBB}});
+ } else
+ changeToCall(II, DTU);
+ Changed = true;
+ }
}
} else if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(Terminator)) {
// Remove catchpads which cannot be reached.