[llvm] r270802 - [IRCE] Refactor out a parseRangeCheckFromCond; NFC
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Wed May 25 18:03:44 PDT 2016
Hi,
FYI: this change introduced a use-of-uninitialized-var that I
(unintentionally) fixed in r270804. I didn't notice the issue since I
was testing both the changes together.
I'm okay with reverting and re-applying if people think that will
help, but given that the problem no longer exists in ToT, it feels
like unnecessary churn.
-- Sanjoy
On Wed, May 25, 2016 at 5:08 PM, Sanjoy Das via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: sanjoy
> Date: Wed May 25 19:08:24 2016
> New Revision: 270802
>
> URL: http://llvm.org/viewvc/llvm-project?rev=270802&view=rev
> Log:
> [IRCE] Refactor out a parseRangeCheckFromCond; NFC
>
> This will later hold more general logic to parse conjunctions of range
> checks.
>
> Modified:
> llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
>
> Modified: llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp?rev=270802&r1=270801&r2=270802&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp Wed May 25 19:08:24 2016
> @@ -125,9 +125,8 @@ class InductiveRangeCheck {
> ScalarEvolution &SE, Value *&Index,
> Value *&Length);
>
> - static InductiveRangeCheck::RangeCheckKind
> - parseRangeCheck(Loop *L, ScalarEvolution &SE, Value *Condition,
> - Value *&Index, Value *&UpperLimit);
> + static Optional<InductiveRangeCheck>
> + parseRangeCheckFromCond(Loop *L, ScalarEvolution &SE, Use &ConditionUse);
>
> InductiveRangeCheck()
> : Offset(nullptr), Scale(nullptr), Length(nullptr),
> @@ -313,14 +312,17 @@ InductiveRangeCheck::parseRangeCheckICmp
> llvm_unreachable("default clause returns!");
> }
>
> -/// Parses an arbitrary condition into a range check. `Length` is set only if
> -/// the range check is recognized to be `RANGE_CHECK_UPPER` or stronger.
> -InductiveRangeCheck::RangeCheckKind
> -InductiveRangeCheck::parseRangeCheck(Loop *L, ScalarEvolution &SE,
> - Value *Condition, Value *&Index,
> - Value *&Length) {
> +/// Parses an arbitrary condition into an inductive range check.
> +Optional<InductiveRangeCheck>
> +InductiveRangeCheck::parseRangeCheckFromCond(Loop *L, ScalarEvolution &SE,
> + Use &ConditionUse) {
> using namespace llvm::PatternMatch;
>
> + Value *Condition = ConditionUse.get();
> +
> + Value *Length, *Index;
> + InductiveRangeCheck::RangeCheckKind RCKind;
> +
> Value *A = nullptr;
> Value *B = nullptr;
>
> @@ -330,31 +332,42 @@ InductiveRangeCheck::parseRangeCheck(Loo
> ICmpInst *ICmpA = dyn_cast<ICmpInst>(A), *ICmpB = dyn_cast<ICmpInst>(B);
>
> if (!ICmpA || !ICmpB)
> - return InductiveRangeCheck::RANGE_CHECK_UNKNOWN;
> + return None;
>
> auto RCKindA = parseRangeCheckICmp(L, ICmpA, SE, IndexA, LengthA);
> auto RCKindB = parseRangeCheckICmp(L, ICmpB, SE, IndexB, LengthB);
>
> if (RCKindA == InductiveRangeCheck::RANGE_CHECK_UNKNOWN ||
> - RCKindB == InductiveRangeCheck::RANGE_CHECK_UNKNOWN)
> - return InductiveRangeCheck::RANGE_CHECK_UNKNOWN;
> -
> - if (IndexA != IndexB)
> - return InductiveRangeCheck::RANGE_CHECK_UNKNOWN;
> -
> - if (LengthA != nullptr && LengthB != nullptr && LengthA != LengthB)
> - return InductiveRangeCheck::RANGE_CHECK_UNKNOWN;
> + RCKindB == InductiveRangeCheck::RANGE_CHECK_UNKNOWN ||
> + IndexA != IndexB ||
> + (LengthA != nullptr && LengthB != nullptr && LengthA != LengthB))
> + return None;
>
> Index = IndexA;
> Length = LengthA == nullptr ? LengthB : LengthA;
> -
> - return (InductiveRangeCheck::RangeCheckKind)(RCKindA | RCKindB);
> + RCKind = (InductiveRangeCheck::RangeCheckKind)(RCKindA | RCKindB);
> + } else if (ICmpInst *ICI = dyn_cast<ICmpInst>(Condition)) {
> + RCKind = parseRangeCheckICmp(L, ICI, SE, Index, Length);
> + if (RCKind == InductiveRangeCheck::RANGE_CHECK_UNKNOWN)
> + return None;
> + } else {
> + return None;
> }
>
> - if (ICmpInst *ICI = dyn_cast<ICmpInst>(Condition))
> - return parseRangeCheckICmp(L, ICI, SE, Index, Length);
> + const auto *IndexAddRec = dyn_cast<SCEVAddRecExpr>(SE.getSCEV(Index));
> + bool IsAffineIndex =
> + IndexAddRec && (IndexAddRec->getLoop() == L) && IndexAddRec->isAffine();
>
> - return InductiveRangeCheck::RANGE_CHECK_UNKNOWN;
> + if (!IsAffineIndex)
> + return None;
> +
> + InductiveRangeCheck IRC;
> + IRC.Length = Length;
> + IRC.Offset = IndexAddRec->getStart();
> + IRC.Scale = IndexAddRec->getStepRecurrence(SE);
> + IRC.CheckUse = &ConditionUse;
> + IRC.Kind = RCKind;
> + return IRC;
> }
>
> Optional<InductiveRangeCheck>
> @@ -366,35 +379,11 @@ InductiveRangeCheck::create(BranchInst *
>
> BranchProbability LikelyTaken(15, 16);
>
> - if (BPI.getEdgeProbability(BI->getParent(), (unsigned) 0) < LikelyTaken)
> - return None;
> -
> - Value *Length = nullptr, *Index = nullptr;
> -
> - auto RCKind = InductiveRangeCheck::parseRangeCheck(L, SE, BI->getCondition(),
> - Index, Length);
> -
> - if (RCKind == InductiveRangeCheck::RANGE_CHECK_UNKNOWN)
> + if (BPI.getEdgeProbability(BI->getParent(), (unsigned)0) < LikelyTaken)
> return None;
>
> - assert(Index && "contract with parseRangeCheck!");
> - assert((!(RCKind & InductiveRangeCheck::RANGE_CHECK_UPPER) || Length) &&
> - "contract with parseRangeCheck!");
> -
> - const auto *IndexAddRec = dyn_cast<SCEVAddRecExpr>(SE.getSCEV(Index));
> - bool IsAffineIndex =
> - IndexAddRec && (IndexAddRec->getLoop() == L) && IndexAddRec->isAffine();
> -
> - if (!IsAffineIndex)
> - return None;
> -
> - InductiveRangeCheck IRC;
> - IRC.Length = Length;
> - IRC.Offset = IndexAddRec->getStart();
> - IRC.Scale = IndexAddRec->getStepRecurrence(SE);
> - IRC.CheckUse = &BI->getOperandUse(0);
> - IRC.Kind = RCKind;
> - return IRC;
> + return InductiveRangeCheck::parseRangeCheckFromCond(L, SE,
> + BI->getOperandUse(0));
> }
>
> namespace {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
--
Sanjoy Das
http://playingwithpointers.com
More information about the llvm-commits
mailing list