@@ -177,7 +177,8 @@ static SDValue selectImmSeq(SelectionDAG *CurDAG, const SDLoc &DL, const MVT VT,
177
177
RISCVMatInt::InstSeq &Seq) {
178
178
SDValue SrcReg = CurDAG->getRegister (RISCV::X0, VT);
179
179
for (const RISCVMatInt::Inst &Inst : Seq) {
180
- SDValue SDImm = CurDAG->getTargetConstant (Inst.getImm (), DL, VT);
180
+ SDValue SDImm =
181
+ CurDAG->getSignedConstant (Inst.getImm (), DL, VT, /* isTarget=*/ true );
181
182
SDNode *Result = nullptr ;
182
183
switch (Inst.getOpndKind ()) {
183
184
case RISCVMatInt::Imm:
@@ -208,10 +209,10 @@ static SDValue selectImm(SelectionDAG *CurDAG, const SDLoc &DL, const MVT VT,
208
209
209
210
// Use a rematerializable pseudo instruction for short sequences if enabled.
210
211
if (Seq.size () == 2 && UsePseudoMovImm)
211
- return SDValue (
212
- CurDAG->getMachineNode (RISCV::PseudoMovImm, DL, VT,
213
- CurDAG-> getTargetConstant ( Imm, DL, VT)),
214
- 0 );
212
+ return SDValue (CurDAG-> getMachineNode (RISCV::PseudoMovImm, DL, VT,
213
+ CurDAG->getSignedConstant (
214
+ Imm, DL, VT, /* isTarget= */ true )),
215
+ 0 );
215
216
216
217
// See if we can create this constant as (ADD (SLLI X, C), X) where X is at
217
218
// worst an LUI+ADDIW. This will require an extra register, but avoids a
@@ -670,9 +671,9 @@ bool RISCVDAGToDAGISel::tryShrinkShlLogicImm(SDNode *Node) {
670
671
671
672
unsigned ShOpc = SignExt ? RISCV::SLLIW : RISCV::SLLI;
672
673
673
- SDNode *BinOp =
674
- CurDAG-> getMachineNode ( BinOpc, DL, VT, Shift.getOperand (0 ),
675
- CurDAG->getTargetConstant (ShiftedVal, DL, VT));
674
+ SDNode *BinOp = CurDAG-> getMachineNode (
675
+ BinOpc, DL, VT, Shift.getOperand (0 ),
676
+ CurDAG->getSignedConstant (ShiftedVal, DL, VT, /* isTarget= */ true ));
676
677
SDNode *SLLI =
677
678
CurDAG->getMachineNode (ShOpc, DL, VT, SDValue (BinOp, 0 ),
678
679
CurDAG->getTargetConstant (ShAmt, DL, VT));
@@ -802,7 +803,8 @@ bool RISCVDAGToDAGISel::tryIndexedLoad(SDNode *Node) {
802
803
803
804
EVT Ty = Ld->getOffset ().getValueType ();
804
805
SDValue Ops[] = {Ld->getBasePtr (),
805
- CurDAG->getTargetConstant (Offset >> Shift, SDLoc (Node), Ty),
806
+ CurDAG->getSignedConstant (Offset >> Shift, SDLoc (Node), Ty,
807
+ /* isTarget=*/ true ),
806
808
CurDAG->getTargetConstant (Shift, SDLoc (Node), Ty),
807
809
Ld->getChain ()};
808
810
SDNode *New = CurDAG->getMachineNode (Opcode, SDLoc (Node), Ld->getValueType (0 ),
@@ -2486,8 +2488,8 @@ bool RISCVDAGToDAGISel::SelectFrameAddrRegImm(SDValue Addr, SDValue &Base,
2486
2488
if (isInt<12 >(CVal)) {
2487
2489
Base = CurDAG->getTargetFrameIndex (FIN->getIndex (),
2488
2490
Subtarget->getXLenVT ());
2489
- Offset = CurDAG->getTargetConstant (CVal, SDLoc (Addr),
2490
- Subtarget->getXLenVT ());
2491
+ Offset = CurDAG->getSignedConstant (
2492
+ CVal, SDLoc (Addr), Subtarget->getXLenVT (), /* isTarget= */ true );
2491
2493
return true ;
2492
2494
}
2493
2495
}
@@ -2523,7 +2525,7 @@ static bool selectConstantAddr(SelectionDAG *CurDAG, const SDLoc &DL,
2523
2525
} else {
2524
2526
Base = CurDAG->getRegister (RISCV::X0, VT);
2525
2527
}
2526
- Offset = CurDAG->getTargetConstant (Lo12, DL, VT);
2528
+ Offset = CurDAG->getSignedConstant (Lo12, DL, VT, /* isTarget= */ true );
2527
2529
return true ;
2528
2530
}
2529
2531
@@ -2543,7 +2545,7 @@ static bool selectConstantAddr(SelectionDAG *CurDAG, const SDLoc &DL,
2543
2545
assert (!Seq.empty () && " Expected more instructions in sequence" );
2544
2546
2545
2547
Base = selectImmSeq (CurDAG, DL, VT, Seq);
2546
- Offset = CurDAG->getTargetConstant (Lo12, DL, VT);
2548
+ Offset = CurDAG->getSignedConstant (Lo12, DL, VT, /* isTarget= */ true );
2547
2549
return true ;
2548
2550
}
2549
2551
@@ -2668,7 +2670,7 @@ bool RISCVDAGToDAGISel::SelectAddrRegImm(SDValue Addr, SDValue &Base,
2668
2670
2669
2671
if (auto *FIN = dyn_cast<FrameIndexSDNode>(Base))
2670
2672
Base = CurDAG->getTargetFrameIndex (FIN->getIndex (), VT);
2671
- Offset = CurDAG->getTargetConstant (CVal, DL, VT);
2673
+ Offset = CurDAG->getSignedConstant (CVal, DL, VT, /* isTarget= */ true );
2672
2674
return true ;
2673
2675
}
2674
2676
}
@@ -2685,10 +2687,11 @@ bool RISCVDAGToDAGISel::SelectAddrRegImm(SDValue Addr, SDValue &Base,
2685
2687
if (isInt<12 >(CVal / 2 ) && isInt<12 >(CVal - CVal / 2 )) {
2686
2688
int64_t Adj = CVal < 0 ? -2048 : 2047 ;
2687
2689
Base = SDValue (
2688
- CurDAG->getMachineNode (RISCV::ADDI, DL, VT, Addr.getOperand (0 ),
2689
- CurDAG->getTargetConstant (Adj, DL, VT)),
2690
+ CurDAG->getMachineNode (
2691
+ RISCV::ADDI, DL, VT, Addr.getOperand (0 ),
2692
+ CurDAG->getSignedConstant (Adj, DL, VT, /* isTarget=*/ true )),
2690
2693
0 );
2691
- Offset = CurDAG->getTargetConstant (CVal - Adj, DL, VT);
2694
+ Offset = CurDAG->getSignedConstant (CVal - Adj, DL, VT, /* isTarget= */ true );
2692
2695
return true ;
2693
2696
}
2694
2697
@@ -2741,7 +2744,7 @@ bool RISCVDAGToDAGISel::SelectAddrRegImmLsb00000(SDValue Addr, SDValue &Base,
2741
2744
2742
2745
if (auto *FIN = dyn_cast<FrameIndexSDNode>(Base))
2743
2746
Base = CurDAG->getTargetFrameIndex (FIN->getIndex (), VT);
2744
- Offset = CurDAG->getTargetConstant (CVal, DL, VT);
2747
+ Offset = CurDAG->getSignedConstant (CVal, DL, VT, /* isTarget= */ true );
2745
2748
return true ;
2746
2749
}
2747
2750
}
@@ -2759,9 +2762,10 @@ bool RISCVDAGToDAGISel::SelectAddrRegImmLsb00000(SDValue Addr, SDValue &Base,
2759
2762
int64_t AdjustedOffset = CVal - Adj;
2760
2763
Base = SDValue (CurDAG->getMachineNode (
2761
2764
RISCV::ADDI, DL, VT, Addr.getOperand (0 ),
2762
- CurDAG->getTargetConstant (AdjustedOffset, DL, VT)),
2765
+ CurDAG->getSignedConstant (AdjustedOffset, DL, VT,
2766
+ /* isTarget=*/ true )),
2763
2767
0 );
2764
- Offset = CurDAG->getTargetConstant (Adj, DL, VT);
2768
+ Offset = CurDAG->getSignedConstant (Adj, DL, VT, /* isTarget= */ true );
2765
2769
return true ;
2766
2770
}
2767
2771
@@ -2857,9 +2861,9 @@ bool RISCVDAGToDAGISel::selectShiftMask(SDValue N, unsigned ShiftWidth,
2857
2861
if (Imm % ShiftWidth == ShiftWidth - 1 ) {
2858
2862
SDLoc DL (ShAmt);
2859
2863
EVT VT = ShAmt.getValueType ();
2860
- MachineSDNode *Not =
2861
- CurDAG-> getMachineNode ( RISCV::XORI, DL, VT, ShAmt.getOperand (1 ),
2862
- CurDAG->getTargetConstant (- 1 , DL, VT));
2864
+ MachineSDNode *Not = CurDAG-> getMachineNode (
2865
+ RISCV::XORI, DL, VT, ShAmt.getOperand (1 ),
2866
+ CurDAG->getAllOnesConstant ( DL, VT, /* isTarget= */ true ));
2863
2867
ShAmt = SDValue (Not, 0 );
2864
2868
return true ;
2865
2869
}
@@ -2906,21 +2910,21 @@ bool RISCVDAGToDAGISel::selectSETCC(SDValue N, ISD::CondCode ExpectedCCVal,
2906
2910
// If the RHS is -2048, we can use xori to produce 0 if the LHS is -2048 and
2907
2911
// non-zero otherwise.
2908
2912
if (CVal == -2048 ) {
2909
- Val =
2910
- SDValue (CurDAG-> getMachineNode (
2911
- RISCV::XORI , DL, N->getValueType (0 ), LHS ,
2912
- CurDAG-> getTargetConstant (CVal, DL, N-> getValueType ( 0 ) )),
2913
- 0 );
2913
+ Val = SDValue (CurDAG-> getMachineNode (
2914
+ RISCV::XORI, DL, N-> getValueType ( 0 ), LHS,
2915
+ CurDAG-> getSignedConstant (CVal , DL, N->getValueType (0 ),
2916
+ /* isTarget= */ true )),
2917
+ 0 );
2914
2918
return true ;
2915
2919
}
2916
2920
// If the RHS is [-2047,2048], we can use addi with -RHS to produce 0 if the
2917
2921
// LHS is equal to the RHS and non-zero otherwise.
2918
2922
if (isInt<12 >(CVal) || CVal == 2048 ) {
2919
- Val =
2920
- SDValue (CurDAG-> getMachineNode (
2921
- RISCV::ADDI , DL, N->getValueType (0 ), LHS ,
2922
- CurDAG-> getTargetConstant (-CVal, DL, N-> getValueType ( 0 ) )),
2923
- 0 );
2923
+ Val = SDValue (CurDAG-> getMachineNode (
2924
+ RISCV::ADDI, DL, N-> getValueType ( 0 ), LHS,
2925
+ CurDAG-> getSignedConstant (-CVal , DL, N->getValueType (0 ),
2926
+ /* isTarget= */ true )),
2927
+ 0 );
2924
2928
return true ;
2925
2929
}
2926
2930
}
@@ -3326,7 +3330,8 @@ bool RISCVDAGToDAGISel::selectSimm5Shl2(SDValue N, SDValue &Simm5,
3326
3330
return false ;
3327
3331
3328
3332
EVT Ty = N->getValueType (0 );
3329
- Simm5 = CurDAG->getTargetConstant (Offset >> Shift, SDLoc (N), Ty);
3333
+ Simm5 = CurDAG->getSignedConstant (Offset >> Shift, SDLoc (N), Ty,
3334
+ /* isTarget=*/ true );
3330
3335
Shl2 = CurDAG->getTargetConstant (Shift, SDLoc (N), Ty);
3331
3336
return true ;
3332
3337
}
@@ -3343,16 +3348,16 @@ bool RISCVDAGToDAGISel::selectVLOp(SDValue N, SDValue &VL) {
3343
3348
N->getValueType (0 ));
3344
3349
} else if (C && C->isAllOnes ()) {
3345
3350
// Treat all ones as VLMax.
3346
- VL = CurDAG->getTargetConstant (RISCV::VLMaxSentinel, SDLoc (N),
3347
- N->getValueType (0 ));
3351
+ VL = CurDAG->getSignedConstant (RISCV::VLMaxSentinel, SDLoc (N),
3352
+ N->getValueType (0 ), /* isTarget= */ true );
3348
3353
} else if (isa<RegisterSDNode>(N) &&
3349
3354
cast<RegisterSDNode>(N)->getReg () == RISCV::X0) {
3350
3355
// All our VL operands use an operand that allows GPRNoX0 or an immediate
3351
3356
// as the register class. Convert X0 to a special immediate to pass the
3352
3357
// MachineVerifier. This is recognized specially by the vsetvli insertion
3353
3358
// pass.
3354
- VL = CurDAG->getTargetConstant (RISCV::VLMaxSentinel, SDLoc (N),
3355
- N->getValueType (0 ));
3359
+ VL = CurDAG->getSignedConstant (RISCV::VLMaxSentinel, SDLoc (N),
3360
+ N->getValueType (0 ), /* isTarget= */ true );
3356
3361
} else {
3357
3362
VL = N;
3358
3363
}
@@ -3410,7 +3415,8 @@ static bool selectVSplatImmHelper(SDValue N, SDValue &SplatVal,
3410
3415
if (!ValidateImm (SplatImm))
3411
3416
return false ;
3412
3417
3413
- SplatVal = DAG.getTargetConstant (SplatImm, SDLoc (N), Subtarget.getXLenVT ());
3418
+ SplatVal = DAG.getSignedConstant (SplatImm, SDLoc (N), Subtarget.getXLenVT (),
3419
+ /* isTarget=*/ true );
3414
3420
return true ;
3415
3421
}
3416
3422
@@ -3504,7 +3510,8 @@ bool RISCVDAGToDAGISel::selectRVVSimm5(SDValue N, unsigned Width,
3504
3510
if (!isInt<5 >(ImmVal))
3505
3511
return false ;
3506
3512
3507
- Imm = CurDAG->getTargetConstant (ImmVal, SDLoc (N), Subtarget->getXLenVT ());
3513
+ Imm = CurDAG->getSignedConstant (ImmVal, SDLoc (N), Subtarget->getXLenVT (),
3514
+ /* isTarget=*/ true );
3508
3515
return true ;
3509
3516
}
3510
3517
0 commit comments