[llvm] [Analysis][LV] Handle FMinNum/FMaxNum in RecurrenceDescriptor::getOpcode (PR #152794)
Uyiosa Iyekekpolor via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 8 13:56:20 PDT 2025
https://github.com/uyoyo0 created https://github.com/llvm/llvm-project/pull/152794
Modify `RecurrenceDescriptor::getOpcode` to handle `RecurKind::FMinNum` and `RecurKind::FMaxNum` by returning `Instruction::FCmp`, matching `FMin/FMax`.
Without these cases, querying the opcode for minNum/maxNum reductions can hit `llvm_unreachable` in code that inspects the recurrence kind. Also added `IVDescriptorsTest.GetOpcodeForFMinMaxNum` (gtest) to verify the mapping.
>From 75a591bc318f451978e53fa03dfd701118da3ca2 Mon Sep 17 00:00:00 2001
From: Uyiosa Iyekekpolor <uyoyo at Uyiosas-Mac-mini.local>
Date: Fri, 8 Aug 2025 16:04:49 -0400
Subject: [PATCH] [Analysis][LV] Handle FMinNum/FMaxNum in
RecurrenceDescriptor::getOpcode
Teach getOpcode to return FCmp for FMinNum/FMaxNum. Without these cases, passes that query the opcode for minNum/maxNum reductions can hit llvm_unreachable. Add a unit test to cover both enums.
---
llvm/lib/Analysis/IVDescriptors.cpp | 2 ++
llvm/unittests/Analysis/IVDescriptorsTest.cpp | 9 +++++++++
2 files changed, 11 insertions(+)
diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index 8be5de3bf356f..efb6a5e97bc2b 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -1228,6 +1228,8 @@ unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) {
return Instruction::ICmp;
case RecurKind::FMax:
case RecurKind::FMin:
+ case RecurKind::FMaxNum:
+ case RecurKind::FMinNum:
case RecurKind::FMaximum:
case RecurKind::FMinimum:
case RecurKind::FMaximumNum:
diff --git a/llvm/unittests/Analysis/IVDescriptorsTest.cpp b/llvm/unittests/Analysis/IVDescriptorsTest.cpp
index 453800abf9cab..bc237296a36b1 100644
--- a/llvm/unittests/Analysis/IVDescriptorsTest.cpp
+++ b/llvm/unittests/Analysis/IVDescriptorsTest.cpp
@@ -259,3 +259,12 @@ for.end:
EXPECT_EQ(Kind, RecurKind::FMax);
});
}
+
+TEST(IVDescriptorsTest, GetOpcodeForFMinMaxNum) {
+ using RK = RecurKind;
+ // Ensure the "num" variants map to the same opcode as the plain ones.
+ EXPECT_EQ(RecurrenceDescriptor::getOpcode(RK::FMinNum),
+ RecurrenceDescriptor::getOpcode(RK::FMin));
+ EXPECT_EQ(RecurrenceDescriptor::getOpcode(RK::FMinNum),
+ RecurrenceDescriptor::getOpcode(RK::FMin));
+}
More information about the llvm-commits
mailing list