Skip to content

Commit 815a1bb

Browse files
authored
[SystemZ] Use getSignedConstant() where necessary (#117181)
This will avoid assertion failures once we disable implicit truncation in getConstant(). Inside adjustSubwordCmp() I ended up suppressing the issue with an explicit cast, because this code deals with a mix of unsigned and signed immediates.
1 parent 0fe12a7 commit 815a1bb

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

llvm/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ void SystemZDAGToDAGISel::getAddressOperands(const SystemZAddressingMode &AM,
671671
}
672672

673673
// Lower the displacement to a TargetConstant.
674-
Disp = CurDAG->getTargetConstant(AM.Disp, SDLoc(Base), VT);
674+
Disp = CurDAG->getSignedTargetConstant(AM.Disp, SDLoc(Base), VT);
675675
}
676676

677677
void SystemZDAGToDAGISel::getAddressOperands(const SystemZAddressingMode &AM,
@@ -2024,8 +2024,9 @@ SDValue SystemZDAGToDAGISel::expandSelectBoolean(SDNode *Node) {
20242024
CurDAG->getConstant(IPM.XORValue, DL, MVT::i32));
20252025

20262026
if (IPM.AddValue)
2027-
Result = CurDAG->getNode(ISD::ADD, DL, MVT::i32, Result,
2028-
CurDAG->getConstant(IPM.AddValue, DL, MVT::i32));
2027+
Result =
2028+
CurDAG->getNode(ISD::ADD, DL, MVT::i32, Result,
2029+
CurDAG->getSignedConstant(IPM.AddValue, DL, MVT::i32));
20292030

20302031
EVT VT = Node->getValueType(0);
20312032
if (VT == MVT::i32 && IPM.Bit == 31) {

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,15 +1444,15 @@ void SystemZTargetLowering::LowerAsmOperandForConstraint(
14441444
case 'K': // Signed 16-bit constant
14451445
if (auto *C = dyn_cast<ConstantSDNode>(Op))
14461446
if (isInt<16>(C->getSExtValue()))
1447-
Ops.push_back(DAG.getTargetConstant(C->getSExtValue(), SDLoc(Op),
1448-
Op.getValueType()));
1447+
Ops.push_back(DAG.getSignedTargetConstant(
1448+
C->getSExtValue(), SDLoc(Op), Op.getValueType()));
14491449
return;
14501450

14511451
case 'L': // Signed 20-bit displacement (on all targets we support)
14521452
if (auto *C = dyn_cast<ConstantSDNode>(Op))
14531453
if (isInt<20>(C->getSExtValue()))
1454-
Ops.push_back(DAG.getTargetConstant(C->getSExtValue(), SDLoc(Op),
1455-
Op.getValueType()));
1454+
Ops.push_back(DAG.getSignedTargetConstant(
1455+
C->getSExtValue(), SDLoc(Op), Op.getValueType()));
14561456
return;
14571457

14581458
case 'M': // 0x7fffffff
@@ -2578,7 +2578,7 @@ static void adjustSubwordCmp(SelectionDAG &DAG, const SDLoc &DL,
25782578
// Make sure that the second operand is an i32 with the right value.
25792579
if (C.Op1.getValueType() != MVT::i32 ||
25802580
Value != ConstOp1->getZExtValue())
2581-
C.Op1 = DAG.getConstant(Value, DL, MVT::i32);
2581+
C.Op1 = DAG.getConstant((uint32_t)Value, DL, MVT::i32);
25822582
}
25832583

25842584
// Return true if Op is either an unextended load, or a load suitable
@@ -3410,7 +3410,7 @@ SDValue SystemZTargetLowering::lowerVectorSETCC(SelectionDAG &DAG,
34103410
}
34113411
if (Invert) {
34123412
SDValue Mask =
3413-
DAG.getSplatBuildVector(VT, DL, DAG.getConstant(-1, DL, MVT::i64));
3413+
DAG.getSplatBuildVector(VT, DL, DAG.getAllOnesConstant(DL, MVT::i64));
34143414
Cmp = DAG.getNode(ISD::XOR, DL, VT, Cmp, Mask);
34153415
}
34163416
if (Chain && Chain.getNode() != Cmp.getNode()) {
@@ -3571,7 +3571,7 @@ SDValue SystemZTargetLowering::lowerGlobalAddress(GlobalAddressSDNode *Node,
35713571
// addition for it.
35723572
if (Offset != 0)
35733573
Result = DAG.getNode(ISD::ADD, DL, PtrVT, Result,
3574-
DAG.getConstant(Offset, DL, PtrVT));
3574+
DAG.getSignedConstant(Offset, DL, PtrVT));
35753575

35763576
return Result;
35773577
}
@@ -3834,7 +3834,7 @@ SDValue SystemZTargetLowering::lowerRETURNADDR(SDValue Op,
38343834
const auto *TFL = Subtarget.getFrameLowering<SystemZFrameLowering>();
38353835
int Offset = TFL->getReturnAddressOffset(MF);
38363836
SDValue Ptr = DAG.getNode(ISD::ADD, DL, PtrVT, FrameAddr,
3837-
DAG.getConstant(Offset, DL, PtrVT));
3837+
DAG.getSignedConstant(Offset, DL, PtrVT));
38383838
return DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), Ptr,
38393839
MachinePointerInfo());
38403840
}
@@ -4584,7 +4584,7 @@ static void getCSAddressAndShifts(SDValue Addr, SelectionDAG &DAG, SDLoc DL,
45844584

45854585
// Get the address of the containing word.
45864586
AlignedAddr = DAG.getNode(ISD::AND, DL, PtrVT, Addr,
4587-
DAG.getConstant(-4, DL, PtrVT));
4587+
DAG.getSignedConstant(-4, DL, PtrVT));
45884588

45894589
// Get the number of bits that the word must be rotated left in order
45904590
// to bring the field to the top bits of a GR32.
@@ -4623,7 +4623,8 @@ SDValue SystemZTargetLowering::lowerATOMIC_LOAD_OP(SDValue Op,
46234623
if (Opcode == SystemZISD::ATOMIC_LOADW_SUB)
46244624
if (auto *Const = dyn_cast<ConstantSDNode>(Src2)) {
46254625
Opcode = SystemZISD::ATOMIC_LOADW_ADD;
4626-
Src2 = DAG.getConstant(-Const->getSExtValue(), DL, Src2.getValueType());
4626+
Src2 = DAG.getSignedConstant(-Const->getSExtValue(), DL,
4627+
Src2.getValueType());
46274628
}
46284629

46294630
SDValue AlignedAddr, BitShift, NegBitShift;

llvm/lib/Target/SystemZ/SystemZOperands.td

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ def NEGLF32 : SDNodeXForm<imm, [{
220220

221221
// Truncate an immediate to a 8-bit signed quantity.
222222
def SIMM8 : SDNodeXForm<imm, [{
223-
return CurDAG->getTargetConstant(int8_t(N->getZExtValue()), SDLoc(N),
224-
MVT::i64);
223+
return CurDAG->getSignedTargetConstant(int8_t(N->getZExtValue()), SDLoc(N),
224+
MVT::i64);
225225
}]>;
226226

227227
// Truncate an immediate to a 8-bit unsigned quantity.
@@ -244,14 +244,14 @@ def UIMM12 : SDNodeXForm<imm, [{
244244

245245
// Truncate an immediate to a 16-bit signed quantity.
246246
def SIMM16 : SDNodeXForm<imm, [{
247-
return CurDAG->getTargetConstant(int16_t(N->getZExtValue()), SDLoc(N),
248-
MVT::i64);
247+
return CurDAG->getSignedTargetConstant(int16_t(N->getZExtValue()), SDLoc(N),
248+
MVT::i64);
249249
}]>;
250250

251251
// Negate and then truncate an immediate to a 16-bit signed quantity.
252252
def NEGSIMM16 : SDNodeXForm<imm, [{
253-
return CurDAG->getTargetConstant(int16_t(-N->getZExtValue()), SDLoc(N),
254-
MVT::i64);
253+
return CurDAG->getSignedTargetConstant(int16_t(-N->getZExtValue()), SDLoc(N),
254+
MVT::i64);
255255
}]>;
256256

257257
// Truncate an immediate to a 16-bit unsigned quantity.
@@ -268,8 +268,8 @@ def SIMM32 : SDNodeXForm<imm, [{
268268

269269
// Negate and then truncate an immediate to a 32-bit unsigned quantity.
270270
def NEGSIMM32 : SDNodeXForm<imm, [{
271-
return CurDAG->getTargetConstant(int32_t(-N->getZExtValue()), SDLoc(N),
272-
MVT::i64);
271+
return CurDAG->getSignedTargetConstant(int32_t(-N->getZExtValue()), SDLoc(N),
272+
MVT::i64);
273273
}]>;
274274

275275
// Truncate an immediate to a 32-bit unsigned quantity.

llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static SDValue emitMemMemReg(SelectionDAG &DAG, const SDLoc &DL, unsigned Op,
5353
int64_t Adj = getMemMemLenAdj(Op);
5454
SDValue LenAdj = DAG.getNode(ISD::ADD, DL, MVT::i64,
5555
DAG.getZExtOrTrunc(Size, DL, MVT::i64),
56-
DAG.getConstant(0 - Adj, DL, MVT::i64));
56+
DAG.getSignedConstant(0 - Adj, DL, MVT::i64));
5757
return createMemMemNode(DAG, DL, Op, Chain, Dst, Src, LenAdj, Byte);
5858
}
5959

0 commit comments

Comments
 (0)