diff --git a/llvm/lib/CodeGen/HardwareLoops.cpp b/llvm/lib/CodeGen/HardwareLoops.cpp --- a/llvm/lib/CodeGen/HardwareLoops.cpp +++ b/llvm/lib/CodeGen/HardwareLoops.cpp @@ -365,7 +365,13 @@ return false; }; - if (!IsCompareZero(ICmp, Count, 0) && !IsCompareZero(ICmp, Count, 1)) + // Check if Count is a zext. + Value *CountBefZext = + isa(Count) ? cast(Count)->getOperand(0) : nullptr; + + if (!IsCompareZero(ICmp, Count, 0) && !IsCompareZero(ICmp, Count, 1) && + !IsCompareZero(ICmp, CountBefZext, 0) && + !IsCompareZero(ICmp, CountBefZext, 1)) return false; unsigned SuccIdx = ICmp->getPredicate() == ICmpInst::ICMP_NE ? 0 : 1;