Skip to content

Commit 166a39f

Browse files
committed
[SystemZ] Use getSignedConstant()
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 22fdc57 commit 166a39f

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
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: 7 additions & 6 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
@@ -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;

0 commit comments

Comments
 (0)