[llvm] [LoopIdiom] Reland: Support 'shift until less-than' idiom #95002 (PR #98298)

Hari Limaye via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 10 07:00:27 PDT 2024


================
@@ -1545,12 +1545,15 @@ static Value *matchShiftULTCondition(BranchInst *BI, BasicBlock *LoopEntry,
   BasicBlock *FalseSucc = BI->getSuccessor(1);
   ICmpInst::Predicate Pred = Cond->getPredicate();
 
-  if (Pred == ICmpInst::ICMP_ULT && FalseSucc == LoopEntry) {
-    Threshold = CmpConst->getZExtValue();
-    return Cond->getOperand(0);
-  }
+  if (Pred != ICmpInst::ICMP_ULT || FalseSucc != LoopEntry)
+    return nullptr;
 
-  return nullptr;
+  std::optional<uint64_t> ValIntOpt = CmpConst->getValue().tryZExtValue();
----------------
hazzlim wrote:

Thanks, I agree that makes far more sense - and is simpler! I've updated to change uint64_t -> APInt where necessary.

I've kept the new test, as it seems somewhat useful to keep a test to verify that this update actually fixes the crash that led to the original patch being reverted. Let me know if you disagree? Thanks :) 

https://github.com/llvm/llvm-project/pull/98298


More information about the llvm-commits mailing list