diff options
author | Jingyue Wu <jingyue@google.com> | 2014-11-12 06:58:45 +0000 |
---|---|---|
committer | Jingyue Wu <jingyue@google.com> | 2014-11-12 06:58:45 +0000 |
commit | 635a9b14fa91dcd6aedadb37aa232c24817e76cd (patch) | |
tree | dce9946fbf1faad094e29f38bdb80476b24f16b4 /llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp | |
parent | 83a63877dc4ebfc2db71539a7be559205f6f547c (diff) | |
download | bcm5719-llvm-635a9b14fa91dcd6aedadb37aa232c24817e76cd.tar.gz bcm5719-llvm-635a9b14fa91dcd6aedadb37aa232c24817e76cd.zip |
Disable indvar widening if arithmetics on the wider type are more expensive
Summary:
IndVarSimplify should not widen an indvar if arithmetics on the wider
indvar are more expensive than those on the narrower indvar. For
instance, although NVPTX64 treats i64 as a legal type, an ADD on i64 is
twice as expensive as that on i32, because the hardware needs to
simulate a 64-bit integer using two 32-bit integers.
Split from D6188, and based on D6195 which adds NVPTXTargetTransformInfo.
Fixes PR21148.
Test Plan:
Added @indvar_32_bit that verifies we do not widen an indvar if the arithmetics
on the wider type are more expensive.
Reviewers: jholewinski, eliben, meheff, atrick
Reviewed By: atrick
Subscribers: jholewinski, llvm-commits
Differential Revision: http://reviews.llvm.org/D6196
llvm-svn: 221772
Diffstat (limited to 'llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp')
-rw-r--r-- | llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp b/llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp index bcac6392a67..5aea7021e42 100644 --- a/llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp @@ -36,12 +36,14 @@ void initializeNVPTXTTIPass(PassRegistry &); namespace { class NVPTXTTI final : public ImmutablePass, public TargetTransformInfo { + const NVPTXTargetLowering *TLI; public: - NVPTXTTI() : ImmutablePass(ID) { + NVPTXTTI() : ImmutablePass(ID), TLI(nullptr) { llvm_unreachable("This pass cannot be directly constructed"); } - NVPTXTTI(const NVPTXTargetMachine *TM) : ImmutablePass(ID) { + NVPTXTTI(const NVPTXTargetMachine *TM) + : ImmutablePass(ID), TLI(TM->getSubtargetImpl()->getTargetLowering()) { initializeNVPTXTTIPass(*PassRegistry::getPassRegistry()); } @@ -63,6 +65,12 @@ public: bool hasBranchDivergence() const override; + unsigned getArithmeticInstrCost( + unsigned Opcode, Type *Ty, OperandValueKind Opd1Info = OK_AnyValue, + OperandValueKind Opd2Info = OK_AnyValue, + OperandValueProperties Opd1PropInfo = OP_None, + OperandValueProperties Opd2PropInfo = OP_None) const override; + /// @} }; @@ -78,3 +86,32 @@ llvm::createNVPTXTargetTransformInfoPass(const NVPTXTargetMachine *TM) { } bool NVPTXTTI::hasBranchDivergence() const { return true; } + +unsigned NVPTXTTI::getArithmeticInstrCost( + unsigned Opcode, Type *Ty, OperandValueKind Opd1Info, + OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo, + OperandValueProperties Opd2PropInfo) const { + // Legalize the type. + std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(Ty); + + int ISD = TLI->InstructionOpcodeToISD(Opcode); + + switch (ISD) { + default: + return TargetTransformInfo::getArithmeticInstrCost( + Opcode, Ty, Opd1Info, Opd2Info, Opd1PropInfo, Opd2PropInfo); + case ISD::ADD: + case ISD::MUL: + case ISD::XOR: + case ISD::OR: + case ISD::AND: + // The machine code (SASS) simulates an i64 with two i32. Therefore, we + // estimate that arithmetic operations on i64 are twice as expensive as + // those on types that can fit into one machine register. + if (LT.second.SimpleTy == MVT::i64) + return 2 * LT.first; + // Delegate other cases to the basic TTI. + return TargetTransformInfo::getArithmeticInstrCost( + Opcode, Ty, Opd1Info, Opd2Info, Opd1PropInfo, Opd2PropInfo); + } +} |