diff options
Diffstat (limited to 'llvm/lib/Target/X86/X86ISelLowering.cpp')
-rw-r--r-- | llvm/lib/Target/X86/X86ISelLowering.cpp | 63 |
1 files changed, 37 insertions, 26 deletions
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index c11598f2eb4..9351a7cbc7e 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -41060,10 +41060,6 @@ SDValue X86TargetLowering::PerformDAGCombine(SDNode *N, return SDValue(); } -/// Return true if the target has native support for the specified value type -/// and it is 'desirable' to use the type for the given node type. e.g. On x86 -/// i16 is legal, but undesirable since i16 instruction encodings are longer and -/// some i16 instructions are slow. bool X86TargetLowering::isTypeDesirableForOp(unsigned Opc, EVT VT) const { if (!isTypeLegal(VT)) return false; @@ -41072,26 +41068,37 @@ bool X86TargetLowering::isTypeDesirableForOp(unsigned Opc, EVT VT) const { if (Opc == ISD::SHL && VT.isVector() && VT.getVectorElementType() == MVT::i8) return false; - if (VT != MVT::i16) - return true; - - switch (Opc) { - default: - return true; - case ISD::LOAD: - case ISD::SIGN_EXTEND: - case ISD::ZERO_EXTEND: - case ISD::ANY_EXTEND: - case ISD::SHL: - case ISD::SRL: - case ISD::SUB: - case ISD::ADD: - case ISD::MUL: - case ISD::AND: - case ISD::OR: - case ISD::XOR: + // 8-bit multiply is probably not much cheaper than 32-bit multiply, and + // we have specializations to turn 32-bit multiply into LEA or other ops. + // Also, see the comment in "IsDesirableToPromoteOp" - where we additionally + // check for a constant operand to the multiply. + if (Opc == ISD::MUL && VT == MVT::i8) return false; + + // i16 instruction encodings are longer and some i16 instructions are slow, + // so those are not desirable. + if (VT == MVT::i16) { + switch (Opc) { + default: + break; + case ISD::LOAD: + case ISD::SIGN_EXTEND: + case ISD::ZERO_EXTEND: + case ISD::ANY_EXTEND: + case ISD::SHL: + case ISD::SRL: + case ISD::SUB: + case ISD::ADD: + case ISD::MUL: + case ISD::AND: + case ISD::OR: + case ISD::XOR: + return false; + } } + + // Any legal type not explicitly accounted for above here is desirable. + return true; } SDValue X86TargetLowering::expandIndirectJTBranch(const SDLoc& dl, @@ -41110,12 +41117,16 @@ SDValue X86TargetLowering::expandIndirectJTBranch(const SDLoc& dl, return TargetLowering::expandIndirectJTBranch(dl, Value, Addr, DAG); } -/// This method query the target whether it is beneficial for dag combiner to -/// promote the specified node. If true, it should return the desired promotion -/// type by reference. bool X86TargetLowering::IsDesirableToPromoteOp(SDValue Op, EVT &PVT) const { EVT VT = Op.getValueType(); - if (VT != MVT::i16) + bool Is8BitMulByConstant = VT == MVT::i8 && Op.getOpcode() == ISD::MUL && + isa<ConstantSDNode>(Op.getOperand(1)); + + // i16 is legal, but undesirable since i16 instruction encodings are longer + // and some i16 instructions are slow. + // 8-bit multiply-by-constant can usually be expanded to something cheaper + // using LEA and/or other ALU ops. + if (VT != MVT::i16 && !Is8BitMulByConstant) return false; auto IsFoldableRMW = [](SDValue Load, SDValue Op) { |