[NFCI][LoopIdiom] 'left-shift until bittest': assert that BaseX is loop-invariant
authorRoman Lebedev <lebedev.ri@gmail.com>
Mon, 24 May 2021 09:13:05 +0000 (12:13 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Mon, 24 May 2021 09:15:06 +0000 (12:15 +0300)
Given that BaseX is an incoming value when coming from the preheader,
it *should* be loop-invariant, but let's just document this assumption.

llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp

index 7d14c66..ae8ef00 100644 (file)
@@ -2166,6 +2166,9 @@ static bool detectShiftUntilBitTestIdiom(Loop *CurLoop, Value *&BaseX,
   NextX =
       dyn_cast<Instruction>(CurrXPN->getIncomingValueForBlock(LoopHeaderBB));
 
+  assert(CurLoop->isLoopInvariant(BaseX) &&
+         "Expected BaseX to be avaliable in the preheader!");
+
   if (!NextX || !match(NextX, m_Shl(m_Specific(CurrX), m_One()))) {
     // FIXME: support right-shift?
     LLVM_DEBUG(dbgs() << DEBUG_TYPE " Bad recurrence.\n");