Skip to content

[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

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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...

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will add the .

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;
}
Copy link
Contributor

@JonPsson1 JonPsson1 Apr 17, 2024

Choose a reason for hiding this comment

The 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 -> !

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

}