[llvm] [IVDescriptors] Call getOpcode on demand in getReductionOpChain. nfc (PR #118777)
Mel Chen via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 30 00:12:27 PDT 2025
https://github.com/Mel-Chen updated https://github.com/llvm/llvm-project/pull/118777
>From c458e9e6ac4f167ccaf7a69c8e2215d3e9a009ed Mon Sep 17 00:00:00 2001
From: Mel Chen <mel.chen at sifive.com>
Date: Thu, 5 Dec 2024 01:34:22 -0800
Subject: [PATCH 1/2] [IVDescriptors][NFC] Refactor getReductionOpChain to
remove the dependency of non-arithmetic reductions on getOpcode.
---
llvm/include/llvm/Analysis/IVDescriptors.h | 3 +++
llvm/lib/Analysis/IVDescriptors.cpp | 8 ++++++--
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/Analysis/IVDescriptors.h b/llvm/include/llvm/Analysis/IVDescriptors.h
index 140edff13a67f..b221ff2017ef6 100644
--- a/llvm/include/llvm/Analysis/IVDescriptors.h
+++ b/llvm/include/llvm/Analysis/IVDescriptors.h
@@ -232,6 +232,9 @@ class RecurrenceDescriptor {
/// Returns true if the recurrence kind is a floating point kind.
static bool isFloatingPointRecurrenceKind(RecurKind Kind);
+ /// Returns true if the recurrence kind is arithmetic.
+ static bool isArithmeticRecurrenceKind(RecurKind Kind);
+
/// Returns true if the recurrence kind is an integer min/max kind.
static bool isIntMinMaxRecurrenceKind(RecurKind Kind) {
return Kind == RecurKind::UMin || Kind == RecurKind::UMax ||
diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index 76552e7488eb5..831b67ceb6912 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -62,6 +62,11 @@ bool RecurrenceDescriptor::isFloatingPointRecurrenceKind(RecurKind Kind) {
return (Kind != RecurKind::None) && !isIntegerRecurrenceKind(Kind);
}
+bool RecurrenceDescriptor::isArithmeticRecurrenceKind(RecurKind Kind) {
+ return (Kind != RecurKind::None) && !isMinMaxRecurrenceKind(Kind) &&
+ !isAnyOfRecurrenceKind(Kind);
+}
+
/// Determines if Phi may have been type-promoted. If Phi has a single user
/// that ANDs the Phi with a type mask, return the user. RT is updated to
/// account for the narrower bit width represented by the mask, and the AND
@@ -1189,7 +1194,6 @@ unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) {
SmallVector<Instruction *, 4>
RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
SmallVector<Instruction *, 4> ReductionOperations;
- unsigned RedOp = getOpcode();
const bool IsMinMax = isMinMaxRecurrenceKind(Kind);
// Search down from the Phi to the LoopExitInstr, looking for instructions
@@ -1237,7 +1241,7 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
if (isFMulAddIntrinsic(Cur))
return true;
- return Cur->getOpcode() == RedOp;
+ return Cur->getOpcode() == getOpcode();
};
// Attempt to look through Phis which are part of the reduction chain
>From 137c6c4e9b97ac0b0a6fc4964ba2525367d403f8 Mon Sep 17 00:00:00 2001
From: Mel Chen <mel.chen at sifive.com>
Date: Mon, 24 Mar 2025 02:46:10 -0700
Subject: [PATCH 2/2] Rebase, and remove isArithmeticRecurrenceKind
---
llvm/include/llvm/Analysis/IVDescriptors.h | 3 ---
llvm/lib/Analysis/IVDescriptors.cpp | 5 -----
2 files changed, 8 deletions(-)
diff --git a/llvm/include/llvm/Analysis/IVDescriptors.h b/llvm/include/llvm/Analysis/IVDescriptors.h
index b221ff2017ef6..140edff13a67f 100644
--- a/llvm/include/llvm/Analysis/IVDescriptors.h
+++ b/llvm/include/llvm/Analysis/IVDescriptors.h
@@ -232,9 +232,6 @@ class RecurrenceDescriptor {
/// Returns true if the recurrence kind is a floating point kind.
static bool isFloatingPointRecurrenceKind(RecurKind Kind);
- /// Returns true if the recurrence kind is arithmetic.
- static bool isArithmeticRecurrenceKind(RecurKind Kind);
-
/// Returns true if the recurrence kind is an integer min/max kind.
static bool isIntMinMaxRecurrenceKind(RecurKind Kind) {
return Kind == RecurKind::UMin || Kind == RecurKind::UMax ||
diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index 831b67ceb6912..a216b0347b9fa 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -62,11 +62,6 @@ bool RecurrenceDescriptor::isFloatingPointRecurrenceKind(RecurKind Kind) {
return (Kind != RecurKind::None) && !isIntegerRecurrenceKind(Kind);
}
-bool RecurrenceDescriptor::isArithmeticRecurrenceKind(RecurKind Kind) {
- return (Kind != RecurKind::None) && !isMinMaxRecurrenceKind(Kind) &&
- !isAnyOfRecurrenceKind(Kind);
-}
-
/// Determines if Phi may have been type-promoted. If Phi has a single user
/// that ANDs the Phi with a type mask, return the user. RT is updated to
/// account for the narrower bit width represented by the mask, and the AND
More information about the llvm-commits
mailing list