Skip to content

Commit e000ded

Browse files
committed
[𝘀𝗽𝗿] changes to main this commit is based on
Created using spr 1.3.5 [skip ci]
1 parent ebacd46 commit e000ded

12 files changed

+1241
-16
lines changed

llvm/lib/Target/Sparc/SparcISelLowering.cpp

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "llvm/CodeGen/MachineRegisterInfo.h"
2828
#include "llvm/CodeGen/SelectionDAG.h"
2929
#include "llvm/CodeGen/SelectionDAGNodes.h"
30+
#include "llvm/CodeGen/TargetLowering.h"
3031
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
3132
#include "llvm/IR/DerivedTypes.h"
3233
#include "llvm/IR/DiagnosticInfo.h"
@@ -1704,8 +1705,10 @@ SparcTargetLowering::SparcTargetLowering(const TargetMachine &TM,
17041705
setOperationAction(ISD::FP16_TO_FP, MVT::f128, Expand);
17051706
setOperationAction(ISD::FP_TO_FP16, MVT::f128, Expand);
17061707

1707-
setOperationAction(ISD::BITCAST, MVT::f32, Expand);
1708-
setOperationAction(ISD::BITCAST, MVT::i32, Expand);
1708+
setOperationAction(ISD::BITCAST, MVT::f32,
1709+
Subtarget->isVIS3() ? Legal : Expand);
1710+
setOperationAction(ISD::BITCAST, MVT::i32,
1711+
Subtarget->isVIS3() ? Legal : Expand);
17091712

17101713
// Sparc has no select or setcc: expand to SELECT_CC.
17111714
setOperationAction(ISD::SELECT, MVT::i32, Expand);
@@ -1737,9 +1740,16 @@ SparcTargetLowering::SparcTargetLowering(const TargetMachine &TM,
17371740
setOperationAction(ISD::SUBC, MVT::i32, Legal);
17381741
setOperationAction(ISD::SUBE, MVT::i32, Legal);
17391742

1743+
if (Subtarget->isVIS3()) {
1744+
setOperationAction(ISD::ADDC, MVT::i64, Legal);
1745+
setOperationAction(ISD::ADDE, MVT::i64, Legal);
1746+
}
1747+
17401748
if (Subtarget->is64Bit()) {
1741-
setOperationAction(ISD::BITCAST, MVT::f64, Expand);
1742-
setOperationAction(ISD::BITCAST, MVT::i64, Expand);
1749+
setOperationAction(ISD::BITCAST, MVT::f64,
1750+
Subtarget->isVIS3() ? Legal : Expand);
1751+
setOperationAction(ISD::BITCAST, MVT::i64,
1752+
Subtarget->isVIS3() ? Legal : Expand);
17431753
setOperationAction(ISD::SELECT, MVT::i64, Expand);
17441754
setOperationAction(ISD::SETCC, MVT::i64, Expand);
17451755
setOperationAction(ISD::BR_CC, MVT::i64, Custom);
@@ -1748,7 +1758,8 @@ SparcTargetLowering::SparcTargetLowering(const TargetMachine &TM,
17481758
setOperationAction(ISD::CTPOP, MVT::i64,
17491759
Subtarget->usePopc() ? Legal : Expand);
17501760
setOperationAction(ISD::CTTZ , MVT::i64, Expand);
1751-
setOperationAction(ISD::CTLZ , MVT::i64, Expand);
1761+
setOperationAction(ISD::CTLZ, MVT::i64,
1762+
Subtarget->isVIS3() ? Legal : Expand);
17521763
setOperationAction(ISD::BSWAP, MVT::i64, Expand);
17531764
setOperationAction(ISD::ROTL , MVT::i64, Expand);
17541765
setOperationAction(ISD::ROTR , MVT::i64, Expand);
@@ -1810,7 +1821,8 @@ SparcTargetLowering::SparcTargetLowering(const TargetMachine &TM,
18101821
setOperationAction(ISD::FREM , MVT::f32, Expand);
18111822
setOperationAction(ISD::FMA , MVT::f32, Expand);
18121823
setOperationAction(ISD::CTTZ , MVT::i32, Expand);
1813-
setOperationAction(ISD::CTLZ , MVT::i32, Expand);
1824+
setOperationAction(ISD::CTLZ, MVT::i32,
1825+
Subtarget->isVIS3() ? Promote : Expand);
18141826
setOperationAction(ISD::ROTL , MVT::i32, Expand);
18151827
setOperationAction(ISD::ROTR , MVT::i32, Expand);
18161828
setOperationAction(ISD::BSWAP, MVT::i32, Expand);
@@ -1849,8 +1861,10 @@ SparcTargetLowering::SparcTargetLowering(const TargetMachine &TM,
18491861
if (Subtarget->is64Bit()) {
18501862
setOperationAction(ISD::UMUL_LOHI, MVT::i64, Expand);
18511863
setOperationAction(ISD::SMUL_LOHI, MVT::i64, Expand);
1852-
setOperationAction(ISD::MULHU, MVT::i64, Expand);
1853-
setOperationAction(ISD::MULHS, MVT::i64, Expand);
1864+
setOperationAction(ISD::MULHU, MVT::i64,
1865+
Subtarget->isVIS3() ? Legal : Expand);
1866+
setOperationAction(ISD::MULHS, MVT::i64,
1867+
Subtarget->isVIS3() ? Legal : Expand);
18541868

18551869
setOperationAction(ISD::SHL_PARTS, MVT::i64, Expand);
18561870
setOperationAction(ISD::SRA_PARTS, MVT::i64, Expand);
@@ -1981,6 +1995,11 @@ SparcTargetLowering::SparcTargetLowering(const TargetMachine &TM,
19811995
if (Subtarget->hasLeonCycleCounter())
19821996
setOperationAction(ISD::READCYCLECOUNTER, MVT::i64, Custom);
19831997

1998+
if (Subtarget->isVIS3()) {
1999+
setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i32, Promote);
2000+
setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i64, Legal);
2001+
}
2002+
19842003
setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
19852004

19862005
setMinFunctionAlignment(Align(4));
@@ -3560,6 +3579,17 @@ bool SparcTargetLowering::useLoadStackGuardNode(const Module &M) const {
35603579
return true;
35613580
}
35623581

3582+
bool SparcTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT,
3583+
bool ForCodeSize) const {
3584+
if (VT != MVT::f32 && VT != MVT::f64)
3585+
return false;
3586+
if (Imm.isZero())
3587+
return Subtarget->isVIS();
3588+
if (Imm.isExactlyValue(+0.5) || Imm.isExactlyValue(-0.5))
3589+
return Subtarget->isVIS3();
3590+
return false;
3591+
}
3592+
35633593
// Override to disable global variable loading on Linux.
35643594
void SparcTargetLowering::insertSSPDeclarations(Module &M) const {
35653595
if (!Subtarget->isTargetLinux())

llvm/lib/Target/Sparc/SparcISelLowering.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ namespace llvm {
207207
return VT != MVT::f128;
208208
}
209209

210+
bool isFPImmLegal(const APFloat &Imm, EVT VT,
211+
bool ForCodeSize) const override;
212+
210213
bool shouldInsertFencesForAtomic(const Instruction *I) const override {
211214
// FIXME: We insert fences for each atomics and generate
212215
// sub-optimal code for PSO/TSO. (Approximately nobody uses any

llvm/lib/Target/Sparc/SparcInstr64Bit.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,11 @@ def : Pat<(and i64:$lhs, (not i64:$rhs)), (ANDNrr $lhs, $rhs)>;
157157
def : Pat<(or i64:$lhs, (not i64:$rhs)), (ORNrr $lhs, $rhs)>;
158158
def : Pat<(not (xor i64:$lhs, i64:$rhs)), (XNORrr $lhs, $rhs)>;
159159

160+
def : Pat<(addc i64:$lhs, i64:$rhs), (ADDCCrr $lhs, $rhs)>, Requires<[HasVIS3]>;
160161
def : Pat<(add i64:$lhs, i64:$rhs), (ADDrr $lhs, $rhs)>;
161162
def : Pat<(sub i64:$lhs, i64:$rhs), (SUBrr $lhs, $rhs)>;
162163

164+
def : Pat<(addc i64:$lhs, (i64 simm13:$rhs)), (ADDCCri $lhs, imm:$rhs)>, Requires<[HasVIS3]>;
163165
def : Pat<(add i64:$lhs, (i64 simm13:$rhs)), (ADDri $lhs, imm:$rhs)>;
164166
def : Pat<(sub i64:$lhs, (i64 simm13:$rhs)), (SUBri $lhs, imm:$rhs)>;
165167

llvm/lib/Target/Sparc/SparcInstrVIS.td

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ class VISInst2<bits<9> opfval, string OpcStr, RegisterClass RC = DFPRegs>
4545
!strconcat(OpcStr, " $rs2, $rd")>;
4646

4747
// For VIS Instructions with only rd operand.
48-
let Constraints = "$rd = $f", rs1 = 0, rs2 = 0 in
48+
let rs1 = 0, rs2 = 0 in
4949
class VISInstD<bits<9> opfval, string OpcStr, RegisterClass RC = DFPRegs>
5050
: VISInstFormat<opfval,
51-
(outs RC:$rd), (ins RC:$f),
51+
(outs RC:$rd), (ins),
5252
!strconcat(OpcStr, " $rd")>;
5353

5454
// VIS 1 Instructions
@@ -259,14 +259,14 @@ def LZCNT : VISInstFormat<0b000010111, (outs I64Regs:$rd),
259259
(ins I64Regs:$rs2), "lzcnt $rs2, $rd">;
260260

261261
let rs1 = 0 in {
262-
def MOVSTOSW : VISInstFormat<0b100010011, (outs I64Regs:$rd),
263-
(ins DFPRegs:$rs2), "movstosw $rs2, $rd">;
264-
def MOVSTOUW : VISInstFormat<0b100010001, (outs I64Regs:$rd),
265-
(ins DFPRegs:$rs2), "movstouw $rs2, $rd">;
262+
def MOVSTOSW : VISInstFormat<0b100010011, (outs IntRegs:$rd),
263+
(ins FPRegs:$rs2), "movstosw $rs2, $rd">;
264+
def MOVSTOUW : VISInstFormat<0b100010001, (outs IntRegs:$rd),
265+
(ins FPRegs:$rs2), "movstouw $rs2, $rd">;
266266
def MOVDTOX : VISInstFormat<0b100010000, (outs I64Regs:$rd),
267267
(ins DFPRegs:$rs2), "movdtox $rs2, $rd">;
268-
def MOVWTOS : VISInstFormat<0b100011001, (outs DFPRegs:$rd),
269-
(ins I64Regs:$rs2), "movwtos $rs2, $rd">;
268+
def MOVWTOS : VISInstFormat<0b100011001, (outs FPRegs:$rd),
269+
(ins IntRegs:$rs2), "movwtos $rs2, $rd">;
270270
def MOVXTOD : VISInstFormat<0b100011000, (outs DFPRegs:$rd),
271271
(ins I64Regs:$rs2), "movxtod $rs2, $rd">;
272272
}
@@ -277,3 +277,74 @@ def UMULXHI : VISInst<0b000010110, "umulxhi", I64Regs>;
277277
def XMULX : VISInst<0b100010101, "xmulx", I64Regs>;
278278
def XMULXHI : VISInst<0b100010110, "xmulxhi", I64Regs>;
279279
} // Predicates = [IsVIS3]
280+
281+
// FP immediate patterns.
282+
def fpimm0 : FPImmLeaf<fAny, [{return Imm.isExactlyValue(+0.0);}]>;
283+
def fpnegimm0 : FPImmLeaf<fAny, [{return Imm.isExactlyValue(-0.0);}]>;
284+
def fpimmhalf : FPImmLeaf<fAny, [{return Imm.isExactlyValue(+0.5);}]>;
285+
def fpnegimmhalf : FPImmLeaf<fAny, [{return Imm.isExactlyValue(-0.5);}]>;
286+
287+
// VIS instruction patterns.
288+
let Predicates = [HasVIS] in {
289+
// Zero immediate.
290+
def : Pat<(f64 fpimm0), (FZERO)>;
291+
def : Pat<(f32 fpimm0), (FZEROS)>;
292+
def : Pat<(f64 fpnegimm0), (FNEGD (FZERO))>;
293+
def : Pat<(f32 fpnegimm0), (FNEGS (FZEROS))>;
294+
} // Predicates = [HasVIS]
295+
296+
// VIS3 instruction patterns.
297+
let Predicates = [HasVIS3] in {
298+
// +/-0.5 immediate.
299+
// This is needed to enable halving instructions.
300+
// FIXME generalize this to arbitrary immediates.
301+
// SET/MOVWTOS or SETX/MOVXTOD pair should let us materialize FP constants
302+
// faster than constant pool loading.
303+
def : Pat<(f32 fpimmhalf), (MOVWTOS (SETHIi 0x0FC000))>;
304+
def : Pat<(f32 fpnegimmhalf), (MOVWTOS (SETHIi 0x2FC000))>;
305+
def : Pat<(f64 fpimmhalf), (MOVXTOD (SLLXri (SETHIi 0x0FF800), 32))>;
306+
def : Pat<(f64 fpnegimmhalf), (MOVXTOD (SLLXri (SETHIi 0x2FF800), 32))>;
307+
308+
def : Pat<(i64 (adde i64:$lhs, i64:$rhs)), (ADDXCCC $lhs, $rhs)>;
309+
310+
def : Pat<(i64 (mulhu i64:$lhs, i64:$rhs)), (UMULXHI $lhs, $rhs)>;
311+
// Signed "MULXHI".
312+
// Based on the formula presented in OSA2011 §7.140, but with bitops to select
313+
// the values to be added.
314+
// TODO: This expansion should probably be moved to DAG legalization phase.
315+
def : Pat<(i64 (mulhs i64:$lhs, i64:$rhs)),
316+
(SUBrr (UMULXHI $lhs, $rhs),
317+
(ADDrr (ANDrr (SRAXri $lhs, 63), $rhs),
318+
(ANDrr (SRAXri $rhs, 63), $lhs)))>;
319+
320+
def : Pat<(i64 (ctlz i64:$src)), (LZCNT $src)>;
321+
def : Pat<(i64 (ctlz_zero_undef i64:$src)), (LZCNT $src)>;
322+
323+
def : Pat<(i32 (bitconvert f32:$src)), (MOVSTOUW $src)>;
324+
def : Pat<(i64 (zanyext (i32 (bitconvert f32:$src)))), (MOVSTOUW $src)>;
325+
def : Pat<(i64 (sext (i32 (bitconvert f32:$src)))), (MOVSTOSW $src)>;
326+
def : Pat<(f32 (bitconvert i32:$src)), (MOVWTOS $src)>;
327+
def : Pat<(i64 (bitconvert f64:$src)), (MOVDTOX $src)>;
328+
def : Pat<(f64 (bitconvert i64:$src)), (MOVXTOD $src)>;
329+
330+
// OP-then-neg FP operations.
331+
def : Pat<(f32 (fneg (fadd f32:$rs1, f32:$rs2))), (FNADDS $rs1, $rs2)>;
332+
def : Pat<(f64 (fneg (fadd f64:$rs1, f64:$rs2))), (FNADDD $rs1, $rs2)>;
333+
def : Pat<(f32 (fneg (fmul f32:$rs1, f32:$rs2))), (FNMULS $rs1, $rs2)>;
334+
def : Pat<(f32 (fmul (fneg f32:$rs1), f32:$rs2)), (FNMULS $rs1, $rs2)>;
335+
def : Pat<(f32 (fmul f32:$rs1, (fneg f32:$rs2))), (FNMULS $rs1, $rs2)>;
336+
def : Pat<(f64 (fneg (fmul f64:$rs1, f64:$rs2))), (FNMULD $rs1, $rs2)>;
337+
def : Pat<(f64 (fmul (fneg f64:$rs1), f64:$rs2)), (FNMULD $rs1, $rs2)>;
338+
def : Pat<(f64 (fmul f64:$rs1, (fneg f64:$rs2))), (FNMULD $rs1, $rs2)>;
339+
def : Pat<(f64 (fneg (fmul (fpextend f32:$rs1), (fpextend f32:$rs2)))), (FNSMULD $rs1, $rs2)>;
340+
def : Pat<(f64 (fmul (fneg (fpextend f32:$rs1)), (fpextend f32:$rs2))), (FNSMULD $rs1, $rs2)>;
341+
def : Pat<(f64 (fmul (fpextend f32:$rs1), (fneg (fpextend f32:$rs2)))), (FNSMULD $rs1, $rs2)>;
342+
343+
// Op-then-halve FP operations.
344+
def : Pat<(f32 (fmul (fadd f32:$rs1, f32:$rs2), fpimmhalf)), (FHADDS $rs1, $rs2)>;
345+
def : Pat<(f64 (fmul (fadd f64:$rs1, f64:$rs2), fpimmhalf)), (FHADDD $rs1, $rs2)>;
346+
def : Pat<(f32 (fmul (fsub f32:$rs1, f32:$rs2), fpimmhalf)), (FHSUBS $rs1, $rs2)>;
347+
def : Pat<(f64 (fmul (fsub f64:$rs1, f64:$rs2), fpimmhalf)), (FHSUBD $rs1, $rs2)>;
348+
def : Pat<(f32 (fmul (fadd f32:$rs1, f32:$rs2), fpnegimmhalf)), (FNHADDS $rs1, $rs2)>;
349+
def : Pat<(f64 (fmul (fadd f64:$rs1, f64:$rs2), fpnegimmhalf)), (FNHADDD $rs1, $rs2)>;
350+
} // Predicates = [HasVIS3]

0 commit comments

Comments
 (0)