From: Philip Reames Date: Mon, 3 Jun 2019 16:23:20 +0000 (+0000) Subject: [LoopPred] Convert a second member function to a static helper [NFC] X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f95d9be119e672e3f1910372b1191b331120a4c;p=llvm [LoopPred] Convert a second member function to a static helper [NFC] (And remember to actually mark the first one static.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362415 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/LoopPredication.cpp b/lib/Transforms/Scalar/LoopPredication.cpp index 2df69acc7bf..017bf21d233 100644 --- a/lib/Transforms/Scalar/LoopPredication.cpp +++ b/lib/Transforms/Scalar/LoopPredication.cpp @@ -300,10 +300,6 @@ class LoopPredication { // within the loop. We identify such unprofitable loops through BPI. bool isLoopProfitableToPredicate(); - // Return the loopLatchCheck corresponding to the RangeCheckType if safe to do - // so. - Optional generateLoopLatchCheck(Type *RangeCheckType); - public: LoopPredication(AliasAnalysis *AA, ScalarEvolution *SE, BranchProbabilityInfo *BPI) @@ -426,9 +422,10 @@ Value *LoopPredication::expandCheck(SCEVExpander &Expander, // sext(x + y) is same as sext(x) + sext(y). // This function returns true if we can safely represent the IV type in // the RangeCheckType without loss of information. -bool isSafeToTruncateWideIVType(const DataLayout &DL, ScalarEvolution &SE, - const LoopICmp LatchCheck, - Type *RangeCheckType) { +static bool isSafeToTruncateWideIVType(const DataLayout &DL, + ScalarEvolution &SE, + const LoopICmp LatchCheck, + Type *RangeCheckType) { if (!EnableIVTruncation) return false; assert(DL.getTypeSizeInBits(LatchCheck.IV->getType()) > @@ -458,26 +455,30 @@ bool isSafeToTruncateWideIVType(const DataLayout &DL, ScalarEvolution &SE, } -Optional -LoopPredication::generateLoopLatchCheck(Type *RangeCheckType) { +// Return an LoopICmp describing a latch check equivlent to LatchCheck but with +// the requested type if safe to do so. May involve the use of a new IV. +static Optional generateLoopLatchCheck(const DataLayout &DL, + ScalarEvolution &SE, + const LoopICmp LatchCheck, + Type *RangeCheckType) { auto *LatchType = LatchCheck.IV->getType(); if (RangeCheckType == LatchType) return LatchCheck; // For now, bail out if latch type is narrower than range type. - if (DL->getTypeSizeInBits(LatchType) < DL->getTypeSizeInBits(RangeCheckType)) + if (DL.getTypeSizeInBits(LatchType) < DL.getTypeSizeInBits(RangeCheckType)) return None; - if (!isSafeToTruncateWideIVType(*DL, *SE, LatchCheck, RangeCheckType)) + if (!isSafeToTruncateWideIVType(DL, SE, LatchCheck, RangeCheckType)) return None; // We can now safely identify the truncated version of the IV and limit for // RangeCheckType. LoopICmp NewLatchCheck; NewLatchCheck.Pred = LatchCheck.Pred; NewLatchCheck.IV = dyn_cast( - SE->getTruncateExpr(LatchCheck.IV, RangeCheckType)); + SE.getTruncateExpr(LatchCheck.IV, RangeCheckType)); if (!NewLatchCheck.IV) return None; - NewLatchCheck.Limit = SE->getTruncateExpr(LatchCheck.Limit, RangeCheckType); + NewLatchCheck.Limit = SE.getTruncateExpr(LatchCheck.Limit, RangeCheckType); LLVM_DEBUG(dbgs() << "IV of type: " << *LatchType << "can be represented as range check type:" << *RangeCheckType << "\n"); @@ -693,7 +694,7 @@ Optional LoopPredication::widenICmpRangeCheck(ICmpInst *ICI, return None; } auto *Ty = RangeCheckIV->getType(); - auto CurrLatchCheckOpt = generateLoopLatchCheck(Ty); + auto CurrLatchCheckOpt = generateLoopLatchCheck(*DL, *SE, LatchCheck, Ty); if (!CurrLatchCheckOpt) { LLVM_DEBUG(dbgs() << "Failed to generate a loop latch check " "corresponding to range type: "