Skip to content

Commit 3fc5bb6

Browse files
authored
[Mips] Use getSignedConstant() for signed values (#116405)
This also adds a getSignedTargetConstant() helper, as these seem to be fairly common in general.
1 parent b5bc528 commit 3fc5bb6

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,10 @@ class SelectionDAG {
700700
bool isOpaque = false) {
701701
return getConstant(Val, DL, VT, true, isOpaque);
702702
}
703+
SDValue getSignedTargetConstant(int64_t Val, const SDLoc &DL, EVT VT,
704+
bool isOpaque = false) {
705+
return getSignedConstant(Val, DL, VT, true, isOpaque);
706+
}
703707

704708
/// Create a true or false constant of type \p VT using the target's
705709
/// BooleanContent for type \p OpVT.

llvm/lib/Target/Mips/MipsISelDAGToDAG.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ class MipsDAGToDAGISel : public SelectionDAGISel {
133133
return CurDAG->getTargetConstant(Imm, SDLoc(Node), Node->getValueType(0));
134134
}
135135

136+
inline SDValue getSignedImm(const SDNode *Node, int64_t Imm) {
137+
return CurDAG->getSignedTargetConstant(Imm, SDLoc(Node),
138+
Node->getValueType(0));
139+
}
140+
136141
virtual void processFunctionAfterISel(MachineFunction &MF) = 0;
137142

138143
bool SelectInlineAsmMemoryOperand(const SDValue &Op,

llvm/lib/Target/Mips/MipsISelLowering.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,9 +2360,9 @@ SDValue MipsTargetLowering::lowerVAARG(SDValue Op, SelectionDAG &DAG) const {
23602360
ISD::ADD, DL, VAList.getValueType(), VAList,
23612361
DAG.getConstant(Align.value() - 1, DL, VAList.getValueType()));
23622362

2363-
VAList = DAG.getNode(
2364-
ISD::AND, DL, VAList.getValueType(), VAList,
2365-
DAG.getConstant(-(int64_t)Align.value(), DL, VAList.getValueType()));
2363+
VAList = DAG.getNode(ISD::AND, DL, VAList.getValueType(), VAList,
2364+
DAG.getSignedConstant(-(int64_t)Align.value(), DL,
2365+
VAList.getValueType()));
23662366
}
23672367

23682368
// Increment the pointer, VAList, to the next vaarg.
@@ -4289,7 +4289,7 @@ void MipsTargetLowering::LowerAsmOperandForConstraint(SDValue Op,
42894289
EVT Type = Op.getValueType();
42904290
int64_t Val = C->getSExtValue();
42914291
if (isInt<16>(Val)) {
4292-
Result = DAG.getTargetConstant(Val, DL, Type);
4292+
Result = DAG.getSignedTargetConstant(Val, DL, Type);
42934293
break;
42944294
}
42954295
}
@@ -4319,7 +4319,7 @@ void MipsTargetLowering::LowerAsmOperandForConstraint(SDValue Op,
43194319
EVT Type = Op.getValueType();
43204320
int64_t Val = C->getSExtValue();
43214321
if ((isInt<32>(Val)) && ((Val & 0xffff) == 0)){
4322-
Result = DAG.getTargetConstant(Val, DL, Type);
4322+
Result = DAG.getSignedTargetConstant(Val, DL, Type);
43234323
break;
43244324
}
43254325
}
@@ -4329,7 +4329,7 @@ void MipsTargetLowering::LowerAsmOperandForConstraint(SDValue Op,
43294329
EVT Type = Op.getValueType();
43304330
int64_t Val = C->getSExtValue();
43314331
if ((Val >= -65535) && (Val <= -1)) {
4332-
Result = DAG.getTargetConstant(Val, DL, Type);
4332+
Result = DAG.getSignedTargetConstant(Val, DL, Type);
43334333
break;
43344334
}
43354335
}
@@ -4339,7 +4339,7 @@ void MipsTargetLowering::LowerAsmOperandForConstraint(SDValue Op,
43394339
EVT Type = Op.getValueType();
43404340
int64_t Val = C->getSExtValue();
43414341
if ((isInt<15>(Val))) {
4342-
Result = DAG.getTargetConstant(Val, DL, Type);
4342+
Result = DAG.getSignedTargetConstant(Val, DL, Type);
43434343
break;
43444344
}
43454345
}

llvm/lib/Target/Mips/MipsInstrInfo.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,9 @@ def HI16 : SDNodeXForm<imm, [{
11991199
}]>;
12001200

12011201
// Plus 1.
1202-
def Plus1 : SDNodeXForm<imm, [{ return getImm(N, N->getSExtValue() + 1); }]>;
1202+
def Plus1 : SDNodeXForm<imm, [{
1203+
return getSignedImm(N, N->getSExtValue() + 1);
1204+
}]>;
12031205

12041206
// Node immediate is zero (e.g. insve.d)
12051207
def immz : PatLeaf<(imm), [{ return N->getSExtValue() == 0; }]>;

0 commit comments

Comments
 (0)