diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Target/X86/X86TargetTransformInfo.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp index a79a48ef579..0010423bc76 100644 --- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp +++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp @@ -612,9 +612,18 @@ int X86TTIImpl::getArithmeticInstrCost( }; // Look for XOP lowering tricks. - if (ST->hasXOP()) - if (const auto *Entry = CostTableLookup(XOPShiftCostTable, ISD, LT.second)) + if (ST->hasXOP()) { + // If the right shift is constant then we'll fold the negation so + // it's as cheap as a left shift. + int ShiftISD = ISD; + if ((ShiftISD == ISD::SRL || ShiftISD == ISD::SRA) && + (Op2Info == TargetTransformInfo::OK_UniformConstantValue || + Op2Info == TargetTransformInfo::OK_NonUniformConstantValue)) + ShiftISD = ISD::SHL; + if (const auto *Entry = + CostTableLookup(XOPShiftCostTable, ShiftISD, LT.second)) return LT.first * Entry->Cost; + } static const CostTblEntry SSE2UniformShiftCostTable[] = { // Uniform splats are cheaper for the following instructions. |