diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h --- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -22,8 +22,11 @@ #include "llvm/IR/GetElementPtrTypeIterator.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Operator.h" +#include "llvm/IR/PatternMatch.h" #include "llvm/IR/Type.h" +using namespace llvm::PatternMatch; + namespace llvm { /// Base class for use as a mix-in that aids implementing @@ -990,6 +993,18 @@ CostKind, I); } case Instruction::Select: { + const Value *Op0, *Op1; + if (match(U, m_LogicalAnd(m_Value(Op0), m_Value(Op1))) || + match(U, m_LogicalOr(m_Value(Op0), m_Value(Op1)))) { + TTI::OperandValueProperties Op1VP = TTI::OP_None; + TTI::OperandValueProperties Op2VP = TTI::OP_None; + TTI::OperandValueKind Op1VK = TTI::getOperandInfo(Op0, Op1VP); + TTI::OperandValueKind Op2VK = TTI::getOperandInfo(Op1, Op2VP); + SmallVector Operands{Op0, Op1}; + return TargetTTI->getArithmeticInstrCost( + match(U, m_LogicalOr()) ? Instruction::Or : Instruction::And, + Ty, CostKind, Op1VK, Op2VK, Op1VP, Op2VP, Operands, I); + } Type *CondTy = U->getOperand(0)->getType(); return TargetTTI->getCmpSelInstrCost(Opcode, U->getType(), CondTy, CmpInst::BAD_ICMP_PREDICATE,