[llvm] IVDescriptors: improve readability of a function (NFC) (PR #106219)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 28 01:10:55 PDT 2024
https://github.com/artagnon updated https://github.com/llvm/llvm-project/pull/106219
>From 2cddfb529dc30537878b1d26d6b147a680291d4b Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <ramkumar.ramachandra at codasip.com>
Date: Tue, 27 Aug 2024 14:12:04 +0100
Subject: [PATCH 1/2] IVDescriptors: improve readability of a function (NFC)
Express a long condtional in terms of an xor, and avoid dereferencing
operand to llvm::isa.
---
llvm/lib/Analysis/IVDescriptors.cpp | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index ac6df226784345..c4f9785dbc5f66 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -734,13 +734,11 @@ RecurrenceDescriptor::isConditionalRdxPattern(RecurKind Kind, Instruction *I) {
Value *FalseVal = SI->getFalseValue();
// Handle only when either of operands of select instruction is a PHI
// node for now.
- if ((isa<PHINode>(*TrueVal) && isa<PHINode>(*FalseVal)) ||
- (!isa<PHINode>(*TrueVal) && !isa<PHINode>(*FalseVal)))
+ if (!(isa<PHINode>(TrueVal) ^ isa<PHINode>(FalseVal)))
return InstDesc(false, I);
- Instruction *I1 =
- isa<PHINode>(*TrueVal) ? dyn_cast<Instruction>(FalseVal)
- : dyn_cast<Instruction>(TrueVal);
+ Instruction *I1 = isa<PHINode>(TrueVal) ? dyn_cast<Instruction>(FalseVal)
+ : dyn_cast<Instruction>(TrueVal);
if (!I1 || !I1->isBinaryOp())
return InstDesc(false, I);
@@ -754,8 +752,8 @@ RecurrenceDescriptor::isConditionalRdxPattern(RecurKind Kind, Instruction *I) {
(m_Mul(m_Value(Op1), m_Value(Op2)).match(I1))))
return InstDesc(false, I);
- Instruction *IPhi = isa<PHINode>(*Op1) ? dyn_cast<Instruction>(Op1)
- : dyn_cast<Instruction>(Op2);
+ Instruction *IPhi = isa<PHINode>(Op1) ? dyn_cast<Instruction>(Op1)
+ : dyn_cast<Instruction>(Op2);
if (!IPhi || IPhi != FalseVal)
return InstDesc(false, I);
>From 6fed1d03f79539ba0356d5224a2557a19568ec1f Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <ramkumar.ramachandra at codasip.com>
Date: Wed, 28 Aug 2024 09:08:50 +0100
Subject: [PATCH 2/2] IVDescriptors: revert xor change
---
llvm/lib/Analysis/IVDescriptors.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index c4f9785dbc5f66..a021dadc178745 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -734,7 +734,8 @@ RecurrenceDescriptor::isConditionalRdxPattern(RecurKind Kind, Instruction *I) {
Value *FalseVal = SI->getFalseValue();
// Handle only when either of operands of select instruction is a PHI
// node for now.
- if (!(isa<PHINode>(TrueVal) ^ isa<PHINode>(FalseVal)))
+ if ((isa<PHINode>(TrueVal) && isa<PHINode>(FalseVal)) ||
+ (!isa<PHINode>(TrueVal) && !isa<PHINode>(FalseVal)))
return InstDesc(false, I);
Instruction *I1 = isa<PHINode>(TrueVal) ? dyn_cast<Instruction>(FalseVal)
More information about the llvm-commits
mailing list