|
18 | 18 | #include "llvm/CodeGen/BasicTTIImpl.h"
|
19 | 19 | #include "llvm/CodeGen/CostTable.h"
|
20 | 20 | #include "llvm/CodeGen/TargetLowering.h"
|
| 21 | +#include "llvm/IR/DerivedTypes.h" |
21 | 22 | #include "llvm/IR/IntrinsicInst.h"
|
22 | 23 | #include "llvm/IR/Intrinsics.h"
|
23 | 24 | #include "llvm/Support/Debug.h"
|
@@ -1323,25 +1324,21 @@ SystemZTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
|
1323 | 1324 | }
|
1324 | 1325 |
|
1325 | 1326 | bool SystemZTTIImpl::shouldExpandReduction(const IntrinsicInst *II) const {
|
1326 |
| - // Always expand on Subtargets without vector instructions |
| 1327 | + // Always expand on Subtargets without vector instructions. |
1327 | 1328 | if (!ST->hasVector())
|
1328 | 1329 | return true;
|
1329 | 1330 |
|
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. |
1339 | 1332 | 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; |
1344 | 1333 | default:
|
1345 | 1334 | 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; |
1346 | 1343 | }
|
1347 | 1344 | }
|
0 commit comments