Index: llvm/include/llvm/Analysis/TargetTransformInfo.h =================================================================== --- llvm/include/llvm/Analysis/TargetTransformInfo.h +++ llvm/include/llvm/Analysis/TargetTransformInfo.h @@ -95,7 +95,7 @@ /// Attributes of a target dependent hardware loop. struct HardwareLoopInfo { HardwareLoopInfo() = delete; - HardwareLoopInfo(Loop *L) : L(L) {} + HardwareLoopInfo(Loop *L); Loop *L = nullptr; BasicBlock *ExitBlock = nullptr; BranchInst *ExitBranch = nullptr; Index: llvm/lib/Analysis/TargetTransformInfo.cpp =================================================================== --- llvm/lib/Analysis/TargetTransformInfo.cpp +++ llvm/lib/Analysis/TargetTransformInfo.cpp @@ -53,16 +53,6 @@ }; } // namespace -bool HardwareLoopInfo::canAnalyze(LoopInfo &LI) { - // If the loop has irreducible control flow, it can not be converted to - // Hardware loop. - LoopBlocksRPO RPOT(L); - RPOT.perform(&LI); - if (containsIrreducibleCFG(RPOT, LI)) - return false; - return true; -} - IntrinsicCostAttributes::IntrinsicCostAttributes( Intrinsic::ID Id, const CallBase &CI, InstructionCost ScalarizationCost, bool TypeBasedOnly) @@ -108,6 +98,24 @@ Arguments.insert(Arguments.begin(), Args.begin(), Args.end()); } +HardwareLoopInfo::HardwareLoopInfo(Loop *L) : L(L) { + // Match default options: + // - hardware-loop-counter-bitwidth = 32 + // - hardware-loop-decrement = 1 + CountType = Type::getInt32Ty(L->getHeader()->getContext()); + LoopDecrement = ConstantInt::get(CountType, 1); +} + +bool HardwareLoopInfo::canAnalyze(LoopInfo &LI) { + // If the loop has irreducible control flow, it can not be converted to + // Hardware loop. + LoopBlocksRPO RPOT(L); + RPOT.perform(&LI); + if (containsIrreducibleCFG(RPOT, LI)) + return false; + return true; +} + bool HardwareLoopInfo::isHardwareLoopCandidate(ScalarEvolution &SE, LoopInfo &LI, DominatorTree &DT, bool ForceNestedLoop,