From 764309a6cd737b0896bc0271dd245735ac8dd68a Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sun, 27 Apr 2014 18:47:54 +0000 Subject: [PATCH] X86TTI: Adjust sdiv cost now that we can lower it on plain SSE2. Includes a fix for a horrible typo that caused all SDIV costs to be slightly off :) llvm-svn: 207371 --- lib/CodeGen/TargetLoweringBase.cpp | 2 +- lib/Target/X86/X86TargetTransformInfo.cpp | 5 +++++ test/Analysis/CostModel/X86/vdiv-cost.ll | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/CodeGen/TargetLoweringBase.cpp b/lib/CodeGen/TargetLoweringBase.cpp index 47ee2b0988f..978432411ef 100644 --- a/lib/CodeGen/TargetLoweringBase.cpp +++ b/lib/CodeGen/TargetLoweringBase.cpp @@ -1327,7 +1327,7 @@ int TargetLoweringBase::InstructionOpcodeToISD(unsigned Opcode) const { case Mul: return ISD::MUL; case FMul: return ISD::FMUL; case UDiv: return ISD::UDIV; - case SDiv: return ISD::UDIV; + case SDiv: return ISD::SDIV; case FDiv: return ISD::FDIV; case URem: return ISD::UREM; case SRem: return ISD::SREM; diff --git a/lib/Target/X86/X86TargetTransformInfo.cpp b/lib/Target/X86/X86TargetTransformInfo.cpp index 628e9130a15..1543f109b4c 100644 --- a/lib/Target/X86/X86TargetTransformInfo.cpp +++ b/lib/Target/X86/X86TargetTransformInfo.cpp @@ -369,11 +369,16 @@ unsigned X86TTI::getArithmeticInstrCost(unsigned Opcode, Type *Ty, { ISD::SDIV, MVT::v8i16, 6 }, // pmulhw sequence { ISD::UDIV, MVT::v8i16, 6 }, // pmulhuw sequence + { ISD::SDIV, MVT::v4i32, 19 }, // pmuludq sequence { ISD::UDIV, MVT::v4i32, 15 }, // pmuludq sequence }; if (Op2Info == TargetTransformInfo::OK_UniformConstantValue && ST->hasSSE2()) { + // pmuldq sequence. + if (ISD == ISD::SDIV && LT.second == MVT::v4i32 && ST->hasSSE41()) + return LT.first * 15; + int Idx = CostTableLookup(SSE2UniformConstCostTable, ISD, LT.second); if (Idx != -1) return LT.first * SSE2UniformConstCostTable[Idx].Cost; diff --git a/test/Analysis/CostModel/X86/vdiv-cost.ll b/test/Analysis/CostModel/X86/vdiv-cost.ll index 4ba1ef07ad7..c8e4557cbef 100644 --- a/test/Analysis/CostModel/X86/vdiv-cost.ll +++ b/test/Analysis/CostModel/X86/vdiv-cost.ll @@ -69,7 +69,7 @@ define <4 x i32> @test8(<4 x i32> %a) { ret <4 x i32> %div ; CHECK: 'Cost Model Analysis' for function 'test8': -; SSE2: Found an estimated cost of 15 for instruction: %div +; SSE2: Found an estimated cost of 19 for instruction: %div ; AVX2: Found an estimated cost of 15 for instruction: %div } @@ -78,7 +78,7 @@ define <8 x i32> @test9(<8 x i32> %a) { ret <8 x i32> %div ; CHECK: 'Cost Model Analysis' for function 'test9': -; SSE2: Found an estimated cost of 30 for instruction: %div +; SSE2: Found an estimated cost of 38 for instruction: %div ; AVX2: Found an estimated cost of 15 for instruction: %div }