@@ -187,7 +187,7 @@ namespace {
187187 const DataLayout &DL ,
188188 OptimizationRemarkEmitter *ORE ) :
189189 SE (SE ), DL (DL ), ORE (ORE ), L(Info.L), M(L->getHeader ()->getModule()),
190- ExitCount (Info.ExitCount ),
190+ TripCount (Info.TripCount ),
191191 CountType(Info.CountType),
192192 ExitBranch(Info.ExitBranch),
193193 LoopDecrement(Info.LoopDecrement),
@@ -202,7 +202,7 @@ namespace {
202202 OptimizationRemarkEmitter *ORE = nullptr ;
203203 Loop *L = nullptr ;
204204 Module *M = nullptr ;
205- const SCEV *ExitCount = nullptr ;
205+ const SCEV *TripCount = nullptr ;
206206 Type *CountType = nullptr ;
207207 BranchInst *ExitBranch = nullptr ;
208208 Value *LoopDecrement = nullptr ;
@@ -298,7 +298,7 @@ bool HardwareLoops::TryConvertLoop(HardwareLoopInfo &HWLoopInfo) {
298298 }
299299
300300 assert (
301- (HWLoopInfo.ExitBlock && HWLoopInfo.ExitBranch && HWLoopInfo.ExitCount ) &&
301+ (HWLoopInfo.ExitBlock && HWLoopInfo.ExitBranch && HWLoopInfo.TripCount ) &&
302302 " Hardware Loop must have set exit info." );
303303
304304 BasicBlock *Preheader = L->getLoopPreheader ();
@@ -383,18 +383,13 @@ Value *HardwareLoop::InitLoopCount() {
383383 // loop counter and tests that is not zero?
384384
385385 SCEVExpander SCEVE (SE , DL , " loopcnt" );
386- if (!ExitCount->getType ()->isPointerTy () &&
387- ExitCount->getType () != CountType)
388- ExitCount = SE .getZeroExtendExpr (ExitCount, CountType);
389-
390- ExitCount = SE .getAddExpr (ExitCount, SE .getOne (CountType));
391386
392387 // If we're trying to use the 'test and set' form of the intrinsic, we need
393388 // to replace a conditional branch that is controlling entry to the loop. It
394389 // is likely (guaranteed?) that the preheader has an unconditional branch to
395390 // the loop header, so also check if it has a single predecessor.
396- if (SE .isLoopEntryGuardedByCond (L, ICmpInst::ICMP_NE , ExitCount ,
397- SE .getZero (ExitCount ->getType ()))) {
391+ if (SE .isLoopEntryGuardedByCond (L, ICmpInst::ICMP_NE , TripCount ,
392+ SE .getZero (TripCount ->getType ()))) {
398393 LLVM_DEBUG (dbgs () << " - Attempting to use test.set counter.\n " );
399394 UseLoopGuard |= ForceGuardLoopEntry;
400395 } else
@@ -406,19 +401,19 @@ Value *HardwareLoop::InitLoopCount() {
406401 BasicBlock *Predecessor = BB ->getSinglePredecessor ();
407402 // If it's not safe to create a while loop then don't force it and create a
408403 // do-while loop instead
409- if (!isSafeToExpandAt (ExitCount , Predecessor->getTerminator (), SE ))
404+ if (!isSafeToExpandAt (TripCount , Predecessor->getTerminator (), SE ))
410405 UseLoopGuard = false ;
411406 else
412407 BB = Predecessor;
413408 }
414409
415- if (!isSafeToExpandAt (ExitCount , BB ->getTerminator (), SE )) {
416- LLVM_DEBUG (dbgs () << " - Bailing, unsafe to expand ExitCount "
417- << *ExitCount << " \n " );
410+ if (!isSafeToExpandAt (TripCount , BB ->getTerminator (), SE )) {
411+ LLVM_DEBUG (dbgs () << " - Bailing, unsafe to expand TripCount "
412+ << *TripCount << " \n " );
418413 return nullptr ;
419414 }
420415
421- Value *Count = SCEVE .expandCodeFor (ExitCount , CountType,
416+ Value *Count = SCEVE .expandCodeFor (TripCount , CountType,
422417 BB ->getTerminator ());
423418
424419 // FIXME: We've expanded Count where we hope to insert the counter setting
0 commit comments