-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SystemZ] Fix Operand Retrieval for Vector Reduction Intrinsic in shouldExpandReduction
#88874
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
#include "llvm/CodeGen/BasicTTIImpl.h" | ||
#include "llvm/CodeGen/CostTable.h" | ||
#include "llvm/CodeGen/TargetLowering.h" | ||
#include "llvm/IR/DerivedTypes.h" | ||
#include "llvm/IR/IntrinsicInst.h" | ||
#include "llvm/IR/Intrinsics.h" | ||
#include "llvm/Support/Debug.h" | ||
|
@@ -1323,25 +1324,21 @@ SystemZTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, | |
} | ||
|
||
bool SystemZTTIImpl::shouldExpandReduction(const IntrinsicInst *II) const { | ||
// Always expand on Subtargets without vector instructions | ||
// Always expand on Subtargets without vector instructions. | ||
if (!ST->hasVector()) | ||
return true; | ||
|
||
// Always expand for operands that do not fill one vector reg | ||
auto *Type = cast<FixedVectorType>(II->getOperand(0)->getType()); | ||
unsigned NumElts = Type->getNumElements(); | ||
unsigned ScalarSize = Type->getScalarSizeInBits(); | ||
unsigned MaxElts = SystemZ::VectorBits / ScalarSize; | ||
if (NumElts < MaxElts) | ||
return true; | ||
|
||
// Otherwise | ||
// Whether or not to expand is a per-intrinsic decision. | ||
switch (II->getIntrinsicID()) { | ||
// Do not expand vector.reduce.add | ||
case Intrinsic::vector_reduce_add: | ||
// Except for i64, since the performance benefit is dubious there | ||
return ScalarSize >= 64; | ||
default: | ||
return true; | ||
// Do not expand vector.reduce.add... | ||
case Intrinsic::vector_reduce_add: | ||
auto *VType = cast<FixedVectorType>(II->getOperand(0)->getType()); | ||
// ...unless the scalar size is i64 or larger, | ||
// or the operand vector is not full, since the | ||
// performance benefit is dubious in those cases. | ||
return VType->getScalarSizeInBits() >= 64 || | ||
VType->getPrimitiveSizeInBits() < SystemZ::VectorBits; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isVectorFull: So the idea is that any vectors which are less than one vector should be expanded, but e.g. 1.5 vectors should not be..? Couldn't you then just check if the total size of VType is >= SystemZ::VectorBits? not -> ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, that would be easier. i was thinking in terms of element counts, but we don't really need that. |
||
} |
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.
If this is the only reduction handled, would it simplify to just check against this near the top, and return true for anything else?
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.
That would simplify it, however, the initial intent was that we would probably want to do similar things for other reduction intrinsics in the future, so i wanted it to be a bit more generic.
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 think generally we might want to keep the code as simple as possible until we actually need something more complex. In this case it is slightly confusing to me to go through the switch and all, when there is actually only one intrinsic handled... But not sure if this is just my opinion...
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.
This style of commenting is kind of nice but I find it perhaps a little unusual compared to https://llvm.org/docs/CodingStandards.html#id8. I guess it's up to you how you want to write it, but at the very least add the final period. I think typically the comment for a particular switch case should be in one place, probably all just below the 'case' line.
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 will add the
.