-
Notifications
You must be signed in to change notification settings - Fork 14.3k
IVDescriptors: improve readability of a function (NFC) #106219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Express a long condtional in terms of an xor, and avoid dereferencing operand to llvm::isa.
@llvm/pr-subscribers-llvm-analysis Author: Ramkumar Ramachandra (artagnon) ChangesExpress a long condtional in terms of an xor, and avoid dereferencing operand to llvm::isa. Full diff: https://github.com/llvm/llvm-project/pull/106219.diff 1 Files Affected:
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);
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't recommend the xor change. Compilers are good at making that change, people are bad at recognising the pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM,thanks!
Avoid dereferencing operand to llvm::isa.