[llvm] [ValueTracking] Support GEPs in matchSimpleRecurrence. (PR #123518)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 28 21:06:40 PST 2025


================
@@ -9240,6 +9262,20 @@ bool llvm::matchSimpleRecurrence(const PHINode *P, BinaryOperator *&BO,
 
       break; // Match!
     }
+    case Instruction::GetElementPtr: {
+      Value *LL;
+      Value *LR;
+      if (!match(L, m_PtrAdd(m_Value(LL), m_Value(LR))))
+        continue;
+
+      // Find a recurrence.
+      if (LL == P) {
+        // Found a match
+        L = LR;
+        break;
+      }
+      continue;
----------------
dtcxzyw wrote:

```suggestion
      Value *LR;
      if (match(L, m_PtrAdd(m_Specific(P), m_Value(LR)))) {
        // Found a match
        L = LR;
        break;
      }
      continue;
```


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


More information about the llvm-commits mailing list