@@ -1096,7 +1096,6 @@ bool TargetLowering::SimplifyDemandedBits(
1096
1096
APInt DemandedBits = OriginalDemandedBits;
1097
1097
APInt DemandedElts = OriginalDemandedElts;
1098
1098
SDLoc dl (Op);
1099
- auto &DL = TLO.DAG .getDataLayout ();
1100
1099
1101
1100
// Undef operand.
1102
1101
if (Op.isUndef ())
@@ -2288,9 +2287,8 @@ bool TargetLowering::SimplifyDemandedBits(
2288
2287
// the right place.
2289
2288
unsigned ShiftOpcode = NLZ > NTZ ? ISD::SRL : ISD::SHL;
2290
2289
if (!TLO.LegalOperations () || isOperationLegal (ShiftOpcode, VT)) {
2291
- EVT ShiftAmtTy = getShiftAmountTy (VT, DL);
2292
2290
unsigned ShiftAmount = NLZ > NTZ ? NLZ - NTZ : NTZ - NLZ;
2293
- SDValue ShAmt = TLO.DAG .getConstant (ShiftAmount, dl, ShiftAmtTy );
2291
+ SDValue ShAmt = TLO.DAG .getShiftAmountConstant (ShiftAmount, VT, dl );
2294
2292
SDValue NewOp = TLO.DAG .getNode (ShiftOpcode, dl, VT, Src, ShAmt);
2295
2293
return TLO.CombineTo (Op, NewOp);
2296
2294
}
@@ -2330,8 +2328,8 @@ bool TargetLowering::SimplifyDemandedBits(
2330
2328
if (!AlreadySignExtended) {
2331
2329
// Compute the correct shift amount type, which must be getShiftAmountTy
2332
2330
// for scalar types after legalization.
2333
- SDValue ShiftAmt = TLO. DAG . getConstant (BitWidth - ExVTBits, dl,
2334
- getShiftAmountTy ( VT, DL) );
2331
+ SDValue ShiftAmt =
2332
+ TLO. DAG . getShiftAmountConstant (BitWidth - ExVTBits, VT, dl );
2335
2333
return TLO.CombineTo (Op,
2336
2334
TLO.DAG .getNode (ISD::SHL, dl, VT, Op0, ShiftAmt));
2337
2335
}
@@ -2574,8 +2572,8 @@ bool TargetLowering::SimplifyDemandedBits(
2574
2572
if (!(HighBits & DemandedBits)) {
2575
2573
// None of the shifted in bits are needed. Add a truncate of the
2576
2574
// shift input, then shift it.
2577
- SDValue NewShAmt = TLO. DAG . getConstant (
2578
- ShVal, dl, getShiftAmountTy ( VT, DL , TLO.LegalTypes () ));
2575
+ SDValue NewShAmt =
2576
+ TLO. DAG . getShiftAmountConstant ( ShVal, VT, dl , TLO.LegalTypes ());
2579
2577
SDValue NewTrunc =
2580
2578
TLO.DAG .getNode (ISD::TRUNCATE, dl, VT, Src.getOperand (0 ));
2581
2579
return TLO.CombineTo (
@@ -2753,8 +2751,7 @@ bool TargetLowering::SimplifyDemandedBits(
2753
2751
unsigned CTZ = DemandedBits.countr_zero ();
2754
2752
ConstantSDNode *C = isConstOrConstSplat (Op.getOperand (1 ), DemandedElts);
2755
2753
if (C && C->getAPIntValue ().countr_zero () == CTZ) {
2756
- EVT ShiftAmtTy = getShiftAmountTy (VT, TLO.DAG .getDataLayout ());
2757
- SDValue AmtC = TLO.DAG .getConstant (CTZ, dl, ShiftAmtTy);
2754
+ SDValue AmtC = TLO.DAG .getShiftAmountConstant (CTZ, VT, dl);
2758
2755
SDValue Shl = TLO.DAG .getNode (ISD::SHL, dl, VT, Op.getOperand (0 ), AmtC);
2759
2756
return TLO.CombineTo (Op, Shl);
2760
2757
}
@@ -2852,9 +2849,9 @@ bool TargetLowering::SimplifyDemandedBits(
2852
2849
return 0 ;
2853
2850
};
2854
2851
2855
- auto foldMul = [&](ISD::NodeType NT, SDValue X, SDValue Y, unsigned ShlAmt) {
2856
- EVT ShiftAmtTy = getShiftAmountTy (VT, TLO. DAG . getDataLayout ());
2857
- SDValue ShlAmtC = TLO.DAG .getConstant (ShlAmt, dl, ShiftAmtTy );
2852
+ auto foldMul = [&](ISD::NodeType NT, SDValue X, SDValue Y,
2853
+ unsigned ShlAmt) {
2854
+ SDValue ShlAmtC = TLO.DAG .getShiftAmountConstant (ShlAmt, VT, dl );
2858
2855
SDValue Shl = TLO.DAG .getNode (ISD::SHL, dl, VT, X, ShlAmtC);
2859
2856
SDValue Res = TLO.DAG .getNode (NT, dl, VT, Y, Shl);
2860
2857
return TLO.CombineTo (Op, Res);
@@ -4204,9 +4201,8 @@ SDValue TargetLowering::foldSetCCWithBinOp(EVT VT, SDValue N0, SDValue N1,
4204
4201
return SDValue ();
4205
4202
4206
4203
// (X - Y) == Y --> X == Y << 1
4207
- EVT ShiftVT = getShiftAmountTy (OpVT, DAG.getDataLayout (),
4208
- !DCI.isBeforeLegalize ());
4209
- SDValue One = DAG.getConstant (1 , DL, ShiftVT);
4204
+ SDValue One =
4205
+ DAG.getShiftAmountConstant (1 , OpVT, DL, !DCI.isBeforeLegalize ());
4210
4206
SDValue YShl1 = DAG.getNode (ISD::SHL, DL, N1.getValueType (), Y, One);
4211
4207
if (!DCI.isCalledByLegalizer ())
4212
4208
DCI.AddToWorklist (YShl1.getNode ());
@@ -5038,34 +5034,35 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
5038
5034
(VT == ShValTy || (isTypeLegal (VT) && VT.bitsLE (ShValTy))) &&
5039
5035
N0.getOpcode () == ISD::AND) {
5040
5036
if (auto *AndRHS = dyn_cast<ConstantSDNode>(N0.getOperand (1 ))) {
5041
- EVT ShiftTy =
5042
- getShiftAmountTy (ShValTy, Layout, !DCI.isBeforeLegalize ());
5043
5037
if (Cond == ISD::SETNE && C1 == 0 ) {// (X & 8) != 0 --> (X & 8) >> 3
5044
5038
// Perform the xform if the AND RHS is a single bit.
5045
5039
unsigned ShCt = AndRHS->getAPIntValue ().logBase2 ();
5046
5040
if (AndRHS->getAPIntValue ().isPowerOf2 () &&
5047
5041
!TLI.shouldAvoidTransformToShift (ShValTy, ShCt)) {
5048
- return DAG.getNode (ISD::TRUNCATE, dl, VT,
5049
- DAG.getNode (ISD::SRL, dl, ShValTy, N0,
5050
- DAG.getConstant (ShCt, dl, ShiftTy)));
5042
+ return DAG.getNode (
5043
+ ISD::TRUNCATE, dl, VT,
5044
+ DAG.getNode (ISD::SRL, dl, ShValTy, N0,
5045
+ DAG.getShiftAmountConstant (
5046
+ ShCt, ShValTy, dl, !DCI.isBeforeLegalize ())));
5051
5047
}
5052
5048
} else if (Cond == ISD::SETEQ && C1 == AndRHS->getAPIntValue ()) {
5053
5049
// (X & 8) == 8 --> (X & 8) >> 3
5054
5050
// Perform the xform if C1 is a single bit.
5055
5051
unsigned ShCt = C1.logBase2 ();
5056
5052
if (C1.isPowerOf2 () &&
5057
5053
!TLI.shouldAvoidTransformToShift (ShValTy, ShCt)) {
5058
- return DAG.getNode (ISD::TRUNCATE, dl, VT,
5059
- DAG.getNode (ISD::SRL, dl, ShValTy, N0,
5060
- DAG.getConstant (ShCt, dl, ShiftTy)));
5054
+ return DAG.getNode (
5055
+ ISD::TRUNCATE, dl, VT,
5056
+ DAG.getNode (ISD::SRL, dl, ShValTy, N0,
5057
+ DAG.getShiftAmountConstant (
5058
+ ShCt, ShValTy, dl, !DCI.isBeforeLegalize ())));
5061
5059
}
5062
5060
}
5063
5061
}
5064
5062
}
5065
5063
5066
5064
if (C1.getSignificantBits () <= 64 &&
5067
5065
!isLegalICmpImmediate (C1.getSExtValue ())) {
5068
- EVT ShiftTy = getShiftAmountTy (ShValTy, Layout, !DCI.isBeforeLegalize ());
5069
5066
// (X & -256) == 256 -> (X >> 8) == 1
5070
5067
if ((Cond == ISD::SETEQ || Cond == ISD::SETNE) &&
5071
5068
N0.getOpcode () == ISD::AND && N0.hasOneUse ()) {
@@ -5074,9 +5071,10 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
5074
5071
if (AndRHSC.isNegatedPowerOf2 () && (AndRHSC & C1) == C1) {
5075
5072
unsigned ShiftBits = AndRHSC.countr_zero ();
5076
5073
if (!TLI.shouldAvoidTransformToShift (ShValTy, ShiftBits)) {
5077
- SDValue Shift =
5078
- DAG.getNode (ISD::SRL, dl, ShValTy, N0.getOperand (0 ),
5079
- DAG.getConstant (ShiftBits, dl, ShiftTy));
5074
+ SDValue Shift = DAG.getNode (
5075
+ ISD::SRL, dl, ShValTy, N0.getOperand (0 ),
5076
+ DAG.getShiftAmountConstant (ShiftBits, ShValTy, dl,
5077
+ !DCI.isBeforeLegalize ()));
5080
5078
SDValue CmpRHS = DAG.getConstant (C1.lshr (ShiftBits), dl, ShValTy);
5081
5079
return DAG.getSetCC (dl, VT, Shift, CmpRHS, Cond);
5082
5080
}
@@ -5103,8 +5101,10 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
5103
5101
if (ShiftBits && NewC.getSignificantBits () <= 64 &&
5104
5102
isLegalICmpImmediate (NewC.getSExtValue ()) &&
5105
5103
!TLI.shouldAvoidTransformToShift (ShValTy, ShiftBits)) {
5106
- SDValue Shift = DAG.getNode (ISD::SRL, dl, ShValTy, N0,
5107
- DAG.getConstant (ShiftBits, dl, ShiftTy));
5104
+ SDValue Shift =
5105
+ DAG.getNode (ISD::SRL, dl, ShValTy, N0,
5106
+ DAG.getShiftAmountConstant (ShiftBits, ShValTy, dl,
5107
+ !DCI.isBeforeLegalize ()));
5108
5108
SDValue CmpRHS = DAG.getConstant (NewC, dl, ShValTy);
5109
5109
return DAG.getSetCC (dl, VT, Shift, CmpRHS, NewCond);
5110
5110
}
@@ -8944,7 +8944,6 @@ SDValue TargetLowering::expandABS(SDNode *N, SelectionDAG &DAG,
8944
8944
bool IsNegative) const {
8945
8945
SDLoc dl (N);
8946
8946
EVT VT = N->getValueType (0 );
8947
- EVT ShVT = getShiftAmountTy (VT, DAG.getDataLayout ());
8948
8947
SDValue Op = N->getOperand (0 );
8949
8948
8950
8949
// abs(x) -> smax(x,sub(0,x))
@@ -8982,9 +8981,9 @@ SDValue TargetLowering::expandABS(SDNode *N, SelectionDAG &DAG,
8982
8981
return SDValue ();
8983
8982
8984
8983
Op = DAG.getFreeze (Op);
8985
- SDValue Shift =
8986
- DAG. getNode ( ISD::SRA, dl, VT, Op,
8987
- DAG.getConstant (VT.getScalarSizeInBits () - 1 , dl, ShVT ));
8984
+ SDValue Shift = DAG. getNode (
8985
+ ISD::SRA, dl, VT, Op,
8986
+ DAG.getShiftAmountConstant (VT.getScalarSizeInBits () - 1 , VT, dl ));
8988
8987
SDValue Xor = DAG.getNode (ISD::XOR, dl, VT, Op, Shift);
8989
8988
8990
8989
// abs(x) -> Y = sra (X, size(X)-1); sub (xor (X, Y), Y)
@@ -9592,9 +9591,7 @@ TargetLowering::expandUnalignedLoad(LoadSDNode *LD, SelectionDAG &DAG) const {
9592
9591
}
9593
9592
9594
9593
// aggregate the two parts
9595
- SDValue ShiftAmount =
9596
- DAG.getConstant (NumBits, dl, getShiftAmountTy (Hi.getValueType (),
9597
- DAG.getDataLayout ()));
9594
+ SDValue ShiftAmount = DAG.getShiftAmountConstant (NumBits, VT, dl);
9598
9595
SDValue Result = DAG.getNode (ISD::SHL, dl, VT, Hi, ShiftAmount);
9599
9596
Result = DAG.getNode (ISD::OR, dl, VT, Result, Lo);
9600
9597
@@ -9706,8 +9703,8 @@ SDValue TargetLowering::expandUnalignedStore(StoreSDNode *ST,
9706
9703
unsigned IncrementSize = NumBits / 8 ;
9707
9704
9708
9705
// Divide the stored value in two parts.
9709
- SDValue ShiftAmount = DAG. getConstant (
9710
- NumBits, dl, getShiftAmountTy ( Val.getValueType (), DAG. getDataLayout ()) );
9706
+ SDValue ShiftAmount =
9707
+ DAG. getShiftAmountConstant ( NumBits, Val.getValueType (), dl );
9711
9708
SDValue Lo = Val;
9712
9709
// If Val is a constant, replace the upper bits with 0. The SRL will constant
9713
9710
// fold and not use the upper bits. A smaller constant may be easier to
@@ -10351,9 +10348,8 @@ TargetLowering::expandFixedPointMul(SDNode *Node, SelectionDAG &DAG) const {
10351
10348
// The result will need to be shifted right by the scale since both operands
10352
10349
// are scaled. The result is given to us in 2 halves, so we only want part of
10353
10350
// both in the result.
10354
- EVT ShiftTy = getShiftAmountTy (VT, DAG.getDataLayout ());
10355
10351
SDValue Result = DAG.getNode (ISD::FSHR, dl, VT, Hi, Lo,
10356
- DAG.getConstant (Scale, dl, ShiftTy ));
10352
+ DAG.getShiftAmountConstant (Scale, VT, dl ));
10357
10353
if (!Saturating)
10358
10354
return Result;
10359
10355
@@ -10381,7 +10377,7 @@ TargetLowering::expandFixedPointMul(SDNode *Node, SelectionDAG &DAG) const {
10381
10377
10382
10378
if (Scale == 0 ) {
10383
10379
SDValue Sign = DAG.getNode (ISD::SRA, dl, VT, Lo,
10384
- DAG.getConstant (VTSize - 1 , dl, ShiftTy ));
10380
+ DAG.getShiftAmountConstant (VTSize - 1 , VT, dl ));
10385
10381
SDValue Overflow = DAG.getSetCC (dl, BoolVT, Hi, Sign, ISD::SETNE);
10386
10382
// Saturated to SatMin if wide product is negative, and SatMax if wide
10387
10383
// product is positive ...
@@ -10448,13 +10444,12 @@ TargetLowering::expandFixedPointDiv(unsigned Opcode, const SDLoc &dl,
10448
10444
// RHS down by RHSShift, we can emit a regular division with a final scaling
10449
10445
// factor of Scale.
10450
10446
10451
- EVT ShiftTy = getShiftAmountTy (VT, DAG.getDataLayout ());
10452
10447
if (LHSShift)
10453
10448
LHS = DAG.getNode (ISD::SHL, dl, VT, LHS,
10454
- DAG.getConstant (LHSShift, dl, ShiftTy ));
10449
+ DAG.getShiftAmountConstant (LHSShift, VT, dl ));
10455
10450
if (RHSShift)
10456
10451
RHS = DAG.getNode (Signed ? ISD::SRA : ISD::SRL, dl, VT, RHS,
10457
- DAG.getConstant (RHSShift, dl, ShiftTy ));
10452
+ DAG.getShiftAmountConstant (RHSShift, VT, dl ));
10458
10453
10459
10454
SDValue Quot;
10460
10455
if (Signed) {
@@ -10597,8 +10592,7 @@ bool TargetLowering::expandMULO(SDNode *Node, SDValue &Result,
10597
10592
if (C.isPowerOf2 ()) {
10598
10593
// smulo(x, signed_min) is same as umulo(x, signed_min).
10599
10594
bool UseArithShift = isSigned && !C.isMinSignedValue ();
10600
- EVT ShiftAmtTy = getShiftAmountTy (VT, DAG.getDataLayout ());
10601
- SDValue ShiftAmt = DAG.getConstant (C.logBase2 (), dl, ShiftAmtTy);
10595
+ SDValue ShiftAmt = DAG.getShiftAmountConstant (C.logBase2 (), VT, dl);
10602
10596
Result = DAG.getNode (ISD::SHL, dl, VT, LHS, ShiftAmt);
10603
10597
Overflow = DAG.getSetCC (dl, SetCCVT,
10604
10598
DAG.getNode (UseArithShift ? ISD::SRA : ISD::SRL,
@@ -10630,8 +10624,8 @@ bool TargetLowering::expandMULO(SDNode *Node, SDValue &Result,
10630
10624
RHS = DAG.getNode (Ops[isSigned][2 ], dl, WideVT, RHS);
10631
10625
SDValue Mul = DAG.getNode (ISD::MUL, dl, WideVT, LHS, RHS);
10632
10626
BottomHalf = DAG.getNode (ISD::TRUNCATE, dl, VT, Mul);
10633
- SDValue ShiftAmt = DAG. getConstant (VT. getScalarSizeInBits (), dl,
10634
- getShiftAmountTy (WideVT, DAG.getDataLayout ()) );
10627
+ SDValue ShiftAmt =
10628
+ DAG.getShiftAmountConstant (VT. getScalarSizeInBits (), WideVT, dl );
10635
10629
TopHalf = DAG.getNode (ISD::TRUNCATE, dl, VT,
10636
10630
DAG.getNode (ISD::SRL, dl, WideVT, Mul, ShiftAmt));
10637
10631
} else {
@@ -10643,9 +10637,8 @@ bool TargetLowering::expandMULO(SDNode *Node, SDValue &Result,
10643
10637
10644
10638
Result = BottomHalf;
10645
10639
if (isSigned) {
10646
- SDValue ShiftAmt = DAG.getConstant (
10647
- VT.getScalarSizeInBits () - 1 , dl,
10648
- getShiftAmountTy (BottomHalf.getValueType (), DAG.getDataLayout ()));
10640
+ SDValue ShiftAmt = DAG.getShiftAmountConstant (
10641
+ VT.getScalarSizeInBits () - 1 , BottomHalf.getValueType (), dl);
10649
10642
SDValue Sign = DAG.getNode (ISD::SRA, dl, VT, BottomHalf, ShiftAmt);
10650
10643
Overflow = DAG.getSetCC (dl, SetCCVT, TopHalf, Sign, ISD::SETNE);
10651
10644
} else {
0 commit comments