Skip to content

Commit

Permalink
[CostModel][X86] X86TTIImpl::getCmpSelInstrCost - try to use Predicat…
Browse files Browse the repository at this point in the history
…e argument directly first (PR48337)

There's still a lot of cases where getCmpSelInstrCost fails to specify a predicate, once those are in place we should be able to remove the fallback to the Instruction argument entirely.
  • Loading branch information
RKSimon committed Oct 3, 2021
1 parent d6482df commit b85bf52
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions llvm/lib/Target/X86/X86TargetTransformInfo.cpp
Expand Up @@ -2420,13 +2420,21 @@ InstructionCost X86TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
assert(ISD && "Invalid opcode");

unsigned ExtraCost = 0;
if (I && (Opcode == Instruction::ICmp || Opcode == Instruction::FCmp)) {
if (Opcode == Instruction::ICmp || Opcode == Instruction::FCmp) {
// Some vector comparison predicates cost extra instructions.
// TODO: Should we invert this and assume worst case cmp costs
// and reduce for particular predicates?
if (MTy.isVector() &&
!((ST->hasXOP() && (!ST->hasAVX2() || MTy.is128BitVector())) ||
(ST->hasAVX512() && 32 <= MTy.getScalarSizeInBits()) ||
ST->hasBWI())) {
switch (cast<CmpInst>(I)->getPredicate()) {
// Fallback to I if a specific predicate wasn't specified.
CmpInst::Predicate Pred = VecPred;
if (I && (Pred == CmpInst::BAD_ICMP_PREDICATE ||
Pred == CmpInst::BAD_FCMP_PREDICATE))
Pred = cast<CmpInst>(I)->getPredicate();

switch (Pred) {
case CmpInst::Predicate::ICMP_NE:
// xor(cmpeq(x,y),-1)
ExtraCost = 1;
Expand Down

0 comments on commit b85bf52

Please sign in to comment.