Skip to content

Commit 5af9701

Browse files
[SystemZ] Fix Operand Retrieval for Vector Reduction Intrinsic in shouldExpandReduction (#88874)
In the existing version, SystemZTTIImpl::shouldExpandReduction will create a `cast` error when handling vector reduction intrinsics that do not have the vector to reduce as their first operand, such as `llvm.vector.reduce.fadd` and `llvm.vector.reduce.fmul`. This commit fixes that problem by moving the cast into the case statement that handles the specific intrinsic, where the vector operand position is well-known.
1 parent e7c042f commit 5af9701

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/CodeGen/BasicTTIImpl.h"
1919
#include "llvm/CodeGen/CostTable.h"
2020
#include "llvm/CodeGen/TargetLowering.h"
21+
#include "llvm/IR/DerivedTypes.h"
2122
#include "llvm/IR/IntrinsicInst.h"
2223
#include "llvm/IR/Intrinsics.h"
2324
#include "llvm/Support/Debug.h"
@@ -1323,25 +1324,21 @@ SystemZTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
13231324
}
13241325

13251326
bool SystemZTTIImpl::shouldExpandReduction(const IntrinsicInst *II) const {
1326-
// Always expand on Subtargets without vector instructions
1327+
// Always expand on Subtargets without vector instructions.
13271328
if (!ST->hasVector())
13281329
return true;
13291330

1330-
// Always expand for operands that do not fill one vector reg
1331-
auto *Type = cast<FixedVectorType>(II->getOperand(0)->getType());
1332-
unsigned NumElts = Type->getNumElements();
1333-
unsigned ScalarSize = Type->getScalarSizeInBits();
1334-
unsigned MaxElts = SystemZ::VectorBits / ScalarSize;
1335-
if (NumElts < MaxElts)
1336-
return true;
1337-
1338-
// Otherwise
1331+
// Whether or not to expand is a per-intrinsic decision.
13391332
switch (II->getIntrinsicID()) {
1340-
// Do not expand vector.reduce.add
1341-
case Intrinsic::vector_reduce_add:
1342-
// Except for i64, since the performance benefit is dubious there
1343-
return ScalarSize >= 64;
13441333
default:
13451334
return true;
1335+
// Do not expand vector.reduce.add...
1336+
case Intrinsic::vector_reduce_add:
1337+
auto *VType = cast<FixedVectorType>(II->getOperand(0)->getType());
1338+
// ...unless the scalar size is i64 or larger,
1339+
// or the operand vector is not full, since the
1340+
// performance benefit is dubious in those cases.
1341+
return VType->getScalarSizeInBits() >= 64 ||
1342+
VType->getPrimitiveSizeInBits() < SystemZ::VectorBits;
13461343
}
13471344
}

0 commit comments

Comments
 (0)