[llvm] [HashRecognize] Fix compiler hang on dense use-def chain (PR #211711)

Sean Clarke via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 24 07:29:00 PDT 2026


https://github.com/xarkenz updated https://github.com/llvm/llvm-project/pull/211711

>From 8801002f8c972f65bb35cc23977ca7ef35f951c4 Mon Sep 17 00:00:00 2001
From: Sean Clarke <sclarke at tenstorrent.com>
Date: Thu, 23 Jul 2026 21:32:24 -0500
Subject: [PATCH 1/3] Fix hang on dense use-def chains in HashRecognize

---
 llvm/lib/Analysis/HashRecognize.cpp           |  18 +-
 .../Analysis/HashRecognize/dig-recurrence.ll  | 171 ++++++++++++++++++
 2 files changed, 187 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/Analysis/HashRecognize/dig-recurrence.ll

diff --git a/llvm/lib/Analysis/HashRecognize.cpp b/llvm/lib/Analysis/HashRecognize.cpp
index d29742ef571bd..e1c6269e49556 100644
--- a/llvm/lib/Analysis/HashRecognize.cpp
+++ b/llvm/lib/Analysis/HashRecognize.cpp
@@ -233,10 +233,16 @@ bool RecurrenceInfo::matchSimpleRecurrence(const PHINode *P) {
 BinaryOperator *
 RecurrenceInfo::digRecurrence(Instruction *V,
                               Instruction::BinaryOps BOWithConstOpToMatch) {
+  LLVM_DEBUG(dbgs() << DEBUG_TYPE " Digging for recurrence starting with %"
+                    << V->getName() << ":\n");
   SmallVector<Instruction *> Worklist;
   Worklist.push_back(V);
+  SmallPtrSet<Instruction *, 16> Visited;
   while (!Worklist.empty()) {
     Instruction *I = Worklist.pop_back_val();
+    // Skip this instruction if we have already visited it before.
+    if (!Visited.insert(I).second)
+      continue;
 
     // Don't add a PHI's operands to the Worklist.
     if (isa<PHINode>(I))
@@ -244,13 +250,20 @@ RecurrenceInfo::digRecurrence(Instruction *V,
 
     // Find a recurrence over a BinOp, by matching either of its operands
     // with with the PHINode.
-    if (match(I, m_c_BinOp(m_Value(), m_Specific(Phi))))
+    if (match(I, m_c_BinOp(m_Value(), m_Specific(Phi)))) {
+      LLVM_DEBUG(dbgs() << DEBUG_TYPE
+                 "  Found recurrence over binary operator %"
+                        << I->getName() << "\n");
       return cast<BinaryOperator>(I);
+    }
 
     // Bind to ExtraConst, if we match exactly one.
     if (I->getOpcode() == BOWithConstOpToMatch) {
-      if (ExtraConst)
+      if (ExtraConst) {
+        LLVM_DEBUG(dbgs() << DEBUG_TYPE
+                   "  No recurrence found (>1 ExtraConst)\n");
         return nullptr;
+      }
       const APInt *C = nullptr;
       if (match(I, m_c_BinOp(m_APInt(C), m_Value())))
         ExtraConst = *C;
@@ -262,6 +275,7 @@ RecurrenceInfo::digRecurrence(Instruction *V,
         if (L.contains(UI))
           Worklist.push_back(UI);
   }
+  LLVM_DEBUG(dbgs() << DEBUG_TYPE "  No recurrence found (worklist empty)\n");
   return nullptr;
 }
 
diff --git a/llvm/test/Analysis/HashRecognize/dig-recurrence.ll b/llvm/test/Analysis/HashRecognize/dig-recurrence.ll
new file mode 100644
index 0000000000000..12c2368301c13
--- /dev/null
+++ b/llvm/test/Analysis/HashRecognize/dig-recurrence.ll
@@ -0,0 +1,171 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -passes='print<hash-recognize>' -disable-output %s 2>&1 | FileCheck %s
+
+; This loop hangs if digRecurrence doesn't keep track of previously visited
+; instructions since most instructions have multiple uses.
+define void @dense_use_def_chain() {
+; CHECK-LABEL: 'dense_use_def_chain'
+; CHECK-NEXT:  Did not find a hash algorithm
+; CHECK-NEXT:  Reason: Unable to find conditional recurrence
+;
+bbl:
+  %load = load i32, ptr null, align 4
+  %sitofp = sitofp i32 %load to float
+  br label %bbl1
+
+bbl1:                                             ; preds = %bbl1, %bbl
+  %phi = phi i32 [ 0, %bbl ], [ %add, %bbl1 ]
+  %phi2 = phi float [ poison, %bbl ], [ %select144, %bbl1 ]
+  %fcmp = fcmp une float %phi2, 0.000000e+00
+  %select = select i1 %fcmp, float %sitofp, float %phi2
+  %fcmp3 = fcmp une float %select, 0.000000e+00
+  %select4 = select i1 %fcmp3, float %sitofp, float %select
+  %fcmp5 = fcmp une float %select4, 0.000000e+00
+  %select6 = select i1 %fcmp5, float %sitofp, float %select4
+  %fcmp7 = fcmp une float %select6, 0.000000e+00
+  %select8 = select i1 %fcmp7, float %sitofp, float %select6
+  %fcmp9 = fcmp une float %select8, 0.000000e+00
+  %select10 = select i1 %fcmp9, float %sitofp, float %select8
+  %fcmp11 = fcmp une float %select10, 0.000000e+00
+  %select12 = select i1 %fcmp11, float %sitofp, float %select10
+  %fcmp13 = fcmp une float %select12, 0.000000e+00
+  %select14 = select i1 %fcmp13, float %sitofp, float %select12
+  %fcmp15 = fcmp une float %select14, 0.000000e+00
+  %select16 = select i1 %fcmp15, float %sitofp, float %select14
+  %fcmp17 = fcmp une float %select16, 0.000000e+00
+  %select18 = select i1 %fcmp17, float %sitofp, float %select16
+  %fcmp19 = fcmp une float %select18, 0.000000e+00
+  %select20 = select i1 %fcmp19, float %sitofp, float %select18
+  %fcmp21 = fcmp une float %select20, 0.000000e+00
+  %select22 = select i1 %fcmp21, float %sitofp, float %select20
+  %fcmp23 = fcmp une float %select22, 0.000000e+00
+  %select24 = select i1 %fcmp23, float %sitofp, float %select22
+  %fcmp25 = fcmp une float %select24, 0.000000e+00
+  %select26 = select i1 %fcmp25, float %sitofp, float %select24
+  %fcmp27 = fcmp une float %select26, 0.000000e+00
+  %select28 = select i1 %fcmp27, float %sitofp, float %select26
+  %fcmp29 = fcmp une float %select28, 0.000000e+00
+  %select30 = select i1 %fcmp29, float %sitofp, float %select28
+  %fcmp31 = fcmp une float %select30, 0.000000e+00
+  %select32 = select i1 %fcmp31, float %sitofp, float %select30
+  %fcmp33 = fcmp une float %select32, 0.000000e+00
+  %select34 = select i1 %fcmp33, float %sitofp, float %select32
+  %fcmp35 = fcmp une float %select34, 0.000000e+00
+  %select36 = select i1 %fcmp35, float %sitofp, float %select34
+  %fcmp37 = fcmp une float %select36, 0.000000e+00
+  %select38 = select i1 %fcmp37, float %sitofp, float %select36
+  %fcmp39 = fcmp une float %select38, 0.000000e+00
+  %select40 = select i1 %fcmp39, float %sitofp, float %select38
+  %fcmp41 = fcmp une float %select40, 0.000000e+00
+  %select42 = select i1 %fcmp41, float %sitofp, float %select40
+  %fcmp43 = fcmp une float %select42, 0.000000e+00
+  %select44 = select i1 %fcmp43, float %sitofp, float %select42
+  %fcmp45 = fcmp une float %select44, 0.000000e+00
+  %select46 = select i1 %fcmp45, float %sitofp, float %select44
+  %fcmp47 = fcmp une float %select46, 0.000000e+00
+  %select48 = select i1 %fcmp47, float %sitofp, float %select46
+  %fcmp49 = fcmp une float %select48, 0.000000e+00
+  %select50 = select i1 %fcmp49, float %sitofp, float %select48
+  %fcmp51 = fcmp une float %select50, 0.000000e+00
+  %select52 = select i1 %fcmp51, float %sitofp, float %select50
+  %fcmp53 = fcmp une float %select52, 0.000000e+00
+  %select54 = select i1 %fcmp53, float %sitofp, float %select52
+  %fcmp55 = fcmp une float %select54, 0.000000e+00
+  %select56 = select i1 %fcmp55, float %sitofp, float %select54
+  %fcmp57 = fcmp une float %select56, 0.000000e+00
+  %select58 = select i1 %fcmp57, float %sitofp, float %select56
+  %fcmp59 = fcmp une float %select58, 0.000000e+00
+  %select60 = select i1 %fcmp59, float %sitofp, float %select58
+  %fcmp61 = fcmp une float %select60, 0.000000e+00
+  %select62 = select i1 %fcmp61, float %sitofp, float %select60
+  %fcmp63 = fcmp une float %select62, 0.000000e+00
+  %select64 = select i1 %fcmp63, float %sitofp, float %select62
+  %fcmp65 = fcmp une float %select64, 0.000000e+00
+  %select66 = select i1 %fcmp65, float %sitofp, float %select64
+  %fcmp67 = fcmp une float %select66, 0.000000e+00
+  %select68 = select i1 %fcmp67, float %sitofp, float %select66
+  %fcmp69 = fcmp une float %select68, 0.000000e+00
+  %select70 = select i1 %fcmp69, float %sitofp, float %select68
+  %fcmp71 = fcmp une float %select70, 0.000000e+00
+  %select72 = select i1 %fcmp71, float %sitofp, float %select70
+  %fcmp73 = fcmp une float %select72, 0.000000e+00
+  %select74 = select i1 %fcmp73, float %sitofp, float %select72
+  %fcmp75 = fcmp une float %select74, 0.000000e+00
+  %select76 = select i1 %fcmp75, float %sitofp, float %select74
+  %fcmp77 = fcmp une float %select76, 0.000000e+00
+  %select78 = select i1 %fcmp77, float %sitofp, float %select76
+  %fcmp79 = fcmp une float %select78, 0.000000e+00
+  %select80 = select i1 %fcmp79, float %sitofp, float %select78
+  %fcmp81 = fcmp une float %select80, 0.000000e+00
+  %select82 = select i1 %fcmp81, float %sitofp, float %select80
+  %fcmp83 = fcmp une float %select82, 0.000000e+00
+  %select84 = select i1 %fcmp83, float %sitofp, float %select82
+  %fcmp85 = fcmp une float %select84, 0.000000e+00
+  %select86 = select i1 %fcmp85, float %sitofp, float %select84
+  %fcmp87 = fcmp une float %select86, 0.000000e+00
+  %select88 = select i1 %fcmp87, float %sitofp, float %select86
+  %fcmp89 = fcmp une float %select88, 0.000000e+00
+  %select90 = select i1 %fcmp89, float %sitofp, float %select88
+  %fcmp91 = fcmp une float %select90, 0.000000e+00
+  %select92 = select i1 %fcmp91, float %sitofp, float %select90
+  %fcmp93 = fcmp une float %select92, 0.000000e+00
+  %select94 = select i1 %fcmp93, float %sitofp, float %select92
+  %fcmp95 = fcmp une float %select94, 0.000000e+00
+  %select96 = select i1 %fcmp95, float %sitofp, float %select94
+  %fcmp97 = fcmp une float %select96, 0.000000e+00
+  %select98 = select i1 %fcmp97, float %sitofp, float %select96
+  %fcmp99 = fcmp une float %select98, 0.000000e+00
+  %select100 = select i1 %fcmp99, float %sitofp, float %select98
+  %fcmp101 = fcmp une float %select100, 0.000000e+00
+  %select102 = select i1 %fcmp101, float %sitofp, float %select100
+  %fcmp103 = fcmp une float %select102, 0.000000e+00
+  %select104 = select i1 %fcmp103, float %sitofp, float %select102
+  %fcmp105 = fcmp une float %select104, 0.000000e+00
+  %select106 = select i1 %fcmp105, float %sitofp, float %select104
+  %fcmp107 = fcmp une float %select106, 0.000000e+00
+  %select108 = select i1 %fcmp107, float %sitofp, float %select106
+  %fcmp109 = fcmp une float %select108, 0.000000e+00
+  %select110 = select i1 %fcmp109, float %sitofp, float %select108
+  %fcmp111 = fcmp une float %select110, 0.000000e+00
+  %select112 = select i1 %fcmp111, float %sitofp, float %select110
+  %fcmp113 = fcmp une float %select112, 0.000000e+00
+  %select114 = select i1 %fcmp113, float %sitofp, float %select112
+  %fcmp115 = fcmp une float %select114, 0.000000e+00
+  %select116 = select i1 %fcmp115, float %sitofp, float %select114
+  %fcmp117 = fcmp une float %select116, 0.000000e+00
+  %select118 = select i1 %fcmp117, float %sitofp, float %select116
+  %fcmp119 = fcmp une float %select118, 0.000000e+00
+  %select120 = select i1 %fcmp119, float %sitofp, float %select118
+  %fcmp121 = fcmp une float %select120, 0.000000e+00
+  %select122 = select i1 %fcmp121, float %sitofp, float %select120
+  %fcmp123 = fcmp une float %select122, 0.000000e+00
+  %select124 = select i1 %fcmp123, float %sitofp, float %select122
+  %fcmp125 = fcmp une float %select124, 0.000000e+00
+  %select126 = select i1 %fcmp125, float %sitofp, float %select124
+  %fcmp127 = fcmp une float %select126, 0.000000e+00
+  %select128 = select i1 %fcmp127, float %sitofp, float %select126
+  %fcmp129 = fcmp une float %select128, 0.000000e+00
+  %select130 = select i1 %fcmp129, float %sitofp, float %select128
+  %fcmp131 = fcmp une float %select130, 0.000000e+00
+  %select132 = select i1 %fcmp131, float %sitofp, float %select130
+  %fcmp133 = fcmp une float %select132, 0.000000e+00
+  %select134 = select i1 %fcmp133, float %sitofp, float %select132
+  %fcmp135 = fcmp une float %select134, 0.000000e+00
+  %select136 = select i1 %fcmp135, float %sitofp, float %select134
+  %fcmp137 = fcmp une float %select136, 0.000000e+00
+  %select138 = select i1 %fcmp137, float %sitofp, float %select136
+  %fcmp139 = fcmp une float %select138, 0.000000e+00
+  %select140 = select i1 %fcmp139, float %sitofp, float %select138
+  %fcmp141 = fcmp une float %select140, 0.000000e+00
+  %select142 = select i1 %fcmp141, float %sitofp, float %select140
+  %fcmp143 = fcmp une float %select142, 0.000000e+00
+  %select144 = select i1 %fcmp143, float %sitofp, float %select142
+  %add = add nuw nsw i32 %phi, 1
+  %icmp = icmp eq i32 %add, 3
+  br i1 %icmp, label %bbl145, label %bbl1
+
+bbl145:                                           ; preds = %bbl1
+  %phi146 = phi float [ %select144, %bbl1 ]
+  store float %phi146, ptr null, align 4
+  ret void
+}

>From e6dd3159f77b0d7c4ff1aff4ebec1db326df8393 Mon Sep 17 00:00:00 2001
From: Sean Clarke <sclarke at tenstorrent.com>
Date: Fri, 24 Jul 2026 09:08:34 -0500
Subject: [PATCH 2/3] Strip debug statements, refine test

---
 llvm/lib/Analysis/HashRecognize.cpp           |  16 +-
 .../Analysis/HashRecognize/dig-recurrence.ll  | 315 +++++++++---------
 2 files changed, 159 insertions(+), 172 deletions(-)

diff --git a/llvm/lib/Analysis/HashRecognize.cpp b/llvm/lib/Analysis/HashRecognize.cpp
index e1c6269e49556..1b6a2acc1a584 100644
--- a/llvm/lib/Analysis/HashRecognize.cpp
+++ b/llvm/lib/Analysis/HashRecognize.cpp
@@ -233,11 +233,9 @@ bool RecurrenceInfo::matchSimpleRecurrence(const PHINode *P) {
 BinaryOperator *
 RecurrenceInfo::digRecurrence(Instruction *V,
                               Instruction::BinaryOps BOWithConstOpToMatch) {
-  LLVM_DEBUG(dbgs() << DEBUG_TYPE " Digging for recurrence starting with %"
-                    << V->getName() << ":\n");
   SmallVector<Instruction *> Worklist;
-  Worklist.push_back(V);
   SmallPtrSet<Instruction *, 16> Visited;
+  Worklist.push_back(V);
   while (!Worklist.empty()) {
     Instruction *I = Worklist.pop_back_val();
     // Skip this instruction if we have already visited it before.
@@ -250,20 +248,13 @@ RecurrenceInfo::digRecurrence(Instruction *V,
 
     // Find a recurrence over a BinOp, by matching either of its operands
     // with with the PHINode.
-    if (match(I, m_c_BinOp(m_Value(), m_Specific(Phi)))) {
-      LLVM_DEBUG(dbgs() << DEBUG_TYPE
-                 "  Found recurrence over binary operator %"
-                        << I->getName() << "\n");
+    if (match(I, m_c_BinOp(m_Value(), m_Specific(Phi))))
       return cast<BinaryOperator>(I);
-    }
 
     // Bind to ExtraConst, if we match exactly one.
     if (I->getOpcode() == BOWithConstOpToMatch) {
-      if (ExtraConst) {
-        LLVM_DEBUG(dbgs() << DEBUG_TYPE
-                   "  No recurrence found (>1 ExtraConst)\n");
+      if (ExtraConst)
         return nullptr;
-      }
       const APInt *C = nullptr;
       if (match(I, m_c_BinOp(m_APInt(C), m_Value())))
         ExtraConst = *C;
@@ -275,7 +266,6 @@ RecurrenceInfo::digRecurrence(Instruction *V,
         if (L.contains(UI))
           Worklist.push_back(UI);
   }
-  LLVM_DEBUG(dbgs() << DEBUG_TYPE "  No recurrence found (worklist empty)\n");
   return nullptr;
 }
 
diff --git a/llvm/test/Analysis/HashRecognize/dig-recurrence.ll b/llvm/test/Analysis/HashRecognize/dig-recurrence.ll
index 12c2368301c13..f975f799848cf 100644
--- a/llvm/test/Analysis/HashRecognize/dig-recurrence.ll
+++ b/llvm/test/Analysis/HashRecognize/dig-recurrence.ll
@@ -3,169 +3,166 @@
 
 ; This loop hangs if digRecurrence doesn't keep track of previously visited
 ; instructions since most instructions have multiple uses.
-define void @dense_use_def_chain() {
+define float @dense_use_def_chain(float %f) {
 ; CHECK-LABEL: 'dense_use_def_chain'
 ; CHECK-NEXT:  Did not find a hash algorithm
 ; CHECK-NEXT:  Reason: Unable to find conditional recurrence
 ;
-bbl:
-  %load = load i32, ptr null, align 4
-  %sitofp = sitofp i32 %load to float
-  br label %bbl1
+entry:
+  br label %loop
 
-bbl1:                                             ; preds = %bbl1, %bbl
-  %phi = phi i32 [ 0, %bbl ], [ %add, %bbl1 ]
-  %phi2 = phi float [ poison, %bbl ], [ %select144, %bbl1 ]
-  %fcmp = fcmp une float %phi2, 0.000000e+00
-  %select = select i1 %fcmp, float %sitofp, float %phi2
-  %fcmp3 = fcmp une float %select, 0.000000e+00
-  %select4 = select i1 %fcmp3, float %sitofp, float %select
-  %fcmp5 = fcmp une float %select4, 0.000000e+00
-  %select6 = select i1 %fcmp5, float %sitofp, float %select4
-  %fcmp7 = fcmp une float %select6, 0.000000e+00
-  %select8 = select i1 %fcmp7, float %sitofp, float %select6
-  %fcmp9 = fcmp une float %select8, 0.000000e+00
-  %select10 = select i1 %fcmp9, float %sitofp, float %select8
-  %fcmp11 = fcmp une float %select10, 0.000000e+00
-  %select12 = select i1 %fcmp11, float %sitofp, float %select10
-  %fcmp13 = fcmp une float %select12, 0.000000e+00
-  %select14 = select i1 %fcmp13, float %sitofp, float %select12
-  %fcmp15 = fcmp une float %select14, 0.000000e+00
-  %select16 = select i1 %fcmp15, float %sitofp, float %select14
-  %fcmp17 = fcmp une float %select16, 0.000000e+00
-  %select18 = select i1 %fcmp17, float %sitofp, float %select16
-  %fcmp19 = fcmp une float %select18, 0.000000e+00
-  %select20 = select i1 %fcmp19, float %sitofp, float %select18
-  %fcmp21 = fcmp une float %select20, 0.000000e+00
-  %select22 = select i1 %fcmp21, float %sitofp, float %select20
-  %fcmp23 = fcmp une float %select22, 0.000000e+00
-  %select24 = select i1 %fcmp23, float %sitofp, float %select22
-  %fcmp25 = fcmp une float %select24, 0.000000e+00
-  %select26 = select i1 %fcmp25, float %sitofp, float %select24
-  %fcmp27 = fcmp une float %select26, 0.000000e+00
-  %select28 = select i1 %fcmp27, float %sitofp, float %select26
-  %fcmp29 = fcmp une float %select28, 0.000000e+00
-  %select30 = select i1 %fcmp29, float %sitofp, float %select28
-  %fcmp31 = fcmp une float %select30, 0.000000e+00
-  %select32 = select i1 %fcmp31, float %sitofp, float %select30
-  %fcmp33 = fcmp une float %select32, 0.000000e+00
-  %select34 = select i1 %fcmp33, float %sitofp, float %select32
-  %fcmp35 = fcmp une float %select34, 0.000000e+00
-  %select36 = select i1 %fcmp35, float %sitofp, float %select34
-  %fcmp37 = fcmp une float %select36, 0.000000e+00
-  %select38 = select i1 %fcmp37, float %sitofp, float %select36
-  %fcmp39 = fcmp une float %select38, 0.000000e+00
-  %select40 = select i1 %fcmp39, float %sitofp, float %select38
-  %fcmp41 = fcmp une float %select40, 0.000000e+00
-  %select42 = select i1 %fcmp41, float %sitofp, float %select40
-  %fcmp43 = fcmp une float %select42, 0.000000e+00
-  %select44 = select i1 %fcmp43, float %sitofp, float %select42
-  %fcmp45 = fcmp une float %select44, 0.000000e+00
-  %select46 = select i1 %fcmp45, float %sitofp, float %select44
-  %fcmp47 = fcmp une float %select46, 0.000000e+00
-  %select48 = select i1 %fcmp47, float %sitofp, float %select46
-  %fcmp49 = fcmp une float %select48, 0.000000e+00
-  %select50 = select i1 %fcmp49, float %sitofp, float %select48
-  %fcmp51 = fcmp une float %select50, 0.000000e+00
-  %select52 = select i1 %fcmp51, float %sitofp, float %select50
-  %fcmp53 = fcmp une float %select52, 0.000000e+00
-  %select54 = select i1 %fcmp53, float %sitofp, float %select52
-  %fcmp55 = fcmp une float %select54, 0.000000e+00
-  %select56 = select i1 %fcmp55, float %sitofp, float %select54
-  %fcmp57 = fcmp une float %select56, 0.000000e+00
-  %select58 = select i1 %fcmp57, float %sitofp, float %select56
-  %fcmp59 = fcmp une float %select58, 0.000000e+00
-  %select60 = select i1 %fcmp59, float %sitofp, float %select58
-  %fcmp61 = fcmp une float %select60, 0.000000e+00
-  %select62 = select i1 %fcmp61, float %sitofp, float %select60
-  %fcmp63 = fcmp une float %select62, 0.000000e+00
-  %select64 = select i1 %fcmp63, float %sitofp, float %select62
-  %fcmp65 = fcmp une float %select64, 0.000000e+00
-  %select66 = select i1 %fcmp65, float %sitofp, float %select64
-  %fcmp67 = fcmp une float %select66, 0.000000e+00
-  %select68 = select i1 %fcmp67, float %sitofp, float %select66
-  %fcmp69 = fcmp une float %select68, 0.000000e+00
-  %select70 = select i1 %fcmp69, float %sitofp, float %select68
-  %fcmp71 = fcmp une float %select70, 0.000000e+00
-  %select72 = select i1 %fcmp71, float %sitofp, float %select70
-  %fcmp73 = fcmp une float %select72, 0.000000e+00
-  %select74 = select i1 %fcmp73, float %sitofp, float %select72
-  %fcmp75 = fcmp une float %select74, 0.000000e+00
-  %select76 = select i1 %fcmp75, float %sitofp, float %select74
-  %fcmp77 = fcmp une float %select76, 0.000000e+00
-  %select78 = select i1 %fcmp77, float %sitofp, float %select76
-  %fcmp79 = fcmp une float %select78, 0.000000e+00
-  %select80 = select i1 %fcmp79, float %sitofp, float %select78
-  %fcmp81 = fcmp une float %select80, 0.000000e+00
-  %select82 = select i1 %fcmp81, float %sitofp, float %select80
-  %fcmp83 = fcmp une float %select82, 0.000000e+00
-  %select84 = select i1 %fcmp83, float %sitofp, float %select82
-  %fcmp85 = fcmp une float %select84, 0.000000e+00
-  %select86 = select i1 %fcmp85, float %sitofp, float %select84
-  %fcmp87 = fcmp une float %select86, 0.000000e+00
-  %select88 = select i1 %fcmp87, float %sitofp, float %select86
-  %fcmp89 = fcmp une float %select88, 0.000000e+00
-  %select90 = select i1 %fcmp89, float %sitofp, float %select88
-  %fcmp91 = fcmp une float %select90, 0.000000e+00
-  %select92 = select i1 %fcmp91, float %sitofp, float %select90
-  %fcmp93 = fcmp une float %select92, 0.000000e+00
-  %select94 = select i1 %fcmp93, float %sitofp, float %select92
-  %fcmp95 = fcmp une float %select94, 0.000000e+00
-  %select96 = select i1 %fcmp95, float %sitofp, float %select94
-  %fcmp97 = fcmp une float %select96, 0.000000e+00
-  %select98 = select i1 %fcmp97, float %sitofp, float %select96
-  %fcmp99 = fcmp une float %select98, 0.000000e+00
-  %select100 = select i1 %fcmp99, float %sitofp, float %select98
-  %fcmp101 = fcmp une float %select100, 0.000000e+00
-  %select102 = select i1 %fcmp101, float %sitofp, float %select100
-  %fcmp103 = fcmp une float %select102, 0.000000e+00
-  %select104 = select i1 %fcmp103, float %sitofp, float %select102
-  %fcmp105 = fcmp une float %select104, 0.000000e+00
-  %select106 = select i1 %fcmp105, float %sitofp, float %select104
-  %fcmp107 = fcmp une float %select106, 0.000000e+00
-  %select108 = select i1 %fcmp107, float %sitofp, float %select106
-  %fcmp109 = fcmp une float %select108, 0.000000e+00
-  %select110 = select i1 %fcmp109, float %sitofp, float %select108
-  %fcmp111 = fcmp une float %select110, 0.000000e+00
-  %select112 = select i1 %fcmp111, float %sitofp, float %select110
-  %fcmp113 = fcmp une float %select112, 0.000000e+00
-  %select114 = select i1 %fcmp113, float %sitofp, float %select112
-  %fcmp115 = fcmp une float %select114, 0.000000e+00
-  %select116 = select i1 %fcmp115, float %sitofp, float %select114
-  %fcmp117 = fcmp une float %select116, 0.000000e+00
-  %select118 = select i1 %fcmp117, float %sitofp, float %select116
-  %fcmp119 = fcmp une float %select118, 0.000000e+00
-  %select120 = select i1 %fcmp119, float %sitofp, float %select118
-  %fcmp121 = fcmp une float %select120, 0.000000e+00
-  %select122 = select i1 %fcmp121, float %sitofp, float %select120
-  %fcmp123 = fcmp une float %select122, 0.000000e+00
-  %select124 = select i1 %fcmp123, float %sitofp, float %select122
-  %fcmp125 = fcmp une float %select124, 0.000000e+00
-  %select126 = select i1 %fcmp125, float %sitofp, float %select124
-  %fcmp127 = fcmp une float %select126, 0.000000e+00
-  %select128 = select i1 %fcmp127, float %sitofp, float %select126
-  %fcmp129 = fcmp une float %select128, 0.000000e+00
-  %select130 = select i1 %fcmp129, float %sitofp, float %select128
-  %fcmp131 = fcmp une float %select130, 0.000000e+00
-  %select132 = select i1 %fcmp131, float %sitofp, float %select130
-  %fcmp133 = fcmp une float %select132, 0.000000e+00
-  %select134 = select i1 %fcmp133, float %sitofp, float %select132
-  %fcmp135 = fcmp une float %select134, 0.000000e+00
-  %select136 = select i1 %fcmp135, float %sitofp, float %select134
-  %fcmp137 = fcmp une float %select136, 0.000000e+00
-  %select138 = select i1 %fcmp137, float %sitofp, float %select136
-  %fcmp139 = fcmp une float %select138, 0.000000e+00
-  %select140 = select i1 %fcmp139, float %sitofp, float %select138
-  %fcmp141 = fcmp une float %select140, 0.000000e+00
-  %select142 = select i1 %fcmp141, float %sitofp, float %select140
-  %fcmp143 = fcmp une float %select142, 0.000000e+00
-  %select144 = select i1 %fcmp143, float %sitofp, float %select142
-  %add = add nuw nsw i32 %phi, 1
-  %icmp = icmp eq i32 %add, 3
-  br i1 %icmp, label %bbl145, label %bbl1
+loop:
+  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
+  %ind = phi float [ 0.0, %entry ], [ %ind.next, %loop ]
+  %fcmp = fcmp une float %ind, 0.0
+  %select = select i1 %fcmp, float %f, float %ind
+  %fcmp3 = fcmp une float %select, 0.0
+  %select4 = select i1 %fcmp3, float %f, float %select
+  %fcmp5 = fcmp une float %select4, 0.0
+  %select6 = select i1 %fcmp5, float %f, float %select4
+  %fcmp7 = fcmp une float %select6, 0.0
+  %select8 = select i1 %fcmp7, float %f, float %select6
+  %fcmp9 = fcmp une float %select8, 0.0
+  %select10 = select i1 %fcmp9, float %f, float %select8
+  %fcmp11 = fcmp une float %select10, 0.0
+  %select12 = select i1 %fcmp11, float %f, float %select10
+  %fcmp13 = fcmp une float %select12, 0.0
+  %select14 = select i1 %fcmp13, float %f, float %select12
+  %fcmp15 = fcmp une float %select14, 0.0
+  %select16 = select i1 %fcmp15, float %f, float %select14
+  %fcmp17 = fcmp une float %select16, 0.0
+  %select18 = select i1 %fcmp17, float %f, float %select16
+  %fcmp19 = fcmp une float %select18, 0.0
+  %select20 = select i1 %fcmp19, float %f, float %select18
+  %fcmp21 = fcmp une float %select20, 0.0
+  %select22 = select i1 %fcmp21, float %f, float %select20
+  %fcmp23 = fcmp une float %select22, 0.0
+  %select24 = select i1 %fcmp23, float %f, float %select22
+  %fcmp25 = fcmp une float %select24, 0.0
+  %select26 = select i1 %fcmp25, float %f, float %select24
+  %fcmp27 = fcmp une float %select26, 0.0
+  %select28 = select i1 %fcmp27, float %f, float %select26
+  %fcmp29 = fcmp une float %select28, 0.0
+  %select30 = select i1 %fcmp29, float %f, float %select28
+  %fcmp31 = fcmp une float %select30, 0.0
+  %select32 = select i1 %fcmp31, float %f, float %select30
+  %fcmp33 = fcmp une float %select32, 0.0
+  %select34 = select i1 %fcmp33, float %f, float %select32
+  %fcmp35 = fcmp une float %select34, 0.0
+  %select36 = select i1 %fcmp35, float %f, float %select34
+  %fcmp37 = fcmp une float %select36, 0.0
+  %select38 = select i1 %fcmp37, float %f, float %select36
+  %fcmp39 = fcmp une float %select38, 0.0
+  %select40 = select i1 %fcmp39, float %f, float %select38
+  %fcmp41 = fcmp une float %select40, 0.0
+  %select42 = select i1 %fcmp41, float %f, float %select40
+  %fcmp43 = fcmp une float %select42, 0.0
+  %select44 = select i1 %fcmp43, float %f, float %select42
+  %fcmp45 = fcmp une float %select44, 0.0
+  %select46 = select i1 %fcmp45, float %f, float %select44
+  %fcmp47 = fcmp une float %select46, 0.0
+  %select48 = select i1 %fcmp47, float %f, float %select46
+  %fcmp49 = fcmp une float %select48, 0.0
+  %select50 = select i1 %fcmp49, float %f, float %select48
+  %fcmp51 = fcmp une float %select50, 0.0
+  %select52 = select i1 %fcmp51, float %f, float %select50
+  %fcmp53 = fcmp une float %select52, 0.0
+  %select54 = select i1 %fcmp53, float %f, float %select52
+  %fcmp55 = fcmp une float %select54, 0.0
+  %select56 = select i1 %fcmp55, float %f, float %select54
+  %fcmp57 = fcmp une float %select56, 0.0
+  %select58 = select i1 %fcmp57, float %f, float %select56
+  %fcmp59 = fcmp une float %select58, 0.0
+  %select60 = select i1 %fcmp59, float %f, float %select58
+  %fcmp61 = fcmp une float %select60, 0.0
+  %select62 = select i1 %fcmp61, float %f, float %select60
+  %fcmp63 = fcmp une float %select62, 0.0
+  %select64 = select i1 %fcmp63, float %f, float %select62
+  %fcmp65 = fcmp une float %select64, 0.0
+  %select66 = select i1 %fcmp65, float %f, float %select64
+  %fcmp67 = fcmp une float %select66, 0.0
+  %select68 = select i1 %fcmp67, float %f, float %select66
+  %fcmp69 = fcmp une float %select68, 0.0
+  %select70 = select i1 %fcmp69, float %f, float %select68
+  %fcmp71 = fcmp une float %select70, 0.0
+  %select72 = select i1 %fcmp71, float %f, float %select70
+  %fcmp73 = fcmp une float %select72, 0.0
+  %select74 = select i1 %fcmp73, float %f, float %select72
+  %fcmp75 = fcmp une float %select74, 0.0
+  %select76 = select i1 %fcmp75, float %f, float %select74
+  %fcmp77 = fcmp une float %select76, 0.0
+  %select78 = select i1 %fcmp77, float %f, float %select76
+  %fcmp79 = fcmp une float %select78, 0.0
+  %select80 = select i1 %fcmp79, float %f, float %select78
+  %fcmp81 = fcmp une float %select80, 0.0
+  %select82 = select i1 %fcmp81, float %f, float %select80
+  %fcmp83 = fcmp une float %select82, 0.0
+  %select84 = select i1 %fcmp83, float %f, float %select82
+  %fcmp85 = fcmp une float %select84, 0.0
+  %select86 = select i1 %fcmp85, float %f, float %select84
+  %fcmp87 = fcmp une float %select86, 0.0
+  %select88 = select i1 %fcmp87, float %f, float %select86
+  %fcmp89 = fcmp une float %select88, 0.0
+  %select90 = select i1 %fcmp89, float %f, float %select88
+  %fcmp91 = fcmp une float %select90, 0.0
+  %select92 = select i1 %fcmp91, float %f, float %select90
+  %fcmp93 = fcmp une float %select92, 0.0
+  %select94 = select i1 %fcmp93, float %f, float %select92
+  %fcmp95 = fcmp une float %select94, 0.0
+  %select96 = select i1 %fcmp95, float %f, float %select94
+  %fcmp97 = fcmp une float %select96, 0.0
+  %select98 = select i1 %fcmp97, float %f, float %select96
+  %fcmp99 = fcmp une float %select98, 0.0
+  %select100 = select i1 %fcmp99, float %f, float %select98
+  %fcmp101 = fcmp une float %select100, 0.0
+  %select102 = select i1 %fcmp101, float %f, float %select100
+  %fcmp103 = fcmp une float %select102, 0.0
+  %select104 = select i1 %fcmp103, float %f, float %select102
+  %fcmp105 = fcmp une float %select104, 0.0
+  %select106 = select i1 %fcmp105, float %f, float %select104
+  %fcmp107 = fcmp une float %select106, 0.0
+  %select108 = select i1 %fcmp107, float %f, float %select106
+  %fcmp109 = fcmp une float %select108, 0.0
+  %select110 = select i1 %fcmp109, float %f, float %select108
+  %fcmp111 = fcmp une float %select110, 0.0
+  %select112 = select i1 %fcmp111, float %f, float %select110
+  %fcmp113 = fcmp une float %select112, 0.0
+  %select114 = select i1 %fcmp113, float %f, float %select112
+  %fcmp115 = fcmp une float %select114, 0.0
+  %select116 = select i1 %fcmp115, float %f, float %select114
+  %fcmp117 = fcmp une float %select116, 0.0
+  %select118 = select i1 %fcmp117, float %f, float %select116
+  %fcmp119 = fcmp une float %select118, 0.0
+  %select120 = select i1 %fcmp119, float %f, float %select118
+  %fcmp121 = fcmp une float %select120, 0.0
+  %select122 = select i1 %fcmp121, float %f, float %select120
+  %fcmp123 = fcmp une float %select122, 0.0
+  %select124 = select i1 %fcmp123, float %f, float %select122
+  %fcmp125 = fcmp une float %select124, 0.0
+  %select126 = select i1 %fcmp125, float %f, float %select124
+  %fcmp127 = fcmp une float %select126, 0.0
+  %select128 = select i1 %fcmp127, float %f, float %select126
+  %fcmp129 = fcmp une float %select128, 0.0
+  %select130 = select i1 %fcmp129, float %f, float %select128
+  %fcmp131 = fcmp une float %select130, 0.0
+  %select132 = select i1 %fcmp131, float %f, float %select130
+  %fcmp133 = fcmp une float %select132, 0.0
+  %select134 = select i1 %fcmp133, float %f, float %select132
+  %fcmp135 = fcmp une float %select134, 0.0
+  %select136 = select i1 %fcmp135, float %f, float %select134
+  %fcmp137 = fcmp une float %select136, 0.0
+  %select138 = select i1 %fcmp137, float %f, float %select136
+  %fcmp139 = fcmp une float %select138, 0.0
+  %select140 = select i1 %fcmp139, float %f, float %select138
+  %fcmp141 = fcmp une float %select140, 0.0
+  %select142 = select i1 %fcmp141, float %f, float %select140
+  %fcmp143 = fcmp une float %select142, 0.0
+  %ind.next = select i1 %fcmp143, float %f, float %select142
+  %iv.next = add nuw nsw i32 %iv, 1
+  %exit.cond = icmp eq i32 %iv.next, 3
+  br i1 %exit.cond, label %exit, label %loop
 
-bbl145:                                           ; preds = %bbl1
-  %phi146 = phi float [ %select144, %bbl1 ]
-  store float %phi146, ptr null, align 4
-  ret void
+exit:
+  %lcssa.phi = phi float [ %ind.next, %loop ]
+  ret float %lcssa.phi
 }

>From 27a4105e3e8717a042adbb10a7a459640d066087 Mon Sep 17 00:00:00 2001
From: Sean Clarke <sclarke at tenstorrent.com>
Date: Fri, 24 Jul 2026 09:27:25 -0500
Subject: [PATCH 3/3] Add instruction to entry block in test

---
 llvm/test/Analysis/HashRecognize/dig-recurrence.ll | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/test/Analysis/HashRecognize/dig-recurrence.ll b/llvm/test/Analysis/HashRecognize/dig-recurrence.ll
index f975f799848cf..e404b08b4afa4 100644
--- a/llvm/test/Analysis/HashRecognize/dig-recurrence.ll
+++ b/llvm/test/Analysis/HashRecognize/dig-recurrence.ll
@@ -3,12 +3,13 @@
 
 ; This loop hangs if digRecurrence doesn't keep track of previously visited
 ; instructions since most instructions have multiple uses.
-define float @dense_use_def_chain(float %f) {
+define float @dense_use_def_chain(float %src) {
 ; CHECK-LABEL: 'dense_use_def_chain'
 ; CHECK-NEXT:  Did not find a hash algorithm
 ; CHECK-NEXT:  Reason: Unable to find conditional recurrence
 ;
 entry:
+  %f = fneg float %src
   br label %loop
 
 loop:



More information about the llvm-commits mailing list