From: Simon Pilgrim Date: Sun, 3 Oct 2021 16:16:45 +0000 (+0100) Subject: [CostModel][X86] X86TTIImpl::getCmpSelInstrCost - try to use Predicate argument direc... X-Git-Tag: upstream/15.0.7~29782 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b85bf520dcd9a809e3d39d4ec2d7105d9e3cc4ac;p=platform%2Fupstream%2Fllvm.git [CostModel][X86] X86TTIImpl::getCmpSelInstrCost - try to use Predicate 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. --- diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp index a379938..a0a8ff6 100644 --- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp +++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp @@ -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(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(I)->getPredicate(); + + switch (Pred) { case CmpInst::Predicate::ICMP_NE: // xor(cmpeq(x,y),-1) ExtraCost = 1;