diff options
| author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2018-05-09 12:48:22 +0000 |
|---|---|---|
| committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2018-05-09 12:48:22 +0000 |
| commit | f384bc716638d94406658be70c3ece82670905c9 (patch) | |
| tree | 2ef45aeb607ddb6d5caa08922d3bb6d48cf5c35c /llvm/lib | |
| parent | 3934dba059ef27a207150a0f5892ad9616aff61a (diff) | |
| download | bcm5719-llvm-f384bc716638d94406658be70c3ece82670905c9.tar.gz bcm5719-llvm-f384bc716638d94406658be70c3ece82670905c9.zip | |
[AArch64] Improve cost of vector division by constant
With custom lowering for vector MULLH{S,U}, it is now profitable to
vectorize a divide by constant loop for the custom types (v16i8, v8i16,
and v4i32). The cost if based on TargetLowering::Build{S,U}DIV which
uses a multiply by constant plus adjustment to express a divide by
constant.
Both {u,s}mull{2} are expressed as Instruction::Mul and shifts by
Instruction::AShr.
llvm-svn: 331873
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp index 316ea048436..098272dc2e2 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -520,6 +520,28 @@ int AArch64TTIImpl::getArithmeticInstrCost( } LLVM_FALLTHROUGH; case ISD::UDIV: + if (Opd2Info == TargetTransformInfo::OK_UniformConstantValue) { + auto VT = TLI->getValueType(DL, Ty); + if (TLI->isOperationLegalOrCustom(ISD::MULHU, VT)) { + // Vector signed division by constant are expanded to the + // sequence MULHS + ADD/SUB + SRA + SRL + ADD, and unsigned division + // to MULHS + SUB + SRL + ADD + SRL. + int MulCost = getArithmeticInstrCost(Instruction::Mul, Ty, Opd1Info, + Opd2Info, + TargetTransformInfo::OP_None, + TargetTransformInfo::OP_None); + int AddCost = getArithmeticInstrCost(Instruction::Add, Ty, Opd1Info, + Opd2Info, + TargetTransformInfo::OP_None, + TargetTransformInfo::OP_None); + int ShrCost = getArithmeticInstrCost(Instruction::AShr, Ty, Opd1Info, + Opd2Info, + TargetTransformInfo::OP_None, + TargetTransformInfo::OP_None); + return MulCost * 2 + AddCost * 2 + ShrCost * 2 + 1; + } + } + Cost += BaseT::getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info, Opd1PropInfo, Opd2PropInfo); if (Ty->isVectorTy()) { |

