Skip to content

Commit e827fe0

Browse files
committed
[CostModel][X86] Fix constant vector XOP rights shifts
We'll constant fold these cases so they are as cheap as vector left shift cases. Noticed while improving funnel shift costs. llvm-svn: 346760
1 parent 86ed347 commit e827fe0

File tree

3 files changed

+82
-89
lines changed

3 files changed

+82
-89
lines changed

llvm/lib/Target/X86/X86TargetTransformInfo.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,18 @@ int X86TTIImpl::getArithmeticInstrCost(
612612
};
613613

614614
// Look for XOP lowering tricks.
615-
if (ST->hasXOP())
616-
if (const auto *Entry = CostTableLookup(XOPShiftCostTable, ISD, LT.second))
615+
if (ST->hasXOP()) {
616+
// If the right shift is constant then we'll fold the negation so
617+
// it's as cheap as a left shift.
618+
int ShiftISD = ISD;
619+
if ((ShiftISD == ISD::SRL || ShiftISD == ISD::SRA) &&
620+
(Op2Info == TargetTransformInfo::OK_UniformConstantValue ||
621+
Op2Info == TargetTransformInfo::OK_NonUniformConstantValue))
622+
ShiftISD = ISD::SHL;
623+
if (const auto *Entry =
624+
CostTableLookup(XOPShiftCostTable, ShiftISD, LT.second))
617625
return LT.first * Entry->Cost;
626+
}
618627

619628
static const CostTblEntry SSE2UniformShiftCostTable[] = {
620629
// Uniform splats are cheaper for the following instructions.

0 commit comments

Comments
 (0)