diff options
author | Philip Reames <listmail@philipreames.com> | 2019-11-06 14:05:59 -0800 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2019-11-06 14:16:34 -0800 |
commit | 686f449e3d4ecad6413427aef35557f5adac100c (patch) | |
tree | c23ccbf41fba2ff50d64a86cff8e33c447427c0a /llvm/lib/Analysis/GuardUtils.cpp | |
parent | 62ad2128255877ed41c714366861eee9c1da30dd (diff) | |
download | bcm5719-llvm-686f449e3d4ecad6413427aef35557f5adac100c.tar.gz bcm5719-llvm-686f449e3d4ecad6413427aef35557f5adac100c.zip |
[WC] Fix a subtle bug in our definition of widenable branch
We had a subtle, but nasty bug in our definition of a widenable branch, and thus in the transforms which used that utility. Specifically, we returned true for any branch which included a widenable condition within it's condition, regardless of whether that widenable condition also had other uses.
The problem is that the result of the WC() call is defined to be one particular value. As such, all users must agree as to what that value is. If we widen a branch without also updating *all other users* of the WC in the same way, we have broken the required semantics.
Most of the textual diff is updating existing transforms not to leave dead uses hanging around. They're largely NFC as the dead instructions would be immediately deleted by other passes. The reason to make these changes is so that the transforms preserve the widenable branch form.
In practice, we don't get bitten by this only because it isn't profitable to CSE WC() calls and the lowering pass from guards uses distinct WC calls per branch.
Differential Revision: https://reviews.llvm.org/D69916
Diffstat (limited to 'llvm/lib/Analysis/GuardUtils.cpp')
-rw-r--r-- | llvm/lib/Analysis/GuardUtils.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/GuardUtils.cpp b/llvm/lib/Analysis/GuardUtils.cpp index cad92f6e56b..863443cea35 100644 --- a/llvm/lib/Analysis/GuardUtils.cpp +++ b/llvm/lib/Analysis/GuardUtils.cpp @@ -42,6 +42,11 @@ bool llvm::parseWidenableBranch(const User *U, Value *&Condition, if (!match(U, m_Br(m_And(m_Value(Condition), m_Value(WidenableCondition)), IfTrueBB, IfFalseBB))) return false; + // For the branch to be (easily) widenable, it must not correlate with other + // branches. Thus, the widenable condition must have a single use. + if (!WidenableCondition->hasOneUse() || + !cast<BranchInst>(U)->getCondition()->hasOneUse()) + return false; // TODO: At the moment, we only recognize the branch if the WC call in this // specific position. We should generalize! return match(WidenableCondition, |