diff options
Diffstat (limited to 'llvm/lib/Target/Mips')
| -rw-r--r-- | llvm/lib/Target/Mips/MicroMips64r6InstrInfo.td | 3 | ||||
| -rw-r--r-- | llvm/lib/Target/Mips/MicroMipsInstrInfo.td | 6 | ||||
| -rw-r--r-- | llvm/lib/Target/Mips/Mips64InstrInfo.td | 10 | ||||
| -rw-r--r-- | llvm/lib/Target/Mips/MipsInstrInfo.td | 39 | ||||
| -rw-r--r-- | llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp | 4 |
5 files changed, 49 insertions, 13 deletions
diff --git a/llvm/lib/Target/Mips/MicroMips64r6InstrInfo.td b/llvm/lib/Target/Mips/MicroMips64r6InstrInfo.td index 87c41deb85a..c6e943deb79 100644 --- a/llvm/lib/Target/Mips/MicroMips64r6InstrInfo.td +++ b/llvm/lib/Target/Mips/MicroMips64r6InstrInfo.td @@ -414,6 +414,9 @@ let DecoderNamespace = "MicroMipsR6" in { ISA_MICROMIPS64R6; } +let AdditionalPredicates = [InMicroMips] in +defm : MaterializeImms<i64, ZERO_64, DADDIU_MM64R6, LUi64, ORi64>; + //===----------------------------------------------------------------------===// // // Arbitrary patterns that map to one or more instructions diff --git a/llvm/lib/Target/Mips/MicroMipsInstrInfo.td b/llvm/lib/Target/Mips/MicroMipsInstrInfo.td index 3e839271a43..39229463fef 100644 --- a/llvm/lib/Target/Mips/MicroMipsInstrInfo.td +++ b/llvm/lib/Target/Mips/MicroMipsInstrInfo.td @@ -981,6 +981,12 @@ let DecoderNamespace = "MicroMips" in { // MicroMips arbitrary patterns that map to one or more instructions //===----------------------------------------------------------------------===// +def : MipsPat<(i32 immLi16:$imm), + (LI16_MM immLi16:$imm)>; + +let AdditionalPredicates = [InMicroMips] in +defm : MaterializeImms<i32, ZERO, ADDiu_MM, LUi_MM, ORi_MM>; + let Predicates = [InMicroMips] in { def : MipsPat<(i32 immLi16:$imm), (LI16_MM immLi16:$imm)>; diff --git a/llvm/lib/Target/Mips/Mips64InstrInfo.td b/llvm/lib/Target/Mips/Mips64InstrInfo.td index c1bffcd497d..ec81be4dbe4 100644 --- a/llvm/lib/Target/Mips/Mips64InstrInfo.td +++ b/llvm/lib/Target/Mips/Mips64InstrInfo.td @@ -494,6 +494,16 @@ def DMTC2 : MTC3OP<"dmtc2", COP2Opnd, GPR64Opnd, II_DMTC2>, MFC3OP_FM<0x12, 5>, // Arbitrary patterns that map to one or more instructions //===----------------------------------------------------------------------===// +// Materialize i64 constants. +defm : MaterializeImms<i64, ZERO_64, DADDiu, LUi64, ORi64>; + +def : MipsPat<(i64 immZExt32Low16Zero:$imm), + (DSLL (ORi64 ZERO_64, (HI16 imm:$imm)), 16)>; + +def : MipsPat<(i64 immZExt32:$imm), + (ORi64 (DSLL (ORi64 ZERO_64, (HI16 imm:$imm)), 16), + (LO16 imm:$imm))>; + // extended loads def : MipsPat<(i64 (extloadi1 addr:$src)), (LB64 addr:$src)>; def : MipsPat<(i64 (extloadi8 addr:$src)), (LB64 addr:$src)>; diff --git a/llvm/lib/Target/Mips/MipsInstrInfo.td b/llvm/lib/Target/Mips/MipsInstrInfo.td index 8bdcb18f719..f8db4ce8c77 100644 --- a/llvm/lib/Target/Mips/MipsInstrInfo.td +++ b/llvm/lib/Target/Mips/MipsInstrInfo.td @@ -1052,11 +1052,23 @@ def immZExt16 : PatLeaf<(imm), [{ }], LO16>; // Immediate can be loaded with LUi (32-bit int with lower 16-bit cleared). -def immLow16Zero : PatLeaf<(imm), [{ +def immSExt32Low16Zero : PatLeaf<(imm), [{ int64_t Val = N->getSExtValue(); return isInt<32>(Val) && !(Val & 0xffff); }]>; +// Zero-extended 32-bit unsigned int with lower 16-bit cleared. +def immZExt32Low16Zero : PatLeaf<(imm), [{ + uint64_t Val = N->getZExtValue(); + return isUInt<32>(Val) && !(Val & 0xffff); +}]>; + +// Note immediate fits as a 32 bit signed extended on target immediate. +def immSExt32 : PatLeaf<(imm), [{ return isInt<32>(N->getSExtValue()); }]>; + +// Note immediate fits as a 32 bit zero extended on target immediate. +def immZExt32 : PatLeaf<(imm), [{ return isUInt<32>(N->getZExtValue()); }]>; + // shamt field must fit in 5 bits. def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>; @@ -2454,19 +2466,24 @@ class LoadRegImmPat<Instruction LoadInst, ValueType ValTy, PatFrag Node> : class StoreRegImmPat<Instruction StoreInst, ValueType ValTy> : MipsPat<(store ValTy:$v, addrRegImm:$a), (StoreInst ValTy:$v, addrRegImm:$a)>; +// Materialize constants. +multiclass MaterializeImms<ValueType VT, Register ZEROReg, + Instruction ADDiuOp, Instruction LUiOp, + Instruction ORiOp> { + // Small immediates -let AdditionalPredicates = [NotInMicroMips] in { -def : MipsPat<(i32 immSExt16:$in), - (ADDiu ZERO, imm:$in)>; -def : MipsPat<(i32 immZExt16:$in), - (ORi ZERO, imm:$in)>; -} -def : MipsPat<(i32 immLow16Zero:$in), - (LUi (HI16 imm:$in))>; +def : MipsPat<(VT immSExt16:$imm), (ADDiuOp ZEROReg, imm:$imm)>; +def : MipsPat<(VT immZExt16:$imm), (ORiOp ZEROReg, imm:$imm)>; + +// Bits 32-16 set, sign/zero extended. +def : MipsPat<(VT immSExt32Low16Zero:$imm), (LUiOp (HI16 imm:$imm))>; // Arbitrary immediates -def : MipsPat<(i32 imm:$imm), - (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>; +def : MipsPat<(VT immSExt32:$imm), (ORiOp (LUiOp (HI16 imm:$imm)), (LO16 imm:$imm))>; +} + +let AdditionalPredicates = [NotInMicroMips] in + defm : MaterializeImms<i32, ZERO, ADDiu, LUi, ORi>; // Carry MipsPatterns let AdditionalPredicates = [NotInMicroMips] in { diff --git a/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp b/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp index d9528da5a96..ff2f7756ad7 100644 --- a/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp +++ b/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp @@ -771,13 +771,13 @@ bool MipsSEDAGToDAGISel::trySelect(SDNode *Node) { case ISD::Constant: { const ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Node); + int64_t Imm = CN->getSExtValue(); unsigned Size = CN->getValueSizeInBits(0); - if (Size == 32) + if (isInt<32>(Imm)) break; MipsAnalyzeImmediate AnalyzeImm; - int64_t Imm = CN->getSExtValue(); const MipsAnalyzeImmediate::InstSeq &Seq = AnalyzeImm.Analyze(Imm, Size, false); |

