[llvm] [HashRecognize] Prevent values other than `ComputedValue` from exiting loop (PR #213080)

Sean Clarke via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 31 06:57:09 PDT 2026


================
@@ -578,15 +578,15 @@ std::variant<PolynomialInfo, StringRef> HashRecognize::recognizeCRC() const {
                    : LHS->getType()->getIntegerBitWidth()))
     return "Loop iterations exceed bitwidth of data";
 
-  // Make sure that the computed value is used in the exit block: this should be
-  // true even if it is only really used in an outer loop's exit block, since
-  // the loop is in LCSSA form.
   auto *ComputedValue = cast<SelectInst>(ConditionalRecurrence.Step);
-  if (none_of(ComputedValue->users(), [Exit](User *U) {
-        auto *UI = dyn_cast<Instruction>(U);
-        return UI && UI->getParent() == Exit;
+
+  // Ensure nothing other than the computed value makes its way out of the loop.
+  // Since the loop is in LCSSA form, this is as simple as checking the PHI
+  // nodes in the exit block.
+  if (any_of(Exit->phis(), [Latch, ComputedValue](PHINode &PN) {
+        return PN.getIncomingValueForBlock(Latch) != ComputedValue;
----------------
xarkenz wrote:

Every PHI node must have an incoming value from each predecessor block, no? Wouldn't the loop structure guarantee that the `Latch` block is a predecessor of the `Exit` block?

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


More information about the llvm-commits mailing list