@@ -4395,14 +4395,13 @@ template <class MatchContextClass> SDValue DAGCombiner::visitMUL(SDNode *N) {
4395
4395
// fold (mul x, -(1 << c)) -> -(x << c) or (-x) << c
4396
4396
if (N1IsConst && !N1IsOpaqueConst && ConstValue1.isNegatedPowerOf2()) {
4397
4397
unsigned Log2Val = (-ConstValue1).logBase2();
4398
- EVT ShiftVT = getShiftAmountTy(N0.getValueType());
4399
4398
4400
4399
// FIXME: If the input is something that is easily negated (e.g. a
4401
4400
// single-use add), we should put the negate there.
4402
4401
return Matcher.getNode(
4403
4402
ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT),
4404
4403
Matcher.getNode(ISD::SHL, DL, VT, N0,
4405
- DAG.getConstant (Log2Val, DL, ShiftVT )));
4404
+ DAG.getShiftAmountConstant (Log2Val, VT, DL )));
4406
4405
}
4407
4406
4408
4407
// Attempt to reuse an existing umul_lohi/smul_lohi node, but only if the
@@ -5101,9 +5100,9 @@ SDValue DAGCombiner::visitMULHS(SDNode *N) {
5101
5100
5102
5101
// fold (mulhs x, 1) -> (sra x, size(x)-1)
5103
5102
if (isOneConstant(N1))
5104
- return DAG.getNode(ISD::SRA, DL, VT, N0,
5105
- DAG.getConstant(N0.getScalarValueSizeInBits() - 1, DL ,
5106
- getShiftAmountTy(VT) ));
5103
+ return DAG.getNode(
5104
+ ISD::SRA, DL, VT, N0 ,
5105
+ DAG.getShiftAmountConstant(N0.getScalarValueSizeInBits() - 1, VT, DL ));
5107
5106
5108
5107
// fold (mulhs x, undef) -> 0
5109
5108
if (N0.isUndef() || N1.isUndef())
@@ -5121,8 +5120,7 @@ SDValue DAGCombiner::visitMULHS(SDNode *N) {
5121
5120
N1 = DAG.getNode(ISD::SIGN_EXTEND, DL, NewVT, N1);
5122
5121
N1 = DAG.getNode(ISD::MUL, DL, NewVT, N0, N1);
5123
5122
N1 = DAG.getNode(ISD::SRL, DL, NewVT, N1,
5124
- DAG.getConstant(SimpleSize, DL,
5125
- getShiftAmountTy(N1.getValueType())));
5123
+ DAG.getShiftAmountConstant(SimpleSize, NewVT, DL));
5126
5124
return DAG.getNode(ISD::TRUNCATE, DL, VT, N1);
5127
5125
}
5128
5126
}
@@ -5192,8 +5190,7 @@ SDValue DAGCombiner::visitMULHU(SDNode *N) {
5192
5190
N1 = DAG.getNode(ISD::ZERO_EXTEND, DL, NewVT, N1);
5193
5191
N1 = DAG.getNode(ISD::MUL, DL, NewVT, N0, N1);
5194
5192
N1 = DAG.getNode(ISD::SRL, DL, NewVT, N1,
5195
- DAG.getConstant(SimpleSize, DL,
5196
- getShiftAmountTy(N1.getValueType())));
5193
+ DAG.getShiftAmountConstant(SimpleSize, NewVT, DL));
5197
5194
return DAG.getNode(ISD::TRUNCATE, DL, VT, N1);
5198
5195
}
5199
5196
}
@@ -5404,8 +5401,7 @@ SDValue DAGCombiner::visitSMUL_LOHI(SDNode *N) {
5404
5401
Lo = DAG.getNode(ISD::MUL, DL, NewVT, Lo, Hi);
5405
5402
// Compute the high part as N1.
5406
5403
Hi = DAG.getNode(ISD::SRL, DL, NewVT, Lo,
5407
- DAG.getConstant(SimpleSize, DL,
5408
- getShiftAmountTy(Lo.getValueType())));
5404
+ DAG.getShiftAmountConstant(SimpleSize, NewVT, DL));
5409
5405
Hi = DAG.getNode(ISD::TRUNCATE, DL, VT, Hi);
5410
5406
// Compute the low part as N0.
5411
5407
Lo = DAG.getNode(ISD::TRUNCATE, DL, VT, Lo);
@@ -5458,8 +5454,7 @@ SDValue DAGCombiner::visitUMUL_LOHI(SDNode *N) {
5458
5454
Lo = DAG.getNode(ISD::MUL, DL, NewVT, Lo, Hi);
5459
5455
// Compute the high part as N1.
5460
5456
Hi = DAG.getNode(ISD::SRL, DL, NewVT, Lo,
5461
- DAG.getConstant(SimpleSize, DL,
5462
- getShiftAmountTy(Lo.getValueType())));
5457
+ DAG.getShiftAmountConstant(SimpleSize, NewVT, DL));
5463
5458
Hi = DAG.getNode(ISD::TRUNCATE, DL, VT, Hi);
5464
5459
// Compute the low part as N0.
5465
5460
Lo = DAG.getNode(ISD::TRUNCATE, DL, VT, Lo);
@@ -7484,8 +7479,7 @@ SDValue DAGCombiner::MatchBSwapHWordLow(SDNode *N, SDValue N0, SDValue N1,
7484
7479
if (OpSizeInBits > 16) {
7485
7480
SDLoc DL(N);
7486
7481
Res = DAG.getNode(ISD::SRL, DL, VT, Res,
7487
- DAG.getConstant(OpSizeInBits - 16, DL,
7488
- getShiftAmountTy(VT)));
7482
+ DAG.getShiftAmountConstant(OpSizeInBits - 16, VT, DL));
7489
7483
}
7490
7484
return Res;
7491
7485
}
@@ -7603,7 +7597,7 @@ static bool isBSwapHWordPair(SDValue N, MutableArrayRef<SDNode *> Parts) {
7603
7597
// (rotr (bswap A), 16)
7604
7598
static SDValue matchBSwapHWordOrAndAnd(const TargetLowering &TLI,
7605
7599
SelectionDAG &DAG, SDNode *N, SDValue N0,
7606
- SDValue N1, EVT VT, EVT ShiftAmountTy ) {
7600
+ SDValue N1, EVT VT) {
7607
7601
assert(N->getOpcode() == ISD::OR && VT == MVT::i32 &&
7608
7602
"MatchBSwapHWordOrAndAnd: expecting i32");
7609
7603
if (!TLI.isOperationLegalOrCustom(ISD::ROTR, VT))
@@ -7635,7 +7629,7 @@ static SDValue matchBSwapHWordOrAndAnd(const TargetLowering &TLI,
7635
7629
7636
7630
SDLoc DL(N);
7637
7631
SDValue BSwap = DAG.getNode(ISD::BSWAP, DL, VT, Shift0.getOperand(0));
7638
- SDValue ShAmt = DAG.getConstant (16, DL, ShiftAmountTy );
7632
+ SDValue ShAmt = DAG.getShiftAmountConstant (16, VT, DL );
7639
7633
return DAG.getNode(ISD::ROTR, DL, VT, BSwap, ShAmt);
7640
7634
}
7641
7635
@@ -7655,13 +7649,11 @@ SDValue DAGCombiner::MatchBSwapHWord(SDNode *N, SDValue N0, SDValue N1) {
7655
7649
if (!TLI.isOperationLegalOrCustom(ISD::BSWAP, VT))
7656
7650
return SDValue();
7657
7651
7658
- if (SDValue BSwap = matchBSwapHWordOrAndAnd(TLI, DAG, N, N0, N1, VT,
7659
- getShiftAmountTy(VT)))
7652
+ if (SDValue BSwap = matchBSwapHWordOrAndAnd(TLI, DAG, N, N0, N1, VT))
7660
7653
return BSwap;
7661
7654
7662
7655
// Try again with commuted operands.
7663
- if (SDValue BSwap = matchBSwapHWordOrAndAnd(TLI, DAG, N, N1, N0, VT,
7664
- getShiftAmountTy(VT)))
7656
+ if (SDValue BSwap = matchBSwapHWordOrAndAnd(TLI, DAG, N, N1, N0, VT))
7665
7657
return BSwap;
7666
7658
7667
7659
@@ -7698,7 +7690,7 @@ SDValue DAGCombiner::MatchBSwapHWord(SDNode *N, SDValue N0, SDValue N1) {
7698
7690
7699
7691
// Result of the bswap should be rotated by 16. If it's not legal, then
7700
7692
// do (x << 16) | (x >> 16).
7701
- SDValue ShAmt = DAG.getConstant (16, DL, getShiftAmountTy(VT) );
7693
+ SDValue ShAmt = DAG.getShiftAmountConstant (16, VT, DL );
7702
7694
if (TLI.isOperationLegalOrCustom(ISD::ROTL, VT))
7703
7695
return DAG.getNode(ISD::ROTL, DL, VT, BSwap, ShAmt);
7704
7696
if (TLI.isOperationLegalOrCustom(ISD::ROTR, VT))
@@ -10430,8 +10422,7 @@ SDValue DAGCombiner::visitSRA(SDNode *N) {
10430
10422
TLI.isOperationLegalOrCustom(ISD::SIGN_EXTEND, TruncVT) &&
10431
10423
TLI.isOperationLegalOrCustom(ISD::TRUNCATE, VT) &&
10432
10424
TLI.isTruncateFree(VT, TruncVT)) {
10433
- SDValue Amt = DAG.getConstant(ShiftAmt, DL,
10434
- getShiftAmountTy(N0.getOperand(0).getValueType()));
10425
+ SDValue Amt = DAG.getShiftAmountConstant(ShiftAmt, VT, DL);
10435
10426
SDValue Shift = DAG.getNode(ISD::SRL, DL, VT,
10436
10427
N0.getOperand(0), Amt);
10437
10428
SDValue Trunc = DAG.getNode(ISD::TRUNCATE, DL, TruncVT,
@@ -10679,10 +10670,9 @@ SDValue DAGCombiner::visitSRL(SDNode *N) {
10679
10670
if (!LegalTypes || TLI.isTypeDesirableForOp(ISD::SRL, SmallVT)) {
10680
10671
uint64_t ShiftAmt = N1C->getZExtValue();
10681
10672
SDLoc DL0(N0);
10682
- SDValue SmallShift = DAG.getNode(ISD::SRL, DL0, SmallVT,
10683
- N0.getOperand(0),
10684
- DAG.getConstant(ShiftAmt, DL0,
10685
- getShiftAmountTy(SmallVT)));
10673
+ SDValue SmallShift =
10674
+ DAG.getNode(ISD::SRL, DL0, SmallVT, N0.getOperand(0),
10675
+ DAG.getShiftAmountConstant(ShiftAmt, SmallVT, DL0));
10686
10676
AddToWorklist(SmallShift.getNode());
10687
10677
APInt Mask = APInt::getLowBitsSet(OpSizeInBits, OpSizeInBits - ShiftAmt);
10688
10678
return DAG.getNode(ISD::AND, DL, VT,
@@ -10726,8 +10716,7 @@ SDValue DAGCombiner::visitSRL(SDNode *N) {
10726
10716
if (ShAmt) {
10727
10717
SDLoc DL(N0);
10728
10718
Op = DAG.getNode(ISD::SRL, DL, VT, Op,
10729
- DAG.getConstant(ShAmt, DL,
10730
- getShiftAmountTy(Op.getValueType())));
10719
+ DAG.getShiftAmountConstant(ShAmt, VT, DL));
10731
10720
AddToWorklist(Op.getNode());
10732
10721
}
10733
10722
return DAG.getNode(ISD::XOR, DL, VT, Op, DAG.getConstant(1, DL, VT));
@@ -11086,7 +11075,7 @@ SDValue DAGCombiner::visitBSWAP(SDNode *N) {
11086
11075
SDValue Res = N0.getOperand(0);
11087
11076
if (uint64_t NewShAmt = (ShAmt->getZExtValue() - (BW / 2)))
11088
11077
Res = DAG.getNode(ISD::SHL, DL, VT, Res,
11089
- DAG.getConstant (NewShAmt, DL, getShiftAmountTy(VT) ));
11078
+ DAG.getShiftAmountConstant (NewShAmt, VT, DL ));
11090
11079
Res = DAG.getZExtOrTrunc(Res, DL, HalfVT);
11091
11080
Res = DAG.getNode(ISD::BSWAP, DL, HalfVT, Res);
11092
11081
return DAG.getZExtOrTrunc(Res, DL, VT);
@@ -12316,9 +12305,9 @@ SDValue DAGCombiner::visitVSELECT(SDNode *N) {
12316
12305
if (TLI.isOperationLegalOrCustom(ISD::ABS, VT))
12317
12306
return DAG.getNode(ISD::ABS, DL, VT, LHS);
12318
12307
12319
- SDValue Shift = DAG.getNode(ISD::SRA, DL, VT, LHS,
12320
- DAG.getConstant(VT.getScalarSizeInBits() - 1 ,
12321
- DL, getShiftAmountTy(VT) ));
12308
+ SDValue Shift = DAG.getNode(
12309
+ ISD::SRA, DL, VT, LHS ,
12310
+ DAG.getShiftAmountConstant(VT.getScalarSizeInBits() - 1, VT, DL ));
12322
12311
SDValue Add = DAG.getNode(ISD::ADD, DL, VT, LHS, Shift);
12323
12312
AddToWorklist(Shift.getNode());
12324
12313
AddToWorklist(Add.getNode());
@@ -14625,18 +14614,15 @@ SDValue DAGCombiner::reduceLoadWidth(SDNode *N) {
14625
14614
// Shift the result left, if we've swallowed a left shift.
14626
14615
SDValue Result = Load;
14627
14616
if (ShLeftAmt != 0) {
14628
- EVT ShImmTy = getShiftAmountTy(Result.getValueType());
14629
- if (!isUIntN(ShImmTy.getScalarSizeInBits(), ShLeftAmt))
14630
- ShImmTy = VT;
14631
14617
// If the shift amount is as large as the result size (but, presumably,
14632
14618
// no larger than the source) then the useful bits of the result are
14633
14619
// zero; we can't simply return the shortened shift, because the result
14634
14620
// of that operation is undefined.
14635
14621
if (ShLeftAmt >= VT.getScalarSizeInBits())
14636
14622
Result = DAG.getConstant(0, DL, VT);
14637
14623
else
14638
- Result = DAG.getNode(ISD::SHL, DL, VT,
14639
- Result, DAG.getConstant (ShLeftAmt, DL, ShImmTy ));
14624
+ Result = DAG.getNode(ISD::SHL, DL, VT, Result,
14625
+ DAG.getShiftAmountConstant (ShLeftAmt, VT, DL ));
14640
14626
}
14641
14627
14642
14628
if (ShiftedOffset != 0) {
@@ -16898,7 +16884,7 @@ SDValue DAGCombiner::combineFMulOrFDivWithIntPow2(SDNode *N) {
16898
16884
16899
16885
// Perform actual transform.
16900
16886
SDValue MantissaShiftCnt =
16901
- DAG.getConstant (*Mantissa, DL, getShiftAmountTy(NewIntVT) );
16887
+ DAG.getShiftAmountConstant (*Mantissa, NewIntVT, DL );
16902
16888
// TODO: Sometimes Log2 is of form `(X + C)`. `(X + C) << C1` should fold to
16903
16889
// `(X << C1) + (C << C1)`, but that isn't always the case because of the
16904
16890
// cast. We could implement that by handle here to handle the casts.
@@ -19811,9 +19797,9 @@ ShrinkLoadReplaceStoreWithStore(const std::pair<unsigned, unsigned> &MaskInfo,
19811
19797
// shifted by ByteShift and truncated down to NumBytes.
19812
19798
if (ByteShift) {
19813
19799
SDLoc DL(IVal);
19814
- IVal = DAG.getNode(ISD::SRL, DL, IVal.getValueType(), IVal,
19815
- DAG.getConstant(ByteShift*8, DL ,
19816
- DC->getShiftAmountTy( IVal.getValueType()) ));
19800
+ IVal = DAG.getNode(
19801
+ ISD::SRL, DL, IVal.getValueType(), IVal ,
19802
+ DAG.getShiftAmountConstant(ByteShift * 8, IVal.getValueType(), DL ));
19817
19803
}
19818
19804
19819
19805
// Figure out the offset for the store and the alignment of the access.
@@ -27422,12 +27408,11 @@ SDValue DAGCombiner::foldSelectCCToShiftAnd(const SDLoc &DL, SDValue N0,
27422
27408
27423
27409
// and (sra X, size(X)-1), A -> "and (srl X, C2), A" iff A is a single-bit
27424
27410
// constant.
27425
- EVT ShiftAmtTy = getShiftAmountTy(N0.getValueType());
27426
27411
auto *N2C = dyn_cast<ConstantSDNode>(N2.getNode());
27427
27412
if (N2C && ((N2C->getAPIntValue() & (N2C->getAPIntValue() - 1)) == 0)) {
27428
27413
unsigned ShCt = XType.getSizeInBits() - N2C->getAPIntValue().logBase2() - 1;
27429
27414
if (!TLI.shouldAvoidTransformToShift(XType, ShCt)) {
27430
- SDValue ShiftAmt = DAG.getConstant (ShCt, DL, ShiftAmtTy );
27415
+ SDValue ShiftAmt = DAG.getShiftAmountConstant (ShCt, XType, DL );
27431
27416
SDValue Shift = DAG.getNode(ISD::SRL, DL, XType, N0, ShiftAmt);
27432
27417
AddToWorklist(Shift.getNode());
27433
27418
@@ -27447,7 +27432,7 @@ SDValue DAGCombiner::foldSelectCCToShiftAnd(const SDLoc &DL, SDValue N0,
27447
27432
if (TLI.shouldAvoidTransformToShift(XType, ShCt))
27448
27433
return SDValue();
27449
27434
27450
- SDValue ShiftAmt = DAG.getConstant (ShCt, DL, ShiftAmtTy );
27435
+ SDValue ShiftAmt = DAG.getShiftAmountConstant (ShCt, XType, DL );
27451
27436
SDValue Shift = DAG.getNode(ISD::SRA, DL, XType, N0, ShiftAmt);
27452
27437
AddToWorklist(Shift.getNode());
27453
27438
@@ -27661,16 +27646,13 @@ SDValue DAGCombiner::SimplifySelectCC(const SDLoc &DL, SDValue N0, SDValue N1,
27661
27646
const APInt &AndMask = ConstAndRHS->getAPIntValue();
27662
27647
if (TLI.shouldFoldSelectWithSingleBitTest(VT, AndMask)) {
27663
27648
unsigned ShCt = AndMask.getBitWidth() - 1;
27664
- SDValue ShlAmt =
27665
- DAG.getConstant(AndMask.countl_zero(), SDLoc(AndLHS),
27666
- getShiftAmountTy(AndLHS.getValueType()));
27649
+ SDValue ShlAmt = DAG.getShiftAmountConstant(AndMask.countl_zero(), VT,
27650
+ SDLoc(AndLHS));
27667
27651
SDValue Shl = DAG.getNode(ISD::SHL, SDLoc(N0), VT, AndLHS, ShlAmt);
27668
27652
27669
27653
// Now arithmetic right shift it all the way over, so the result is
27670
27654
// either all-ones, or zero.
27671
- SDValue ShrAmt =
27672
- DAG.getConstant(ShCt, SDLoc(Shl),
27673
- getShiftAmountTy(Shl.getValueType()));
27655
+ SDValue ShrAmt = DAG.getShiftAmountConstant(ShCt, VT, SDLoc(Shl));
27674
27656
SDValue Shr = DAG.getNode(ISD::SRA, SDLoc(N0), VT, Shl, ShrAmt);
27675
27657
27676
27658
return DAG.getNode(ISD::AND, DL, VT, Shr, N3);
@@ -27718,9 +27700,9 @@ SDValue DAGCombiner::SimplifySelectCC(const SDLoc &DL, SDValue N0, SDValue N1,
27718
27700
return SDValue();
27719
27701
27720
27702
// shl setcc result by log2 n2c
27721
- return DAG.getNode(ISD::SHL, DL, N2.getValueType(), Temp,
27722
- DAG.getConstant(ShCt, SDLoc( Temp) ,
27723
- getShiftAmountTy(Temp .getValueType())));
27703
+ return DAG.getNode(
27704
+ ISD::SHL, DL, N2.getValueType(), Temp,
27705
+ DAG.getShiftAmountConstant(ShCt, N2 .getValueType(), SDLoc(Temp )));
27724
27706
}
27725
27707
27726
27708
// select_cc seteq X, 0, sizeof(X), ctlz(X) -> ctlz(X)
0 commit comments