Skip to content

[Mips] Use getSignedConstant() for signed values #116405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/include/llvm/CodeGen/SelectionDAG.h
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,10 @@ class SelectionDAG {
bool isOpaque = false) {
return getConstant(Val, DL, VT, true, isOpaque);
}
SDValue getSignedTargetConstant(int64_t Val, const SDLoc &DL, EVT VT,
bool isOpaque = false) {
return getSignedConstant(Val, DL, VT, true, isOpaque);
}

/// Create a true or false constant of type \p VT using the target's
/// BooleanContent for type \p OpVT.
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Target/Mips/MipsISelDAGToDAG.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ class MipsDAGToDAGISel : public SelectionDAGISel {
return CurDAG->getTargetConstant(Imm, SDLoc(Node), Node->getValueType(0));
}

inline SDValue getSignedImm(const SDNode *Node, int64_t Imm) {
return CurDAG->getSignedTargetConstant(Imm, SDLoc(Node),
Node->getValueType(0));
}

virtual void processFunctionAfterISel(MachineFunction &MF) = 0;

bool SelectInlineAsmMemoryOperand(const SDValue &Op,
Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/Target/Mips/MipsISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2362,9 +2362,9 @@ SDValue MipsTargetLowering::lowerVAARG(SDValue Op, SelectionDAG &DAG) const {
ISD::ADD, DL, VAList.getValueType(), VAList,
DAG.getConstant(Align.value() - 1, DL, VAList.getValueType()));

VAList = DAG.getNode(
ISD::AND, DL, VAList.getValueType(), VAList,
DAG.getConstant(-(int64_t)Align.value(), DL, VAList.getValueType()));
VAList = DAG.getNode(ISD::AND, DL, VAList.getValueType(), VAList,
DAG.getSignedConstant(-(int64_t)Align.value(), DL,
VAList.getValueType()));
}

// Increment the pointer, VAList, to the next vaarg.
Expand Down Expand Up @@ -4291,7 +4291,7 @@ void MipsTargetLowering::LowerAsmOperandForConstraint(SDValue Op,
EVT Type = Op.getValueType();
int64_t Val = C->getSExtValue();
if (isInt<16>(Val)) {
Result = DAG.getTargetConstant(Val, DL, Type);
Result = DAG.getSignedTargetConstant(Val, DL, Type);
break;
}
}
Expand Down Expand Up @@ -4321,7 +4321,7 @@ void MipsTargetLowering::LowerAsmOperandForConstraint(SDValue Op,
EVT Type = Op.getValueType();
int64_t Val = C->getSExtValue();
if ((isInt<32>(Val)) && ((Val & 0xffff) == 0)){
Result = DAG.getTargetConstant(Val, DL, Type);
Result = DAG.getSignedTargetConstant(Val, DL, Type);
break;
}
}
Expand All @@ -4331,7 +4331,7 @@ void MipsTargetLowering::LowerAsmOperandForConstraint(SDValue Op,
EVT Type = Op.getValueType();
int64_t Val = C->getSExtValue();
if ((Val >= -65535) && (Val <= -1)) {
Result = DAG.getTargetConstant(Val, DL, Type);
Result = DAG.getSignedTargetConstant(Val, DL, Type);
break;
}
}
Expand All @@ -4341,7 +4341,7 @@ void MipsTargetLowering::LowerAsmOperandForConstraint(SDValue Op,
EVT Type = Op.getValueType();
int64_t Val = C->getSExtValue();
if ((isInt<15>(Val))) {
Result = DAG.getTargetConstant(Val, DL, Type);
Result = DAG.getSignedTargetConstant(Val, DL, Type);
break;
}
}
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Target/Mips/MipsInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,9 @@ def HI16 : SDNodeXForm<imm, [{
}]>;

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

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