[llvm] [ValueTracking] Use Instruction instead of Operator in matchSimpleRecurrence. (PR #74678)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 7 09:59:29 PST 2023


https://github.com/topperc updated https://github.com/llvm/llvm-project/pull/74678

>From dbde4164cdc33f8b728c22579a8a93b4289c616b Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Wed, 6 Dec 2023 15:40:53 -0800
Subject: [PATCH 1/2] [ValueTracking] Use Instruction instead of Operator in
 matchSimpleRecurrence.

Operator allows the phi operand to be a ConstantExpr. A ConstantExpr
is a valid operand to a phi, but a ConstantExpr is never going to be a
recurrence. So I think we should use Instruction.
---
 llvm/lib/Analysis/ValueTracking.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index ee4f97f3bf5e0..78b791d1d3b33 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -8024,7 +8024,7 @@ bool llvm::matchSimpleRecurrence(const PHINode *P, BinaryOperator *&BO,
   for (unsigned i = 0; i != 2; ++i) {
     Value *L = P->getIncomingValue(i);
     Value *R = P->getIncomingValue(!i);
-    Operator *LU = dyn_cast<Operator>(L);
+    auto *LU = dyn_cast<Instruction>(L);
     if (!LU)
       continue;
     unsigned Opcode = LU->getOpcode();

>From 80bb0c4deda43fe66d48ada51858aaf1a1e60850 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Thu, 7 Dec 2023 09:58:54 -0800
Subject: [PATCH 2/2] Use BinaryOperator

---
 llvm/lib/Analysis/ValueTracking.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 78b791d1d3b33..97ac13329ebef 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -8024,7 +8024,7 @@ bool llvm::matchSimpleRecurrence(const PHINode *P, BinaryOperator *&BO,
   for (unsigned i = 0; i != 2; ++i) {
     Value *L = P->getIncomingValue(i);
     Value *R = P->getIncomingValue(!i);
-    auto *LU = dyn_cast<Instruction>(L);
+    auto *LU = dyn_cast<BinaryOperator>(L);
     if (!LU)
       continue;
     unsigned Opcode = LU->getOpcode();
@@ -8062,7 +8062,7 @@ bool llvm::matchSimpleRecurrence(const PHINode *P, BinaryOperator *&BO,
     // OR
     //   %iv = [R, %entry], [%iv.next, %backedge]
     //   %iv.next = binop L, %iv
-    BO = cast<BinaryOperator>(LU);
+    BO = LU;
     Start = R;
     Step = L;
     return true;



More information about the llvm-commits mailing list