From d109e2a7c3b7602c92e1fd92884876a28b68fd78 Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Mon, 1 Apr 2019 16:05:15 +0000 Subject: [LoopPred] Delete the old condition expressions if unused LoopPredication was replacing the original condition, but leaving the instructions to compute the old conditions around. This would get cleaned up by other passes of course, but we might as well do it eagerly. That also makes the test output less confusing. llvm-svn: 357406 --- llvm/lib/Transforms/Scalar/LoopPredication.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/Scalar/LoopPredication.cpp b/llvm/lib/Transforms/Scalar/LoopPredication.cpp index 7695889a4a5..6257f419459 100644 --- a/llvm/lib/Transforms/Scalar/LoopPredication.cpp +++ b/llvm/lib/Transforms/Scalar/LoopPredication.cpp @@ -193,6 +193,7 @@ #include "llvm/Pass.h" #include "llvm/Support/Debug.h" #include "llvm/Transforms/Scalar.h" +#include "llvm/Transforms/Utils/Local.h" #include "llvm/Transforms/Utils/LoopUtils.h" #define DEBUG_TYPE "loop-predication" @@ -641,7 +642,9 @@ bool LoopPredication::widenGuardConditions(IntrinsicInst *Guard, LastCheck = Check; else LastCheck = Builder.CreateAnd(LastCheck, Check); + auto *OldCond = Guard->getOperand(0); Guard->setOperand(0, LastCheck); + RecursivelyDeleteTriviallyDeadInstructions(OldCond); LLVM_DEBUG(dbgs() << "Widened checks = " << NumWidened << "\n"); return true; @@ -676,9 +679,11 @@ bool LoopPredication::widenWidenableBranchGuardConditions( // Make sure that the check contains widenable condition and therefore can be // further widened. LastCheck = Builder.CreateAnd(LastCheck, WidenableCondition); + auto *OldCond = Guard->getOperand(0); Guard->setOperand(0, LastCheck); assert(isGuardAsWidenableBranch(Guard) && "Stopped being a guard after transform?"); + RecursivelyDeleteTriviallyDeadInstructions(OldCond); LLVM_DEBUG(dbgs() << "Widened checks = " << NumWidened << "\n"); return true; -- cgit v1.2.3