diff options
| author | David Green <david.green@arm.com> | 2019-10-11 20:33:03 +0000 | 
|---|---|---|
| committer | David Green <david.green@arm.com> | 2019-10-11 20:33:03 +0000 | 
| commit | 7c30af8e65904bc2eb7e8926c7d2a2ad68aeab4d (patch) | |
| tree | ea2eca9816d1aac65ebc4fa6cdbe6195ff342231 /llvm/lib/CodeGen | |
| parent | f30ae7173958681b4b639e82e6530b3b047c1fde (diff) | |
| download | bcm5719-llvm-7c30af8e65904bc2eb7e8926c7d2a2ad68aeab4d.tar.gz bcm5719-llvm-7c30af8e65904bc2eb7e8926c7d2a2ad68aeab4d.zip | |
Revert 374373: [Codegen] Alter the default promotion for saturating adds and subs
This commit is not extending the promoted integers as it should. Reverting
whilst I look into the details.
llvm-svn: 374592
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp | 92 | 
1 files changed, 31 insertions, 61 deletions
| diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp index 3c8f63e46bc..e094981a191 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp @@ -642,78 +642,48 @@ SDValue DAGTypeLegalizer::PromoteIntRes_Overflow(SDNode *N) {  }  SDValue DAGTypeLegalizer::PromoteIntRes_ADDSUBSAT(SDNode *N) { -  // If the promoted type is legal, we can convert this to: -  //   1. ANY_EXTEND iN to iM -  //   2. SHL by M-N -  //   3. [US][ADD|SUB]SAT -  //   4. L/ASHR by M-N -  // Else it is more efficient to convert this to a min and a max -  // operation in the higher precision arithmetic. +  // For promoting iN -> iM, this can be expanded by +  // 1. ANY_EXTEND iN to iM +  // 2. SHL by M-N +  // 3. [US][ADD|SUB]SAT +  // 4. L/ASHR by M-N    SDLoc dl(N);    SDValue Op1 = N->getOperand(0);    SDValue Op2 = N->getOperand(1);    unsigned OldBits = Op1.getScalarValueSizeInBits();    unsigned Opcode = N->getOpcode(); +  unsigned ShiftOp; +  switch (Opcode) { +  case ISD::SADDSAT: +  case ISD::SSUBSAT: +    ShiftOp = ISD::SRA; +    break; +  case ISD::UADDSAT: +  case ISD::USUBSAT: +    ShiftOp = ISD::SRL; +    break; +  default: +    llvm_unreachable("Expected opcode to be signed or unsigned saturation " +                     "addition or subtraction"); +  }    SDValue Op1Promoted = GetPromotedInteger(Op1);    SDValue Op2Promoted = GetPromotedInteger(Op2); +    EVT PromotedType = Op1Promoted.getValueType();    unsigned NewBits = PromotedType.getScalarSizeInBits(); - -  if (TLI.isOperationLegalOrCustom(Opcode, PromotedType)) { -    unsigned ShiftOp; -    switch (Opcode) { -    case ISD::SADDSAT: -    case ISD::SSUBSAT: -      ShiftOp = ISD::SRA; -      break; -    case ISD::UADDSAT: -    case ISD::USUBSAT: -      ShiftOp = ISD::SRL; -      break; -    default: -      llvm_unreachable("Expected opcode to be signed or unsigned saturation " -                       "addition or subtraction"); -    } - -    unsigned SHLAmount = NewBits - OldBits; -    EVT SHVT = TLI.getShiftAmountTy(PromotedType, DAG.getDataLayout()); -    SDValue ShiftAmount = DAG.getConstant(SHLAmount, dl, SHVT); -    Op1Promoted = -        DAG.getNode(ISD::SHL, dl, PromotedType, Op1Promoted, ShiftAmount); -    Op2Promoted = -        DAG.getNode(ISD::SHL, dl, PromotedType, Op2Promoted, ShiftAmount); - -    SDValue Result = -        DAG.getNode(Opcode, dl, PromotedType, Op1Promoted, Op2Promoted); -    return DAG.getNode(ShiftOp, dl, PromotedType, Result, ShiftAmount); -  } else { -    if (Opcode == ISD::USUBSAT) { -      SDValue Max = -          DAG.getNode(ISD::UMAX, dl, PromotedType, Op1Promoted, Op2Promoted); -      return DAG.getNode(ISD::SUB, dl, PromotedType, Max, Op2Promoted); -    } - -    if (Opcode == ISD::UADDSAT) { -      APInt MaxVal = APInt::getAllOnesValue(OldBits).zext(NewBits); -      SDValue SatMax = DAG.getConstant(MaxVal, dl, PromotedType); -      SDValue Add = -          DAG.getNode(ISD::ADD, dl, PromotedType, Op1Promoted, Op2Promoted); -      return DAG.getNode(ISD::UMIN, dl, PromotedType, Add, SatMax); -    } - -    unsigned AddOp = Opcode == ISD::SADDSAT ? ISD::ADD : ISD::SUB; -    APInt MinVal = APInt::getSignedMinValue(OldBits).sext(NewBits); -    APInt MaxVal = APInt::getSignedMaxValue(OldBits).sext(NewBits); -    SDValue SatMin = DAG.getConstant(MinVal, dl, PromotedType); -    SDValue SatMax = DAG.getConstant(MaxVal, dl, PromotedType); -    SDValue Result = -        DAG.getNode(AddOp, dl, PromotedType, Op1Promoted, Op2Promoted); -    Result = DAG.getNode(ISD::SMIN, dl, PromotedType, Result, SatMax); -    Result = DAG.getNode(ISD::SMAX, dl, PromotedType, Result, SatMin); -    return Result; -  } +  unsigned SHLAmount = NewBits - OldBits; +  EVT SHVT = TLI.getShiftAmountTy(PromotedType, DAG.getDataLayout()); +  SDValue ShiftAmount = DAG.getConstant(SHLAmount, dl, SHVT); +  Op1Promoted = +      DAG.getNode(ISD::SHL, dl, PromotedType, Op1Promoted, ShiftAmount); +  Op2Promoted = +      DAG.getNode(ISD::SHL, dl, PromotedType, Op2Promoted, ShiftAmount); + +  SDValue Result = +      DAG.getNode(Opcode, dl, PromotedType, Op1Promoted, Op2Promoted); +  return DAG.getNode(ShiftOp, dl, PromotedType, Result, ShiftAmount);  }  SDValue DAGTypeLegalizer::PromoteIntRes_MULFIX(SDNode *N) { | 

