diff options
author | Philip Reames <listmail@philipreames.com> | 2019-04-02 02:42:57 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2019-04-02 02:42:57 +0000 |
commit | adb3ece2164105373a41b4e043dc0694d49ca0d8 (patch) | |
tree | 47eacecbe58c3d5cbf48009d2efa867c8ee424c3 /llvm/lib/Transforms/Scalar/LoopPredication.cpp | |
parent | c0ebfbe3f3215e15ff5d6b69218576ec07317821 (diff) | |
download | llvm-adb3ece2164105373a41b4e043dc0694d49ca0d8.zip llvm-adb3ece2164105373a41b4e043dc0694d49ca0d8.tar.gz llvm-adb3ece2164105373a41b4e043dc0694d49ca0d8.tar.bz2 |
[LoopPredication] Simplify widenable condition handling [NFC]
The code doesn't actually need any of the information about the widenable condition at this level. The only thing we need is to ensure the WC call is the last thing anded in, and even that is a quirk we should really look to remove.
llvm-svn: 357448
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopPredication.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopPredication.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopPredication.cpp b/llvm/lib/Transforms/Scalar/LoopPredication.cpp index 2b031ba..8487278 100644 --- a/llvm/lib/Transforms/Scalar/LoopPredication.cpp +++ b/llvm/lib/Transforms/Scalar/LoopPredication.cpp @@ -594,6 +594,7 @@ unsigned LoopPredication::collectChecks(SmallVectorImpl<Value *> &Checks, // resulting list of subconditions in Checks vector. SmallVector<Value *, 4> Worklist(1, Condition); SmallPtrSet<Value *, 4> Visited; + Value *WideableCond = nullptr; do { Value *Condition = Worklist.pop_back_val(); if (!Visited.insert(Condition).second) @@ -607,6 +608,13 @@ unsigned LoopPredication::collectChecks(SmallVectorImpl<Value *> &Checks, continue; } + if (match(Condition, + m_Intrinsic<Intrinsic::experimental_widenable_condition>())) { + // Pick any, we don't care which + WideableCond = Condition; + continue; + } + if (ICmpInst *ICI = dyn_cast<ICmpInst>(Condition)) { if (auto NewRangeCheck = widenICmpRangeCheck(ICI, Expander, Builder)) { @@ -619,6 +627,12 @@ unsigned LoopPredication::collectChecks(SmallVectorImpl<Value *> &Checks, // Save the condition as is if we can't widen it Checks.push_back(Condition); } while (!Worklist.empty()); + // At the moment, our matching logic for wideable conditions implicitly + // assumes we preserve the form: (br (and Cond, WC())). FIXME + // Note that if there were multiple calls to wideable condition in the + // traversal, we only need to keep one, and which one is arbitrary. + if (WideableCond) + Checks.push_back(WideableCond); return NumWidened; } @@ -662,10 +676,8 @@ bool LoopPredication::widenWidenableBranchGuardConditions( TotalConsidered++; SmallVector<Value *, 4> Checks; IRBuilder<> Builder(cast<Instruction>(Preheader->getTerminator())); - Value *Condition = nullptr, *WidenableCondition = nullptr; - BasicBlock *GBB = nullptr, *DBB = nullptr; - parseWidenableBranch(BI, Condition, WidenableCondition, GBB, DBB); - unsigned NumWidened = collectChecks(Checks, Condition, Expander, Builder); + unsigned NumWidened = collectChecks(Checks, BI->getCondition(), + Expander, Builder); if (NumWidened == 0) return false; @@ -679,11 +691,8 @@ bool LoopPredication::widenWidenableBranchGuardConditions( LastCheck = Check; else LastCheck = Builder.CreateAnd(LastCheck, Check); - // Make sure that the check contains widenable condition and therefore can be - // further widened. - LastCheck = Builder.CreateAnd(LastCheck, WidenableCondition); - auto *OldCond = BI->getOperand(0); - BI->setOperand(0, LastCheck); + auto *OldCond = BI->getCondition(); + BI->setCondition(LastCheck); assert(isGuardAsWidenableBranch(BI) && "Stopped being a guard after transform?"); RecursivelyDeleteTriviallyDeadInstructions(OldCond); |