Index: llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp =================================================================== --- llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -257,9 +257,9 @@ bool expandCondBranches(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out, const MCSubtargetInfo *STI); - bool expandDiv(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out, - const MCSubtargetInfo *STI, const bool IsMips64, - const bool Signed); + bool expandDivRem(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out, + const MCSubtargetInfo *STI, const bool IsMips64, + const bool Signed); bool expandTrunc(MCInst &Inst, bool IsDouble, bool Is64FPU, SMLoc IDLoc, MCStreamer &Out, const MCSubtargetInfo *STI); @@ -2431,20 +2431,28 @@ return expandCondBranches(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success; case Mips::SDivMacro: case Mips::SDivIMacro: - return expandDiv(Inst, IDLoc, Out, STI, false, true) ? MER_Fail - : MER_Success; + case Mips::SRemMacro: + case Mips::SRemIMacro: + return expandDivRem(Inst, IDLoc, Out, STI, false, true) ? MER_Fail + : MER_Success; case Mips::DSDivMacro: case Mips::DSDivIMacro: - return expandDiv(Inst, IDLoc, Out, STI, true, true) ? MER_Fail - : MER_Success; + case Mips::DSRemMacro: + case Mips::DSRemIMacro: + return expandDivRem(Inst, IDLoc, Out, STI, true, true) ? MER_Fail + : MER_Success; case Mips::UDivMacro: case Mips::UDivIMacro: - return expandDiv(Inst, IDLoc, Out, STI, false, false) ? MER_Fail - : MER_Success; + case Mips::URemMacro: + case Mips::URemIMacro: + return expandDivRem(Inst, IDLoc, Out, STI, false, false) ? MER_Fail + : MER_Success; case Mips::DUDivMacro: case Mips::DUDivIMacro: - return expandDiv(Inst, IDLoc, Out, STI, true, false) ? MER_Fail - : MER_Success; + case Mips::DURemMacro: + case Mips::DURemIMacro: + return expandDivRem(Inst, IDLoc, Out, STI, true, false) ? MER_Fail + : MER_Success; case Mips::PseudoTRUNC_W_S: return expandTrunc(Inst, false, false, IDLoc, Out, STI) ? MER_Fail : MER_Success; @@ -3927,9 +3935,9 @@ // The destination register can only be $zero when expanding (S)DivIMacro or // D(S)DivMacro. -bool MipsAsmParser::expandDiv(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out, - const MCSubtargetInfo *STI, const bool IsMips64, - const bool Signed) { +bool MipsAsmParser::expandDivRem(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out, + const MCSubtargetInfo *STI, const bool IsMips64, + const bool Signed) { MipsTargetStreamer &TOut = getTargetStreamer(); warnIfNoMacro(IDLoc); @@ -3969,6 +3977,17 @@ bool UseTraps = useTraps(); + unsigned Opcode = Inst.getOpcode(); + bool isDiv = Opcode == Mips::SDivMacro || Opcode == Mips::SDivIMacro || + Opcode == Mips::UDivMacro || Opcode == Mips::UDivIMacro || + Opcode == Mips::DSDivMacro || Opcode == Mips::DSDivIMacro || + Opcode == Mips::DUDivMacro || Opcode == Mips::DUDivIMacro; + + bool isRem = Opcode == Mips::SRemMacro || Opcode == Mips::SRemIMacro || + Opcode == Mips::URemMacro || Opcode == Mips::URemIMacro || + Opcode == Mips::DSRemMacro || Opcode == Mips::DSRemIMacro || + Opcode == Mips::DURemMacro || Opcode == Mips::DURemIMacro; + if (RtOp.isImm()) { unsigned ATReg = getATReg(IDLoc); if (!ATReg) @@ -3982,10 +4001,13 @@ return false; } - if (ImmValue == 1) { + if (isRem && (ImmValue == 1 || (Signed && (ImmValue == -1)))) { + TOut.emitRRR(Mips::OR, RdReg, ZeroReg, ZeroReg, IDLoc, STI); + return false; + } else if (isDiv && ImmValue == 1) { TOut.emitRRR(Mips::OR, RdReg, RsReg, Mips::ZERO, IDLoc, STI); return false; - } else if (Signed && ImmValue == -1) { + } else if (isDiv && Signed && ImmValue == -1) { TOut.emitRRR(SubOp, RdReg, ZeroReg, RsReg, IDLoc, STI); return false; } else { @@ -3993,16 +4015,16 @@ false, Inst.getLoc(), Out, STI)) return true; TOut.emitRR(DivOp, RsReg, ATReg, IDLoc, STI); - TOut.emitR(Mips::MFLO, RdReg, IDLoc, STI); + TOut.emitR(isDiv ? Mips::MFLO : Mips::MFHI, RdReg, IDLoc, STI); return false; } return true; } - // If the macro expansion of (d)div(u) would always trap or break, insert - // the trap/break and exit. This gives a different result to GAS. GAS has - // an inconsistency/missed optimization in that not all cases are handled - // equivalently. As the observed behaviour is the same, we're ok. + // If the macro expansion of (d)div(u) or (d)rem(u) would always trap or + // break, insert the trap/break and exit. This gives a different result to + // GAS. GAS has an inconsistency/missed optimization in that not all cases + // are handled equivalently. As the observed behaviour is the same, we're ok. if (RtReg == Mips::ZERO || RtReg == Mips::ZERO_64) { if (UseTraps) { TOut.emitRRI(Mips::TEQ, ZeroReg, ZeroReg, 0x7, IDLoc, STI); @@ -4012,6 +4034,13 @@ return false; } + // (d)rem(u) $0, $X, $Y is a special case. Like div $zero, $X, $Y, it does + // not expand to macro sequence. + if (isRem && (RdReg == Mips::ZERO || RdReg == Mips::ZERO_64)) { + TOut.emitRR(DivOp, RsReg, RtReg, IDLoc, STI); + return false; + } + // Temporary label for first branch traget MCContext &Context = TOut.getStreamer().getContext(); MCSymbol *BrTarget; @@ -4035,7 +4064,7 @@ if (!UseTraps) TOut.getStreamer().EmitLabel(BrTarget); - TOut.emitR(Mips::MFLO, RdReg, IDLoc, STI); + TOut.emitR(isDiv ? Mips::MFLO : Mips::MFHI, RdReg, IDLoc, STI); return false; } @@ -4058,7 +4087,7 @@ if (IsMips64) { TOut.emitRRI(Mips::ADDiu, ATReg, ZeroReg, 1, IDLoc, STI); - TOut.emitRRI(Mips::DSLL32, ATReg, ATReg, 0x1f, IDLoc, STI); + TOut.emitDSLL(ATReg, ATReg, 63, IDLoc, STI); } else { TOut.emitRI(Mips::LUi, ATReg, (uint16_t)0x8000, IDLoc, STI); } @@ -4068,12 +4097,12 @@ else { // Branch to the mflo instruction. TOut.emitRRX(Mips::BNE, RsReg, ATReg, LabelOpEnd, IDLoc, STI); - TOut.emitRRI(Mips::SLL, ZeroReg, ZeroReg, 0, IDLoc, STI); + TOut.emitNop(IDLoc, STI); TOut.emitII(Mips::BREAK, 0x6, 0, IDLoc, STI); } TOut.getStreamer().EmitLabel(BrTargetEnd); - TOut.emitR(Mips::MFLO, RdReg, IDLoc, STI); + TOut.emitR(isDiv ? Mips::MFLO : Mips::MFHI, RdReg, IDLoc, STI); return false; } Index: llvm/trunk/lib/Target/Mips/Mips64InstrInfo.td =================================================================== --- llvm/trunk/lib/Target/Mips/Mips64InstrInfo.td +++ llvm/trunk/lib/Target/Mips/Mips64InstrInfo.td @@ -1032,6 +1032,38 @@ GPR64Opnd:$rd, imm64:$imm), 0>, ISA_MIPS3_NOT_32R6_64R6; + def DSRemMacro : MipsAsmPseudoInst<(outs GPR64Opnd:$rd), + (ins GPR64Opnd:$rs, GPR64Opnd:$rt), + "drem\t$rd, $rs, $rt">, + ISA_MIPS3_NOT_32R6_64R6; + def DSRemIMacro : MipsAsmPseudoInst<(outs GPR64Opnd:$rd), + (ins GPR64Opnd:$rs, simm32_relaxed:$imm), + "drem\t$rd, $rs, $imm">, + ISA_MIPS3_NOT_32R6_64R6; + def DURemMacro : MipsAsmPseudoInst<(outs GPR64Opnd:$rd), + (ins GPR64Opnd:$rs, GPR64Opnd:$rt), + "dremu\t$rd, $rs, $rt">, + ISA_MIPS3_NOT_32R6_64R6; + def DURemIMacro : MipsAsmPseudoInst<(outs GPR64Opnd:$rd), + (ins GPR64Opnd:$rs, simm32_relaxed:$imm), + "dremu\t$rd, $rs, $imm">, + ISA_MIPS3_NOT_32R6_64R6; + def : MipsInstAlias<"drem $rt, $rs", (DSRemMacro GPR64Opnd:$rt, + GPR64Opnd:$rt, + GPR64Opnd:$rs), 0>, + ISA_MIPS3_NOT_32R6_64R6; + def : MipsInstAlias<"drem $rd, $imm", (DSRemIMacro GPR64Opnd:$rd, + GPR64Opnd:$rd, + simm32_relaxed:$imm), 0>, + ISA_MIPS3_NOT_32R6_64R6; + def : MipsInstAlias<"dremu $rt, $rs", (DURemMacro GPR64Opnd:$rt, + GPR64Opnd:$rt, + GPR64Opnd:$rs), 0>, + ISA_MIPS3_NOT_32R6_64R6; + def : MipsInstAlias<"dremu $rd, $imm", (DURemIMacro GPR64Opnd:$rd, + GPR64Opnd:$rd, + simm32_relaxed:$imm), 0>, + ISA_MIPS3_NOT_32R6_64R6; } def NORImm64 : NORIMM_DESC_BASE, GPR_64; Index: llvm/trunk/lib/Target/Mips/MipsInstrInfo.td =================================================================== --- llvm/trunk/lib/Target/Mips/MipsInstrInfo.td +++ llvm/trunk/lib/Target/Mips/MipsInstrInfo.td @@ -2950,6 +2950,36 @@ simm32:$imm), 0>, ISA_MIPS1_NOT_32R6_64R6; +def SRemMacro : MipsAsmPseudoInst<(outs GPR32Opnd:$rd), + (ins GPR32Opnd:$rs, GPR32Opnd:$rt), + "rem\t$rd, $rs, $rt">, + ISA_MIPS1_NOT_32R6_64R6; +def SRemIMacro : MipsAsmPseudoInst<(outs GPR32Opnd:$rd), + (ins GPR32Opnd:$rs, simm32_relaxed:$imm), + "rem\t$rd, $rs, $imm">, + ISA_MIPS1_NOT_32R6_64R6; +def URemMacro : MipsAsmPseudoInst<(outs GPR32Opnd:$rd), + (ins GPR32Opnd:$rs, GPR32Opnd:$rt), + "remu\t$rd, $rs, $rt">, + ISA_MIPS1_NOT_32R6_64R6; +def URemIMacro : MipsAsmPseudoInst<(outs GPR32Opnd:$rd), + (ins GPR32Opnd:$rs, simm32_relaxed:$imm), + "remu\t$rd, $rs, $imm">, + ISA_MIPS1_NOT_32R6_64R6; + +def : MipsInstAlias<"rem $rt, $rs", (SRemMacro GPR32Opnd:$rt, GPR32Opnd:$rt, + GPR32Opnd:$rs), 0>, + ISA_MIPS1_NOT_32R6_64R6; +def : MipsInstAlias<"rem $rd, $imm", (SRemIMacro GPR32Opnd:$rd, GPR32Opnd:$rd, + simm32_relaxed:$imm), 0>, + ISA_MIPS1_NOT_32R6_64R6; +def : MipsInstAlias<"remu $rt, $rs", (URemMacro GPR32Opnd:$rt, GPR32Opnd:$rt, + GPR32Opnd:$rs), 0>, + ISA_MIPS1_NOT_32R6_64R6; +def : MipsInstAlias<"remu $rd, $imm", (URemIMacro GPR32Opnd:$rd, GPR32Opnd:$rd, + simm32_relaxed:$imm), 0>, + ISA_MIPS1_NOT_32R6_64R6; + def Ulh : MipsAsmPseudoInst<(outs GPR32Opnd:$rt), (ins mem:$addr), "ulh\t$rt, $addr">; //, ISA_MIPS1_NOT_32R6_64R6; Index: llvm/trunk/test/MC/Mips/macro-ddiv.s =================================================================== --- llvm/trunk/test/MC/Mips/macro-ddiv.s +++ llvm/trunk/test/MC/Mips/macro-ddiv.s @@ -16,7 +16,7 @@ # CHECK-NOTRAP: dsll32 $1, $1, 31 # encoding: [0x00,0x01,0x0f,0xfc] # CHECK-NOTRAP: bne $25, $1, .Ltmp1 # encoding: [0x17,0x21,A,A] # CHECK-NOTRAP: # fixup A - offset: 0, value: .Ltmp1-4, kind: fixup_Mips_PC16 -# CHECK-NOTRAP: sll $zero, $zero, 0 # encoding: [0x00,0x00,0x00,0x00] +# CHECK-NOTRAP: nop # encoding: [0x00,0x00,0x00,0x00] # CHECK-NOTRAP: break 6 # encoding: [0x00,0x06,0x00,0x0d] # CHECK-NOTRAP: .Ltmp1 # CHECK-NOTRAP: mflo $25 # encoding: [0x00,0x00,0xc8,0x12] @@ -45,7 +45,7 @@ # CHECK-NOTRAP: dsll32 $1, $1, 31 # encoding: [0x00,0x01,0x0f,0xfc] # CHECK-NOTRAP: bne $24, $1, .Ltmp3 # encoding: [0x17,0x01,A,A] # CHECK-NOTRAP: # fixup A - offset: 0, value: .Ltmp3-4, kind: fixup_Mips_PC16 -# CHECK-NOTRAP: sll $zero, $zero, 0 # encoding: [0x00,0x00,0x00,0x00] +# CHECK-NOTRAP: nop # encoding: [0x00,0x00,0x00,0x00] # CHECK-NOTRAP: break 6 # encoding: [0x00,0x06,0x00,0x0d] # CHECK-NOTRAP: .Ltmp3 # CHECK-NOTRAP: mflo $24 # encoding: [0x00,0x00,0xc0,0x12] @@ -211,7 +211,7 @@ # CHECK-NOTRAP: dsll32 $1, $1, 31 # encoding: [0x00,0x01,0x0f,0xfc] # CHECK-NOTRAP: bne $5, $1, .Ltmp7 # encoding: [0x14,0xa1,A,A] # CHECK-NOTRAP: # fixup A - offset: 0, value: .Ltmp7-4, kind: fixup_Mips_PC16 -# CHECK-NOTRAP: sll $zero, $zero, 0 # encoding: [0x00,0x00,0x00,0x00] +# CHECK-NOTRAP: nop # encoding: [0x00,0x00,0x00,0x00] # CHECK-NOTRAP: break 6 # encoding: [0x00,0x06,0x00,0x0d] # CHECK-NOTRAP: .Ltmp7: # CHECK-NOTRAP: mflo $4 # encoding: [0x00,0x00,0x20,0x12] Index: llvm/trunk/test/MC/Mips/macro-drem.s =================================================================== --- llvm/trunk/test/MC/Mips/macro-drem.s +++ llvm/trunk/test/MC/Mips/macro-drem.s @@ -0,0 +1,244 @@ +# RUN: llvm-mc %s -triple=mips64el-unknown-linux -show-encoding -mcpu=mips64 | \ +# RUN: FileCheck %s --check-prefix=CHECK-NOTRAP +# RUN: llvm-mc %s -triple=mips64el-unknown-linux -show-encoding -mcpu=mips64 \ +# RUN: -mattr=+use-tcc-in-div | FileCheck %s --check-prefix=CHECK-TRAP + + drem $4,$5 +# CHECK-NOTRAP: bne $5, $zero, .Ltmp0 # encoding: [A,A,0xa0,0x14] +# CHECK-NOTRAP: # fixup A - offset: 0, value: .Ltmp0-4, kind: fixup_Mips_PC16 +# CHECK-NOTRAP: ddiv $zero, $4, $5 # encoding: [0x1e,0x00,0x85,0x00] +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-NOTRAP: .Ltmp0 +# CHECK-NOTRAP: addiu $1, $zero, -1 # encoding: [0xff,0xff,0x01,0x24] +# CHECK-NOTRAP: bne $5, $1, .Ltmp1 # encoding: [A,A,0xa1,0x14] +# CHECK-NOTRAP: # fixup A - offset: 0, value: .Ltmp1-4, kind: fixup_Mips_PC16 +# CHECK-NOTRAP: addiu $1, $zero, 1 # encoding: [0x01,0x00,0x01,0x24] +# CHECK-NOTRAP: dsll32 $1, $1, 31 # encoding: [0xfc,0x0f,0x01,0x00] +# CHECK-NOTRAP: bne $4, $1, .Ltmp1 # encoding: [A,A,0x81,0x14] +# CHECK-NOTRAP: # fixup A - offset: 0, value: .Ltmp1-4, kind: fixup_Mips_PC16 +# CHECK-NOTRAP: nop # encoding: [0x00,0x00,0x00,0x00] +# CHECK-NOTRAP: break 6 # encoding: [0x0d,0x00,0x06,0x00] +# CHECK-NOTRAP: .Ltmp1 +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,$0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] + + drem $4,0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] + + drem $0,0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] + + drem $4,1 +# CHECK-NOTRAP: or $4, $zero, $zero # encoding: [0x25,0x20,0x00,0x00] + + drem $4,-1 +# CHECK-NOTRAP: or $4, $zero, $zero # encoding: [0x25,0x20,0x00,0x00] + + drem $4,2 +# CHECK-NOTRAP: addiu $1, $zero, 2 # encoding: [0x02,0x00,0x01,0x24] +# CHECK-NOTRAP: ddiv $zero, $4, $1 # encoding: [0x1e,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,0x10000 +# CHECK-NOTRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-NOTRAP: ddiv $zero, $4, $1 # encoding: [0x1e,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,0x1a5a5 +# CHECK-NOTRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-NOTRAP: ori $1, $1, 42405 # encoding: [0xa5,0xa5,0x21,0x34] +# CHECK-NOTRAP: ddiv $zero, $4, $1 # encoding: [0x1e,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,0x8000 +# CHECK-NOTRAP: ori $1, $zero, 32768 # encoding: [0x00,0x80,0x01,0x34] +# CHECK-NOTRAP: ddiv $zero, $4, $1 # encoding: [0x1e,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,-0x8000 +# CHECK-NOTRAP: addiu $1, $zero, -32768 # encoding: [0x00,0x80,0x01,0x24] +# CHECK-NOTRAP: ddiv $zero, $4, $1 # encoding: [0x1e,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,$5,$6 +# CHECK-NOTRAP: bne $6, $zero, .Ltmp2 # encoding: [A,A,0xc0,0x14] +# CHECK-NOTRAP: # fixup A - offset: 0, value: .Ltmp2-4, kind: fixup_Mips_PC16 +# CHECK-NOTRAP: ddiv $zero, $5, $6 # encoding: [0x1e,0x00,0xa6,0x00] +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-NOTRAP: .Ltmp2: +# CHECK-NOTRAP: addiu $1, $zero, -1 # encoding: [0xff,0xff,0x01,0x24] +# CHECK-NOTRAP: bne $6, $1, .Ltmp3 # encoding: [A,A,0xc1,0x14] +# CHECK-NOTRAP: addiu $1, $zero, 1 # encoding: [0x01,0x00,0x01,0x24] +# CHECK-NOTRAP: dsll32 $1, $1, 31 # encoding: [0xfc,0x0f,0x01,0x00] +# CHECK-NOTRAP: bne $5, $1, .Ltmp3 # encoding: [A,A,0xa1,0x14] +# CHECK-NOTRAP: nop # encoding: [0x00,0x00,0x00,0x00] +# CHECK-NOTRAP: break 6 # encoding: [0x0d,0x00,0x06,0x00] +# CHECK-NOTRAP: .Ltmp3: +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,$5,$0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] + + drem $4,$0,$0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] + + drem $0,$5,$4 +# CHECK-NOTRAP: ddiv $zero, $5, $4 # encoding: [0x1e,0x00,0xa4,0x00] + + drem $4,$5,0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] + + drem $4,$0,0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] + + drem $0,$4,$5 +# CHECK-NOTRAP: ddiv $zero, $4, $5 # encoding: [0x1e,0x00,0x85,0x00] + + drem $4,$5,1 +# CHECK-NOTRAP: or $4, $zero, $zero # encoding: [0x25,0x20,0x00,0x00] + + drem $4,$5,-1 +# CHECK-NOTRAP: or $4, $zero, $zero # encoding: [0x25,0x20,0x00,0x00] + + drem $4,$5,2 +# CHECK-NOTRAP: addiu $1, $zero, 2 # encoding: [0x02,0x00,0x01,0x24] +# CHECK-NOTRAP: ddiv $zero, $5, $1 # encoding: [0x1e,0x00,0xa1,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,$5,0x10000 +# CHECK-NOTRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-NOTRAP: ddiv $zero, $5, $1 # encoding: [0x1e,0x00,0xa1,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,$5,0x1a5a5 +# CHECK-NOTRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-NOTRAP: ori $1, $1, 42405 # encoding: [0xa5,0xa5,0x21,0x34] +# CHECK-NOTRAP: ddiv $zero, $5, $1 # encoding: [0x1e,0x00,0xa1,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,$5,0x8000 +# CHECK-NOTRAP: ori $1, $zero, 32768 # encoding: [0x00,0x80,0x01,0x34] +# CHECK-NOTRAP: ddiv $zero, $5, $1 # encoding: [0x1e,0x00,0xa1,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,$5,-0x8000 +# CHECK-NOTRAP: addiu $1, $zero, -32768 # encoding: [0x00,0x80,0x01,0x24] +# CHECK-NOTRAP: ddiv $zero, $5, $1 # encoding: [0x1e,0x00,0xa1,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,$5 +# CHECK-TRAP: teq $5, $zero, 7 # encoding: [0xf4,0x01,0xa0,0x00] +# CHECK-TRAP: ddiv $zero, $4, $5 # encoding: [0x1e,0x00,0x85,0x00] +# CHECK-TRAP: addiu $1, $zero, -1 # encoding: [0xff,0xff,0x01,0x24] +# CHECK-TRAP: bne $5, $1, .Ltmp2 # encoding: [A,A,0xa1,0x14] +# CHECK-TRAP: # fixup A - offset: 0, value: .Ltmp2-4, kind: fixup_Mips_PC16 +# CHECK-TRAP: addiu $1, $zero, 1 # encoding: [0x01,0x00,0x01,0x24] +# CHECK-TRAP: dsll32 $1, $1, 31 # encoding: [0xfc,0x0f,0x01,0x00] +# CHECK-TRAP: teq $4, $1, 6 # encoding: [0xb4,0x01,0x81,0x00] +# CHECK-TRAP: .Ltmp2 +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,$0 +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + drem $4,0 +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + drem $0,0 +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + drem $4,1 +# CHECK-TRAP: or $4, $zero, $zero # encoding: [0x25,0x20,0x00,0x00] + + drem $4,-1 +# CHECK-TRAP: or $4, $zero, $zero # encoding: [0x25,0x20,0x00,0x00] + + drem $4,2 +# CHECK-TRAP: addiu $1, $zero, 2 # encoding: [0x02,0x00,0x01,0x24] +# CHECK-TRAP: ddiv $zero, $4, $1 # encoding: [0x1e,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,0x10000 +# CHECK-TRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-TRAP: ddiv $zero, $4, $1 # encoding: [0x1e,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,0x1a5a5 +# CHECK-TRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-TRAP: ori $1, $1, 42405 # encoding: [0xa5,0xa5,0x21,0x34] +# CHECK-TRAP: ddiv $zero, $4, $1 # encoding: [0x1e,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,0x8000 +# CHECK-TRAP: ori $1, $zero, 32768 # encoding: [0x00,0x80,0x01,0x34] +# CHECK-TRAP: ddiv $zero, $4, $1 # encoding: [0x1e,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,-0x8000 +# CHECK-TRAP: addiu $1, $zero, -32768 # encoding: [0x00,0x80,0x01,0x24] +# CHECK-TRAP: ddiv $zero, $4, $1 # encoding: [0x1e,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,$5,$6 +# CHECK-TRAP: teq $6, $zero, 7 # encoding: [0xf4,0x01,0xc0,0x00] +# CHECK-TRAP: ddiv $zero, $5, $6 # encoding: [0x1e,0x00,0xa6,0x00] +# CHECK-TRAP: addiu $1, $zero, -1 # encoding: [0xff,0xff,0x01,0x24] +# CHECK-TRAP: bne $6, $1, .Ltmp3 # encoding: [A,A,0xc1,0x14] +# CHECK-TRAP; # fixup A - offset: 0, value: .Ltmp3-4, kind: fixup_Mips_PC16 +# CHECK-TRAP: addiu $1, $zero, 1 # encoding: [0x01,0x00,0x01,0x24] +# CHECK-TRAP: dsll32 $1, $1, 31 # encoding: [0xfc,0x0f,0x01,0x00] +# CHECK-TRAP: teq $5, $1, 6 # encoding: [0xb4,0x01,0xa1,0x00] +# CHECK-TRAP: .Ltmp3 +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,$5,$0 +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + drem $4,$0,$0 +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + drem $0,$5,$4 +# CHECK-TRAP: ddiv $zero, $5, $4 # encoding: [0x1e,0x00,0xa4,0x00] + + drem $4,$5,0 +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + drem $4,$0,0 +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + drem $0,$4,$5 +# CHECK-TRAP: ddiv $zero, $4, $5 # encoding: [0x1e,0x00,0x85,0x00] + + drem $4,$5,1 +# CHECK-TRAP: or $4, $zero, $zero # encoding: [0x25,0x20,0x00,0x00] + + drem $4,$5,-1 +# CHECK-TRAP: or $4, $zero, $zero # encoding: [0x25,0x20,0x00,0x00] + + drem $4,$5,2 +# CHECK-TRAP: addiu $1, $zero, 2 # encoding: [0x02,0x00,0x01,0x24] +# CHECK-TRAP: ddiv $zero, $5, $1 # encoding: [0x1e,0x00,0xa1,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,$5,0x10000 +# CHECK-TRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-TRAP: ddiv $zero, $5, $1 # encoding: [0x1e,0x00,0xa1,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,$5,0x1a5a5 +# CHECK-TRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-TRAP: ori $1, $1, 42405 # encoding: [0xa5,0xa5,0x21,0x34] +# CHECK-TRAP: ddiv $zero, $5, $1 # encoding: [0x1e,0x00,0xa1,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,$5,0x8000 +# CHECK-TRAP: ori $1, $zero, 32768 # encoding: [0x00,0x80,0x01,0x34] +# CHECK-TRAP: ddiv $zero, $5, $1 # encoding: [0x1e,0x00,0xa1,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + drem $4,$5,-0x8000 +# CHECK-TRAP: addiu $1, $zero, -32768 # encoding: [0x00,0x80,0x01,0x24] +# CHECK-TRAP: ddiv $zero, $5, $1 # encoding: [0x1e,0x00,0xa1,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] Index: llvm/trunk/test/MC/Mips/macro-dremu.s =================================================================== --- llvm/trunk/test/MC/Mips/macro-dremu.s +++ llvm/trunk/test/MC/Mips/macro-dremu.s @@ -0,0 +1,136 @@ +# RUN: llvm-mc %s -triple=mips64el-unknown-linux -show-encoding -mcpu=mips64 | \ +# RUN: FileCheck %s --check-prefix=CHECK-NOTRAP +# RUN: llvm-mc %s -triple=mips64el-unknown-linux -show-encoding -mcpu=mips64 \ +# RUN: -mattr=+use-tcc-in-div | FileCheck %s --check-prefix=CHECK-TRAP + + dremu $4,$5 +# CHECK-NOTRAP: bne $5, $zero, .Ltmp0 # encoding: [A,A,0xa0,0x14] +# CHECK-NOTRAP: # fixup A - offset: 0, value: .Ltmp0-4, kind: fixup_Mips_PC16 +# CHECK-NOTRAP: ddivu $zero, $4, $5 # encoding: [0x1f,0x00,0x85,0x00] +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-NOTRAP: .Ltmp0 +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: teq $5, $zero, 7 # encoding: [0xf4,0x01,0xa0,0x00] +# CHECK-TRAP: ddivu $zero, $4, $5 # encoding: [0x1f,0x00,0x85,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + dremu $4,$0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + dremu $4,0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + dremu $0,0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + dremu $4,1 +# CHECK-NOTRAP: or $4, $zero, $zero # encoding: [0x25,0x20,0x00,0x00] +# CHECK-TRAP: or $4, $zero, $zero # encoding: [0x25,0x20,0x00,0x00] + + dremu $4,2 +# CHECK-NOTRAP: addiu $1, $zero, 2 # encoding: [0x02,0x00,0x01,0x24] +# CHECK-NOTRAP: ddivu $zero, $4, $1 # encoding: [0x1f,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: addiu $1, $zero, 2 # encoding: [0x02,0x00,0x01,0x24] +# CHECK-TRAP: ddivu $zero, $4, $1 # encoding: [0x1f,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + dremu $4,-1 +# CHECK-NOTRAP: addiu $1, $zero, -1 # encoding: [0xff,0xff,0x01,0x24] +# CHECK-NOTRAP: ddivu $zero, $4, $1 # encoding: [0x1f,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: addiu $1, $zero, -1 # encoding: [0xff,0xff,0x01,0x24] +# CHECK-TRAP: ddivu $zero, $4, $1 # encoding: [0x1f,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + dremu $4,0x1a5a5 +# CHECK-NOTRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-NOTRAP: ori $1, $1, 42405 # encoding: [0xa5,0xa5,0x21,0x34] +# CHECK-NOTRAP: ddivu $zero, $4, $1 # encoding: [0x1f,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-TRAP: ori $1, $1, 42405 # encoding: [0xa5,0xa5,0x21,0x34] +# CHECK-TRAP: ddivu $zero, $4, $1 # encoding: [0x1f,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + dremu $4,0x10000 +# CHECK-NOTRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-NOTRAP: ddivu $zero, $4, $1 # encoding: [0x1f,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-TRAP: ddivu $zero, $4, $1 # encoding: [0x1f,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + dremu $4,-0x8000 +# CHECK-NOTRAP: addiu $1, $zero, -32768 # encoding: [0x00,0x80,0x01,0x24] +# CHECK-NOTRAP: ddivu $zero, $4, $1 # encoding: [0x1f,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: addiu $1, $zero, -32768 # encoding: [0x00,0x80,0x01,0x24] +# CHECK-TRAP: ddivu $zero, $4, $1 # encoding: [0x1f,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + dremu $4,0x8000 +# CHECK-NOTRAP: ori $1, $zero, 32768 # encoding: [0x00,0x80,0x01,0x34] +# CHECK-NOTRAP: ddivu $zero, $4, $1 # encoding: [0x1f,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: ori $1, $zero, 32768 # encoding: [0x00,0x80,0x01,0x34] +# CHECK-TRAP: ddivu $zero, $4, $1 # encoding: [0x1f,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + dremu $4,$5,$6 +# CHECK-NOTRAP: bne $6, $zero, .Ltmp1 # encoding: [A,A,0xc0,0x14] +# CHECK-NOTRAP: # fixup A - offset: 0, value: .Ltmp1-4, kind: fixup_Mips_PC16 +# CHECK-NOTRAP: ddivu $zero, $5, $6 # encoding: [0x1f,0x00,0xa6,0x00] +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-NOTRAP: .Ltmp1 +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: teq $6, $zero, 7 # encoding: [0xf4,0x01,0xc0,0x00] +# CHECK-TRAP: ddivu $zero, $5, $6 # encoding: [0x1f,0x00,0xa6,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + dremu $4,$5,$0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + dremu $4,$0,$0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + dremu $0,$4,$5 +# CHECK-NOTRAP: ddivu $zero, $4, $5 # encoding: [0x1f,0x00,0x85,0x00] +# CHECK-TRAP: ddivu $zero, $4, $5 # encoding: [0x1f,0x00,0x85,0x00] + + dremu $0,$5,$4 +# CHECK-NOTRAP: ddivu $zero, $5, $4 # encoding: [0x1f,0x00,0xa4,0x00] +# CHECK-TRAP: ddivu $zero, $5, $4 # encoding: [0x1f,0x00,0xa4,0x00] + + dremu $4,$5,0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + dremu $4,$0,0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + dremu $4,$5,1 +# CHECK-NOTRAP: or $4, $zero, $zero # encoding: [0x25,0x20,0x00,0x00] +# CHECK-TRAP: or $4, $zero, $zero # encoding: [0x25,0x20,0x00,0x00] + + dremu $4,$5,-1 +# CHECK-NOTRAP: addiu $1, $zero, -1 # encoding: [0xff,0xff,0x01,0x24] +# CHECK-NOTRAP: ddivu $zero, $5, $1 # encoding: [0x1f,0x00,0xa1,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: addiu $1, $zero, -1 # encoding: [0xff,0xff,0x01,0x24] +# CHECK-TRAP: ddivu $zero, $5, $1 # encoding: [0x1f,0x00,0xa1,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + dremu $4,$5,2 +# CHECK-NOTRAP: addiu $1, $zero, 2 # encoding: [0x02,0x00,0x01,0x24] +# CHECK-NOTRAP: ddivu $zero, $5, $1 # encoding: [0x1f,0x00,0xa1,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: addiu $1, $zero, 2 # encoding: [0x02,0x00,0x01,0x24] +# CHECK-TRAP: ddivu $zero, $5, $1 # encoding: [0x1f,0x00,0xa1,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] Index: llvm/trunk/test/MC/Mips/macro-rem.s =================================================================== --- llvm/trunk/test/MC/Mips/macro-rem.s +++ llvm/trunk/test/MC/Mips/macro-rem.s @@ -0,0 +1,187 @@ +# RUN: llvm-mc %s -triple=mipsel-unknown-linux -show-encoding -mcpu=mips32 | \ +# RUN: FileCheck %s --check-prefix=CHECK-NOTRAP +# RUN: llvm-mc %s -triple=mipsel-unknown-linux -show-encoding -mcpu=mips32 \ +# RUN: -mattr=+use-tcc-in-div | FileCheck %s --check-prefix=CHECK-TRAP + + rem $4,$5 +# CHECK-NOTRAP: bnez $5, $tmp0 # encoding: [A,A,0xa0,0x14] +# CHECK-NOTRAP: # fixup A - offset: 0, value: ($tmp0)-4, kind: fixup_Mips_PC16 +# CHECK-NOTRAP: div $zero, $4, $5 # encoding: [0x1a,0x00,0x85,0x00] +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-NOTRAP: $tmp0 +# CHECK-NOTRAP: addiu $1, $zero, -1 # encoding: [0xff,0xff,0x01,0x24] +# CHECK-NOTRAP: bne $5, $1, $tmp1 # encoding: [A,A,0xa1,0x14] +# CHECK-NOTRAP: # fixup A - offset: 0, value: ($tmp1)-4, kind: fixup_Mips_PC16 +# CHECK-NOTRAP: lui $1, 32768 # encoding: [0x00,0x80,0x01,0x3c] +# CHECK-NOTRAP: bne $4, $1, $tmp1 # encoding: [A,A,0x81,0x14] +# CHECK-NOTRAP: # fixup A - offset: 0, value: ($tmp1)-4, kind: fixup_Mips_PC16 +# CHECK-NOTRAP: nop # encoding: [0x00,0x00,0x00,0x00] +# CHECK-NOTRAP: break 6 # encoding: [0x0d,0x00,0x06,0x00] +# CHECK-NOTRAP: $tmp1 +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + +# CHECK-TRAP: teq $5, $zero, 7 # encoding: [0xf4,0x01,0xa0,0x00] +# CHECK-TRAP: div $zero, $4, $5 # encoding: [0x1a,0x00,0x85,0x00] +# CHECK-TRAP: addiu $1, $zero, -1 # encoding: [0xff,0xff,0x01,0x24] +# CHECK-TRAP: bne $5, $1, $tmp0 # encoding: [A,A,0xa1,0x14] +# CHECK-TRAP: lui $1, 32768 # encoding: [0x00,0x80,0x01,0x3c] +# CHECK-TRAP: teq $4, $1, 6 # encoding: [0xb4,0x01,0x81,0x00] +# CHECK-TRAP: $tmp0 +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + rem $4,$0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + rem $4,0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + rem $0,0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + rem $4,1 +# CHECK-NOTRAP: move $4, $zero # encoding: [0x25,0x20,0x00,0x00] +# CHECK-TRAP: move $4, $zero # encoding: [0x25,0x20,0x00,0x00] + + rem $4,-1 +# CHECK-NOTRAP: move $4, $zero # encoding: [0x25,0x20,0x00,0x00] +# CHECK-TRAP: move $4, $zero # encoding: [0x25,0x20,0x00,0x00] + + rem $4,2 +# CHECK-NOTRAP: addiu $1, $zero, 2 # encoding: [0x02,0x00,0x01,0x24] +# CHECK-NOTRAP: div $zero, $4, $1 # encoding: [0x1a,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: addiu $1, $zero, 2 # encoding: [0x02,0x00,0x01,0x24] +# CHECK-TRAP: div $zero, $4, $1 # encoding: [0x1a,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + rem $4,0x8000 +# CHECK-NOTRAP: ori $1, $zero, 32768 # encoding: [0x00,0x80,0x01,0x34] +# CHECK-NOTRAP: div $zero, $4, $1 # encoding: [0x1a,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: ori $1, $zero, 32768 # encoding: [0x00,0x80,0x01,0x34] +# CHECK-TRAP: div $zero, $4, $1 # encoding: [0x1a,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + rem $4,-0x8000 +# CHECK-NOTRAP: addiu $1, $zero, -32768 # encoding: [0x00,0x80,0x01,0x24] +# CHECK-NOTRAP: div $zero, $4, $1 # encoding: [0x1a,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: addiu $1, $zero, -32768 # encoding: [0x00,0x80,0x01,0x24] +# CHECK-TRAP: div $zero, $4, $1 # encoding: [0x1a,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + rem $4,0x10000 +# CHECK-NOTRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-NOTRAP: div $zero, $4, $1 # encoding: [0x1a,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-TRAP: div $zero, $4, $1 # encoding: [0x1a,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + rem $4,0x1a5a5 +# CHECK-NOTRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-NOTRAP: ori $1, $1, 42405 # encoding: [0xa5,0xa5,0x21,0x34] +# CHECK-NOTRAP: div $zero, $4, $1 # encoding: [0x1a,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-TRAP: ori $1, $1, 42405 # encoding: [0xa5,0xa5,0x21,0x34] +# CHECK-TRAP: div $zero, $4, $1 # encoding: [0x1a,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + rem $4,$5,$6 +# CHECK-NOTRAP: bnez $6, $tmp2 # encoding: [A,A,0xc0,0x14] +# CHECK-NOTRAP: div $zero, $5, $6 # encoding: [0x1a,0x00,0xa6,0x00] +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECk-NOTRAP: $tmp2 +# CHECK-NOTRAP: addiu $1, $zero, -1 # encoding: [0xff,0xff,0x01,0x24] +# CHECK-NOTRAP: bne $6, $1, $tmp3 # encoding: [A,A,0xc1,0x14] +# CHECK-NOTRAP: lui $1, 32768 # encoding: [0x00,0x80,0x01,0x3c] +# CHECK-NOTRAP: bne $5, $1, $tmp3 # encoding: [A,A,0xa1,0x14] +# CHECK-NOTRAP: nop # encoding: [0x00,0x00,0x00,0x00] +# CHECK-NOTRAP: break 6 # encoding: [0x0d,0x00,0x06,0x00] +# CHECK-NOTRAP: $tmp3 +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: teq $6, $zero, 7 # encoding: [0xf4,0x01,0xc0,0x00] +# CHECK-TRAP: div $zero, $5, $6 # encoding: [0x1a,0x00,0xa6,0x00] +# CHECK-TRAP: addiu $1, $zero, -1 # encoding: [0xff,0xff,0x01,0x24] +# CHECK-TRAP: bne $6, $1, $tmp1 # encoding: [A,A,0xc1,0x14] +# CHECK-TRAP: lui $1, 32768 # encoding: [0x00,0x80,0x01,0x3c] +# CHECK-TRAP: teq $5, $1, 6 # encoding: [0xb4,0x01,0xa1,0x00] +# CHECK-TRAP: $tmp1 +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + rem $4,$5,$0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + rem $4,$0,$0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + rem $0,$5,$4 +# CHECK-NOTRAP: div $zero, $5, $4 # encoding: [0x1a,0x00,0xa4,0x00] +# CHECK-TRAP: div $zero, $5, $4 # encoding: [0x1a,0x00,0xa4,0x00] + + rem $4,$5,0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + rem $4,$0,0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + rem $4,$5,1 +# CHECK-NOTRAP: move $4, $zero # encoding: [0x25,0x20,0x00,0x00] +# CHECK-TRAP: move $4, $zero # encoding: [0x25,0x20,0x00,0x00] + + rem $4,$5,-1 +# CHECK-NOTRAP: move $4, $zero # encoding: [0x25,0x20,0x00,0x00] +# CHECK-TRAP: move $4, $zero # encoding: [0x25,0x20,0x00,0x00] + + rem $4,$5,2 +# CHECK-NOTRAP: addiu $1, $zero, 2 # encoding: [0x02,0x00,0x01,0x24] +# CHECK-NOTRAP: div $zero, $5, $1 # encoding: [0x1a,0x00,0xa1,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: addiu $1, $zero, 2 # encoding: [0x02,0x00,0x01,0x24] +# CHECK-TRAP: div $zero, $5, $1 # encoding: [0x1a,0x00,0xa1,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + rem $4,$5,0x8000 +# CHECK-NOTRAP: ori $1, $zero, 32768 # encoding: [0x00,0x80,0x01,0x34] +# CHECK-NOTRAP: div $zero, $5, $1 # encoding: [0x1a,0x00,0xa1,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: ori $1, $zero, 32768 # encoding: [0x00,0x80,0x01,0x34] +# CHECK-TRAP: div $zero, $5, $1 # encoding: [0x1a,0x00,0xa1,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + + rem $4,$5,-0x8000 +# CHECK-NOTRAP: addiu $1, $zero, -32768 # encoding: [0x00,0x80,0x01,0x24] +# CHECK-NOTRAP: div $zero, $5, $1 # encoding: [0x1a,0x00,0xa1,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: addiu $1, $zero, -32768 # encoding: [0x00,0x80,0x01,0x24] +# CHECK-TRAP: div $zero, $5, $1 # encoding: [0x1a,0x00,0xa1,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + + rem $4,$5,0x10000 +# CHECK-NOTRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-NOTRAP: div $zero, $5, $1 # encoding: [0x1a,0x00,0xa1,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-TRAP: div $zero, $5, $1 # encoding: [0x1a,0x00,0xa1,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + + rem $4,$5,0x1a5a5 +# CHECK-NOTRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-NOTRAP: ori $1, $1, 42405 # encoding: [0xa5,0xa5,0x21,0x34] +# CHECK-NOTRAP: div $zero, $5, $1 # encoding: [0x1a,0x00,0xa1,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-TRAP: ori $1, $1, 42405 # encoding: [0xa5,0xa5,0x21,0x34] +# CHECK-TRAP: div $zero, $5, $1 # encoding: [0x1a,0x00,0xa1,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] Index: llvm/trunk/test/MC/Mips/macro-remu.s =================================================================== --- llvm/trunk/test/MC/Mips/macro-remu.s +++ llvm/trunk/test/MC/Mips/macro-remu.s @@ -0,0 +1,167 @@ +# RUN: llvm-mc %s -triple=mipsel-unknown-linux -show-encoding -mcpu=mips32 | \ +# RUN: FileCheck %s --check-prefix=CHECK-NOTRAP +# RUN: llvm-mc %s -triple=mipsel-unknown-linux -show-encoding -mcpu=mips32 \ +# RUN: -mattr=+use-tcc-in-div | FileCheck %s --check-prefix=CHECK-TRAP + + remu $4,$5 +# CHECK-NOTRAP: bnez $5, $tmp0 # encoding: [A,A,0xa0,0x14] +# CHECK-NOTRAP: # fixup A - offset: 0, value: ($tmp0)-4, kind: fixup_Mips_PC16 +# CHECK-NOTRAP: divu $zero, $4, $5 # encoding: [0x1b,0x00,0x85,0x00] +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: teq $5, $zero, 7 # encoding: [0xf4,0x01,0xa0,0x00] +# CHECK-TRAP: divu $zero, $4, $5 # encoding: [0x1b,0x00,0x85,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + remu $4,$0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + remu $4,0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + remu $0,0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + remu $4,1 +# CHECK-NOTRAP: move $4, $zero # encoding: [0x25,0x20,0x00,0x00] +# CHECK-TRAP: move $4, $zero # encoding: [0x25,0x20,0x00,0x00] + + remu $4,-1 +# CHECK-NOTRAP: addiu $1, $zero, -1 # encoding: [0xff,0xff,0x01,0x24] +# CHECK-NOTRAP: divu $zero, $4, $1 # encoding: [0x1b,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: addiu $1, $zero, -1 # encoding: [0xff,0xff,0x01,0x24] +# CHECK-TRAP: divu $zero, $4, $1 # encoding: [0x1b,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + remu $4,2 +# CHECK-NOTRAP: addiu $1, $zero, 2 # encoding: [0x02,0x00,0x01,0x24] +# CHECK-NOTRAP: divu $zero, $4, $1 # encoding: [0x1b,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: addiu $1, $zero, 2 # encoding: [0x02,0x00,0x01,0x24] +# CHECK-TRAP: divu $zero, $4, $1 # encoding: [0x1b,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + remu $4,0x8000 +# CHECK-NOTRAP: ori $1, $zero, 32768 # encoding: [0x00,0x80,0x01,0x34] +# CHECK-NOTRAP: divu $zero, $4, $1 # encoding: [0x1b,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: ori $1, $zero, 32768 # encoding: [0x00,0x80,0x01,0x34] +# CHECK-TRAP: divu $zero, $4, $1 # encoding: [0x1b,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + + remu $4,-0x8000 +# CHECK-NOTRAP: addiu $1, $zero, -32768 # encoding: [0x00,0x80,0x01,0x24] +# CHECK-NOTRAP: divu $zero, $4, $1 # encoding: [0x1b,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: addiu $1, $zero, -32768 # encoding: [0x00,0x80,0x01,0x24] +# CHECK-TRAP: divu $zero, $4, $1 # encoding: [0x1b,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + remu $4,0x10000 +# CHECK-NOTRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-NOTRAP: divu $zero, $4, $1 # encoding: [0x1b,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-TRAP: divu $zero, $4, $1 # encoding: [0x1b,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + remu $4,0x1a5a5 +# CHECK-NOTRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-NOTRAP: ori $1, $1, 42405 # encoding: [0xa5,0xa5,0x21,0x34] +# CHECK-NOTRAP: divu $zero, $4, $1 # encoding: [0x1b,0x00,0x81,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-TRAP: ori $1, $1, 42405 # encoding: [0xa5,0xa5,0x21,0x34] +# CHECK-TRAP: divu $zero, $4, $1 # encoding: [0x1b,0x00,0x81,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + remu $4,$5,$6 +# CHECK-NOTRAP: bnez $6, $tmp1 # encoding: [A,A,0xc0,0x14] +# CHECK-NOTRAP: # fixup A - offset: 0, value: ($tmp1)-4, kind: fixup_Mips_PC16 +# CHECK-NOTRAP: divu $zero, $5, $6 # encoding: [0x1b,0x00,0xa6,0x00] +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-NOTRAP: $tmp1 +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: teq $6, $zero, 7 # encoding: [0xf4,0x01,0xc0,0x00] +# CHECK-TRAP: divu $zero, $5, $6 # encoding: [0x1b,0x00,0xa6,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + + remu $4,$5,$0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + remu $4,$0,$0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + remu $0,$5,$4 +# CHECK-NOTRAP: divu $zero, $5, $4 # encoding: [0x1b,0x00,0xa4,0x00] +# CHECK-TRAP: divu $zero, $5, $4 # encoding: [0x1b,0x00,0xa4,0x00] + + remu $4,$5,0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + remu $4,$0,0 +# CHECK-NOTRAP: break 7 # encoding: [0x0d,0x00,0x07,0x00] +# CHECK-TRAP: teq $zero, $zero, 7 # encoding: [0xf4,0x01,0x00,0x00] + + remu $4,$5,1 +# CHECK-NOTRAP: move $4, $zero # encoding: [0x25,0x20,0x00,0x00] +# CHECK-TRAP: move $4, $zero # encoding: [0x25,0x20,0x00,0x00] + + remu $4,$5,-1 +# CHECK-NOTRAP: addiu $1, $zero, -1 # encoding: [0xff,0xff,0x01,0x24] +# CHECK-NOTRAP: divu $zero, $5, $1 # encoding: [0x1b,0x00,0xa1,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: addiu $1, $zero, -1 # encoding: [0xff,0xff,0x01,0x24] +# CHECK-TRAP: divu $zero, $5, $1 # encoding: [0x1b,0x00,0xa1,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + remu $4,$5,2 +# CHECK-NOTRAP: addiu $1, $zero, 2 # encoding: [0x02,0x00,0x01,0x24] +# CHECK-NOTRAP: divu $zero, $5, $1 # encoding: [0x1b,0x00,0xa1,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: addiu $1, $zero, 2 # encoding: [0x02,0x00,0x01,0x24] +# CHECK-TRAP: divu $zero, $5, $1 # encoding: [0x1b,0x00,0xa1,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + remu $4,$5,0x8000 +# CHECK-NOTRAP: ori $1, $zero, 32768 # encoding: [0x00,0x80,0x01,0x34] +# CHECK-NOTRAP: divu $zero, $5, $1 # encoding: [0x1b,0x00,0xa1,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: ori $1, $zero, 32768 # encoding: [0x00,0x80,0x01,0x34] +# CHECK-TRAP: divu $zero, $5, $1 # encoding: [0x1b,0x00,0xa1,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + remu $4,$5,-0x8000 +# CHECK-NOTRAP: addiu $1, $zero, -32768 # encoding: [0x00,0x80,0x01,0x24] +# CHECK-NOTRAP: divu $zero, $5, $1 # encoding: [0x1b,0x00,0xa1,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: addiu $1, $zero, -32768 # encoding: [0x00,0x80,0x01,0x24] +# CHECK-TRAP: divu $zero, $5, $1 # encoding: [0x1b,0x00,0xa1,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + remu $4,$5,0x10000 +# CHECK-NOTRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-NOTRAP: divu $zero, $5, $1 # encoding: [0x1b,0x00,0xa1,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-TRAP: divu $zero, $5, $1 # encoding: [0x1b,0x00,0xa1,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] + + remu $4,$5,0x1a5a5 +# CHECK-NOTRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-NOTRAP: ori $1, $1, 42405 # encoding: [0xa5,0xa5,0x21,0x34] +# CHECK-NOTRAP: divu $zero, $5, $1 # encoding: [0x1b,0x00,0xa1,0x00] +# CHECK-NOTRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00] +# CHECK-TRAP: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c] +# CHECK-TRAP: ori $1, $1, 42405 # encoding: [0xa5,0xa5,0x21,0x34] +# CHECK-TRAP: divu $zero, $5, $1 # encoding: [0x1b,0x00,0xa1,0x00] +# CHECK-TRAP: mfhi $4 # encoding: [0x10,0x20,0x00,0x00]