Skip to content

Commit 61806b9

Browse files
author
git apple-llvm automerger
committed
Merge commit '891220096640' from llvm.org/main into next
2 parents 702114e + 8912200 commit 61806b9

32 files changed

+11728
-163
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5023,6 +5023,10 @@ void SelectionDAGLegalize::PromoteNode(SDNode *Node) {
50235023
case ISD::SREM:
50245024
case ISD::UDIV:
50255025
case ISD::UREM:
5026+
case ISD::SMIN:
5027+
case ISD::SMAX:
5028+
case ISD::UMIN:
5029+
case ISD::UMAX:
50265030
case ISD::AND:
50275031
case ISD::OR:
50285032
case ISD::XOR: {
@@ -5039,12 +5043,21 @@ void SelectionDAGLegalize::PromoteNode(SDNode *Node) {
50395043
break;
50405044
case ISD::SDIV:
50415045
case ISD::SREM:
5046+
case ISD::SMIN:
5047+
case ISD::SMAX:
50425048
ExtOp = ISD::SIGN_EXTEND;
50435049
break;
50445050
case ISD::UDIV:
50455051
case ISD::UREM:
50465052
ExtOp = ISD::ZERO_EXTEND;
50475053
break;
5054+
case ISD::UMIN:
5055+
case ISD::UMAX:
5056+
if (TLI.isSExtCheaperThanZExt(OVT, NVT))
5057+
ExtOp = ISD::SIGN_EXTEND;
5058+
else
5059+
ExtOp = ISD::ZERO_EXTEND;
5060+
break;
50485061
}
50495062
TruncOp = ISD::TRUNCATE;
50505063
}
@@ -5166,7 +5179,11 @@ void SelectionDAGLegalize::PromoteNode(SDNode *Node) {
51665179
unsigned ExtOp = ISD::FP_EXTEND;
51675180
if (NVT.isInteger()) {
51685181
ISD::CondCode CCCode = cast<CondCodeSDNode>(Node->getOperand(2))->get();
5169-
ExtOp = isSignedIntSetCC(CCCode) ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND;
5182+
if (isSignedIntSetCC(CCCode) ||
5183+
TLI.isSExtCheaperThanZExt(Node->getOperand(0).getValueType(), NVT))
5184+
ExtOp = ISD::SIGN_EXTEND;
5185+
else
5186+
ExtOp = ISD::ZERO_EXTEND;
51705187
}
51715188
if (Node->isStrictFPOpcode()) {
51725189
SDValue InChain = Node->getOperand(0);

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ SDValue DAGTypeLegalizer::PromoteIntRes_AtomicCmpSwap(AtomicSDNode *N,
371371
N->getMemOperand());
372372
ReplaceValueWith(SDValue(N, 0), Res.getValue(0));
373373
ReplaceValueWith(SDValue(N, 2), Res.getValue(2));
374-
return Res.getValue(1);
374+
return DAG.getSExtOrTrunc(Res.getValue(1), SDLoc(N), NVT);
375375
}
376376

377377
// Op2 is used for the comparison and thus must be extended according to the

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3484,7 +3484,7 @@ void SelectionDAGBuilder::visitSelect(const User &I) {
34843484
}
34853485

34863486
if (!IsUnaryAbs && Opc != ISD::DELETED_NODE &&
3487-
(TLI.isOperationLegalOrCustom(Opc, VT) ||
3487+
(TLI.isOperationLegalOrCustomOrPromote(Opc, VT) ||
34883488
(UseScalarMinMax &&
34893489
TLI.isOperationLegalOrCustom(Opc, VT.getScalarType()))) &&
34903490
// If the underlying comparison instruction is used by any other

llvm/lib/Target/RISCV/RISCVGISel.td

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ def simm12Plus1 : ImmLeaf<XLenVT, [{
2121
def simm12Plus1i32 : ImmLeaf<i32, [{
2222
return (isInt<12>(Imm) && Imm != -2048) || Imm == 2048;}]>;
2323

24-
def simm12i32 : ImmLeaf<i32, [{return isInt<12>(Imm);}]>;
25-
2624
def uimm5i32 : ImmLeaf<i32, [{return isUInt<5>(Imm);}]>;
2725

2826
// FIXME: This doesn't check that the G_CONSTANT we're deriving the immediate
@@ -49,11 +47,6 @@ def GIAddrRegImm :
4947
GIComplexOperandMatcher<s32, "selectAddrRegImm">,
5048
GIComplexPatternEquiv<AddrRegImm>;
5149

52-
// Convert from i32 immediate to i64 target immediate to make SelectionDAG type
53-
// checking happy so we can use ADDIW which expects an XLen immediate.
54-
def as_i64imm : SDNodeXForm<imm, [{
55-
return CurDAG->getTargetConstant(N->getSExtValue(), SDLoc(N), MVT::i64);
56-
}]>;
5750
def gi_as_i64imm : GICustomOperandRenderer<"renderImm">,
5851
GISDNodeXFormEquiv<as_i64imm>;
5952

@@ -88,14 +81,10 @@ def : Pat<(XLenVT (sub GPR:$rs1, simm12Plus1:$imm)),
8881
(ADDI GPR:$rs1, (NegImm simm12Plus1:$imm))>;
8982

9083
let Predicates = [IsRV64] in {
91-
def : Pat<(i32 (add GPR:$rs1, GPR:$rs2)), (ADDW GPR:$rs1, GPR:$rs2)>;
92-
def : Pat<(i32 (sub GPR:$rs1, GPR:$rs2)), (SUBW GPR:$rs1, GPR:$rs2)>;
9384
def : Pat<(i32 (and GPR:$rs1, GPR:$rs2)), (AND GPR:$rs1, GPR:$rs2)>;
9485
def : Pat<(i32 (or GPR:$rs1, GPR:$rs2)), (OR GPR:$rs1, GPR:$rs2)>;
9586
def : Pat<(i32 (xor GPR:$rs1, GPR:$rs2)), (XOR GPR:$rs1, GPR:$rs2)>;
9687

97-
def : Pat<(i32 (add GPR:$rs1, simm12i32:$imm)),
98-
(ADDIW GPR:$rs1, (i64 (as_i64imm $imm)))>;
9988
def : Pat<(i32 (sub GPR:$rs1, simm12Plus1i32:$imm)),
10089
(ADDIW GPR:$rs1, (i64 (NegImm $imm)))>;
10190

@@ -116,33 +105,15 @@ def : Pat<(i32 (sra GPR:$rs1, uimm5i32:$imm)),
116105
(SRAIW GPR:$rs1, (i64 (as_i64imm $imm)))>;
117106
def : Pat<(i32 (srl GPR:$rs1, uimm5i32:$imm)),
118107
(SRLIW GPR:$rs1, (i64 (as_i64imm $imm)))>;
119-
120-
def : Pat<(i64 (sext i32:$rs)), (ADDIW GPR:$rs, 0)>;
121-
}
122-
123-
let Predicates = [HasStdExtMOrZmmul, IsRV64] in {
124-
def : Pat<(i32 (mul GPR:$rs1, GPR:$rs2)), (MULW GPR:$rs1, GPR:$rs2)>;
125-
}
126-
127-
let Predicates = [HasStdExtM, IsRV64] in {
128-
def : Pat<(i32 (sdiv GPR:$rs1, GPR:$rs2)), (DIVW GPR:$rs1, GPR:$rs2)>;
129-
def : Pat<(i32 (srem GPR:$rs1, GPR:$rs2)), (REMW GPR:$rs1, GPR:$rs2)>;
130-
def : Pat<(i32 (udiv GPR:$rs1, GPR:$rs2)), (DIVUW GPR:$rs1, GPR:$rs2)>;
131-
def : Pat<(i32 (urem GPR:$rs1, GPR:$rs2)), (REMUW GPR:$rs1, GPR:$rs2)>;
132108
}
133109

134110
let Predicates = [HasStdExtZba, IsRV64] in {
135111
// This pattern is put here due to the fact that i32 is not a legal type
136112
// in SDISel for RV64, which is not the case in GISel.
137113
def : Pat<(shl (i64 (zext i32:$rs1)), uimm5:$shamt),
138114
(SLLI_UW GPR:$rs1, uimm5:$shamt)>;
139-
140-
def : Pat<(i64 (zext i32:$rs)), (ADD_UW GPR:$rs, (XLenVT X0))>;
141115
} // Predicates = [HasStdExtZba, IsRV64]
142116

143-
let Predicates = [IsRV64, NotHasStdExtZba] in
144-
def: Pat<(i64 (zext i32:$rs)), (SRLI (SLLI GPR:$rs, 32), 32)>;
145-
146117
// Ptr type used in patterns with GlobalISelEmitter
147118
def PtrVT : PtrValueTypeByHwMode<XLenVT, 0>;
148119

@@ -196,8 +167,6 @@ def : Pat<(XLenVT (setle (Ty GPR:$rs1), (Ty GPR:$rs2))),
196167
(XORI (SLT GPR:$rs2, GPR:$rs1), 1)>;
197168
}
198169

199-
// Define pattern expansions for load/extload and store/truncstore operations
200-
// for ptr return type
201170
let Predicates = [IsRV32] in {
202171
def : LdPat<load, LW, PtrVT>;
203172
def : StPat<store, SW, GPR, PtrVT>;
@@ -206,18 +175,4 @@ def : StPat<store, SW, GPR, PtrVT>;
206175
let Predicates = [IsRV64] in {
207176
def : LdPat<load, LD, PtrVT>;
208177
def : StPat<store, SD, GPR, PtrVT>;
209-
210-
// Define pattern expansions for rv64 load/extloads and store/truncstore
211-
// operations for i32 return type
212-
def : LdPat<sextloadi8, LB, i32>;
213-
def : LdPat<extloadi8, LBU, i32>;
214-
def : LdPat<zextloadi8, LBU, i32>;
215-
def : LdPat<sextloadi16, LH, i32>;
216-
def : LdPat<extloadi16, LH, i32>;
217-
def : LdPat<zextloadi16, LHU, i32>;
218-
def : LdPat<load, LW, i32>;
219-
220-
def : StPat<truncstorei8, SB, GPR, i32>;
221-
def : StPat<truncstorei16, SH, GPR, i32>;
222-
def : StPat<store, SW, GPR, i32>;
223-
} // Predicates = [IsRV64]
178+
}

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ void RISCVDAGToDAGISel::PreprocessISelDAG() {
6767
VT.isInteger() ? RISCVISD::VMV_V_X_VL : RISCVISD::VFMV_V_F_VL;
6868
SDLoc DL(N);
6969
SDValue VL = CurDAG->getRegister(RISCV::X0, Subtarget->getXLenVT());
70-
Result = CurDAG->getNode(Opc, DL, VT, CurDAG->getUNDEF(VT),
71-
N->getOperand(0), VL);
70+
SDValue Src = N->getOperand(0);
71+
if (VT.isInteger())
72+
Src = CurDAG->getNode(ISD::ANY_EXTEND, DL, Subtarget->getXLenVT(),
73+
N->getOperand(0));
74+
Result = CurDAG->getNode(Opc, DL, VT, CurDAG->getUNDEF(VT), Src, VL);
7275
break;
7376
}
7477
case RISCVISD::SPLAT_VECTOR_SPLIT_I64_VL: {
@@ -833,7 +836,7 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
833836

834837
switch (Opcode) {
835838
case ISD::Constant: {
836-
assert(VT == Subtarget->getXLenVT() && "Unexpected VT");
839+
assert((VT == Subtarget->getXLenVT() || VT == MVT::i32) && "Unexpected VT");
837840
auto *ConstNode = cast<ConstantSDNode>(Node);
838841
if (ConstNode->isZero()) {
839842
SDValue New =
@@ -3299,6 +3302,9 @@ bool RISCVDAGToDAGISel::doPeepholeSExtW(SDNode *N) {
32993302
case RISCV::TH_MULAH:
33003303
case RISCV::TH_MULSW:
33013304
case RISCV::TH_MULSH:
3305+
if (N0.getValueType() == MVT::i32)
3306+
break;
3307+
33023308
// Result is already sign extended just remove the sext.w.
33033309
// NOTE: We only handle the nodes that are selected with hasAllWUsers.
33043310
ReplaceUses(N, N0.getNode());

0 commit comments

Comments
 (0)