From 25a3130d89f00f53a23f7fc38250d5dc43e29cfb Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Mon, 19 Jul 2021 15:31:10 -0500 Subject: [Local] Do not introduce a new `llvm.trap` before `unreachable` This is the second attempt to remove the `llvm.trap` insertion after https://reviews.llvm.org/rGe14e7bc4b889dfaffb7180d176a03311df2d4ae6 reverted the first one. It is not clear what the exact issue was back then and it might already be gone by now, it has been >5 years after all. Replaces D106299. Differential Revision: https://reviews.llvm.org/D106308 --- llvm/lib/Transforms/Utils/Local.cpp | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'llvm/lib/Transforms/Utils/Local.cpp') diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index d95c053..e36d108 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -2110,8 +2110,8 @@ llvm::removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB) { return {NumDeadInst, NumDeadDbgInst}; } -unsigned llvm::changeToUnreachable(Instruction *I, bool UseLLVMTrap, - bool PreserveLCSSA, DomTreeUpdater *DTU, +unsigned llvm::changeToUnreachable(Instruction *I, bool PreserveLCSSA, + DomTreeUpdater *DTU, MemorySSAUpdater *MSSAU) { BasicBlock *BB = I->getParent(); @@ -2127,14 +2127,6 @@ unsigned llvm::changeToUnreachable(Instruction *I, bool UseLLVMTrap, if (DTU) UniqueSuccessors.insert(Successor); } - // Insert a call to llvm.trap right before this. This turns the undefined - // behavior into a hard fail instead of falling through into random code. - if (UseLLVMTrap) { - Function *TrapFn = - Intrinsic::getDeclaration(BB->getParent()->getParent(), Intrinsic::trap); - CallInst *CallTrap = CallInst::Create(TrapFn, "", I); - CallTrap->setDebugLoc(I->getDebugLoc()); - } auto *UI = new UnreachableInst(I->getContext(), I); UI->setDebugLoc(I->getDebugLoc()); @@ -2271,7 +2263,7 @@ static bool markAliveBlocks(Function &F, if (IntrinsicID == Intrinsic::assume) { if (match(CI->getArgOperand(0), m_CombineOr(m_Zero(), m_Undef()))) { // Don't insert a call to llvm.trap right before the unreachable. - changeToUnreachable(CI, false, false, DTU); + changeToUnreachable(CI, false, DTU); Changed = true; break; } @@ -2287,8 +2279,7 @@ static bool markAliveBlocks(Function &F, // still be useful for widening. if (match(CI->getArgOperand(0), m_Zero())) if (!isa(CI->getNextNode())) { - changeToUnreachable(CI->getNextNode(), /*UseLLVMTrap=*/false, - false, DTU); + changeToUnreachable(CI->getNextNode(), false, DTU); Changed = true; break; } @@ -2296,7 +2287,7 @@ static bool markAliveBlocks(Function &F, } else if ((isa(Callee) && !NullPointerIsDefined(CI->getFunction())) || isa(Callee)) { - changeToUnreachable(CI, /*UseLLVMTrap=*/false, false, DTU); + changeToUnreachable(CI, false, DTU); Changed = true; break; } @@ -2306,7 +2297,7 @@ static bool markAliveBlocks(Function &F, // though. if (!isa(CI->getNextNode())) { // Don't insert a call to llvm.trap right before the unreachable. - changeToUnreachable(CI->getNextNode(), false, false, DTU); + changeToUnreachable(CI->getNextNode(), false, DTU); Changed = true; } break; @@ -2325,7 +2316,7 @@ static bool markAliveBlocks(Function &F, (isa(Ptr) && !NullPointerIsDefined(SI->getFunction(), SI->getPointerAddressSpace()))) { - changeToUnreachable(SI, true, false, DTU); + changeToUnreachable(SI, false, DTU); Changed = true; break; } @@ -2339,7 +2330,7 @@ static bool markAliveBlocks(Function &F, if ((isa(Callee) && !NullPointerIsDefined(BB->getParent())) || isa(Callee)) { - changeToUnreachable(II, true, false, DTU); + changeToUnreachable(II, false, DTU); Changed = true; } else if (II->doesNotThrow() && canSimplifyInvokeNoUnwind(&F)) { if (II->use_empty() && II->onlyReadsMemory()) { -- cgit v1.1