diff --git a/llvm/lib/Target/SBF/SBFISelLowering.cpp b/llvm/lib/Target/SBF/SBFISelLowering.cpp index f87cb9d28230ac..70663966d7ad36 100644 --- a/llvm/lib/Target/SBF/SBFISelLowering.cpp +++ b/llvm/lib/Target/SBF/SBFISelLowering.cpp @@ -123,7 +123,6 @@ SBFTargetLowering::SBFTargetLowering(const TargetMachine &TM, if (Subtarget->isSolana() && !STI.getHasPqrClass()) { setOperationAction(ISD::SDIV, VT, Expand); setOperationAction(ISD::SREM, VT, Expand); - setOperationAction(ISD::UREM, VT, Expand); setOperationAction(ISD::MULHU, VT, Expand); setOperationAction(ISD::MULHS, VT, Expand); } diff --git a/llvm/lib/Target/SBF/SBFInstrFormats.td b/llvm/lib/Target/SBF/SBFInstrFormats.td index 2bc92f939dde42..8a772e3bf1cc6e 100644 --- a/llvm/lib/Target/SBF/SBFInstrFormats.td +++ b/llvm/lib/Target/SBF/SBFInstrFormats.td @@ -39,6 +39,7 @@ def SBF_AND : SBFArithOp<0x5>; def SBF_LSH : SBFArithOp<0x6>; def SBF_RSH : SBFArithOp<0x7>; def SBF_NEG : SBFArithOp<0x8>; +def SBF_MOD : SBFArithOp<0x9>; def SBF_XOR : SBFArithOp<0xa>; def SBF_MOV : SBFArithOp<0xb>; def SBF_ARSH : SBFArithOp<0xc>; diff --git a/llvm/lib/Target/SBF/SBFInstrInfo.td b/llvm/lib/Target/SBF/SBFInstrInfo.td index 84cdf3aa1a55d3..4bc620a97e81ba 100644 --- a/llvm/lib/Target/SBF/SBFInstrInfo.td +++ b/llvm/lib/Target/SBF/SBFInstrInfo.td @@ -324,6 +324,7 @@ let Constraints = "$dst = $src2" in { let Predicates = [SBFNoPqrInstr] in { defm MUL : ALU; defm DIV : ALU; + defm MOD : ALU; } let Predicates = [SBFPqrInstr] in { diff --git a/llvm/test/CodeGen/SBF/32-bit-subreg-alu.ll b/llvm/test/CodeGen/SBF/32-bit-subreg-alu.ll index 17c13fa3215f11..91183a6a09eadb 100644 --- a/llvm/test/CodeGen/SBF/32-bit-subreg-alu.ll +++ b/llvm/test/CodeGen/SBF/32-bit-subreg-alu.ll @@ -51,6 +51,16 @@ ; return a / 0xf; ; } ; +; unsigned rem(unsigned a, unsigned b) +; { +; return a % b; +; } +; +; unsigned rem_i(unsigned a) +; { +; return a % 0xf; +; } +; ; int or(int a, int b) ; { ; return a | b; @@ -194,6 +204,22 @@ entry: ret i32 %div } +; Function Attrs: norecurse nounwind readnone +define dso_local i32 @rem(i32 %a, i32 %b) local_unnamed_addr #0 { +entry: + %rem = urem i32 %a, %b +; CHECK: mod32 w{{[0-9]+}}, w{{[0-9]+}} + ret i32 %rem +} + +; Function Attrs: norecurse nounwind readnone +define dso_local i32 @rem_i(i32 %a) local_unnamed_addr #0 { +entry: + %rem = urem i32 %a, 15 +; CHECK: mod32 w{{[0-9]+}}, 15 + ret i32 %rem +} + ; Function Attrs: norecurse nounwind readnone define dso_local i32 @or(i32 %a, i32 %b) local_unnamed_addr #0 { entry: diff --git a/llvm/test/CodeGen/SBF/mod-64.ll b/llvm/test/CodeGen/SBF/mod-64.ll new file mode 100644 index 00000000000000..5a8ec18c6e3b91 --- /dev/null +++ b/llvm/test/CodeGen/SBF/mod-64.ll @@ -0,0 +1,17 @@ +; RUN: llc -O2 -march=sbf < %s | FileCheck %s + +; Function Attrs: norecurse nounwind readnone +define dso_local i64 @rem(i64 %a, i64 %b) local_unnamed_addr #0 { +entry: + %rem = urem i64 %a, %b +; CHECK: mod64 r{{[0-9]+}}, r{{[0-9]+}} + ret i64 %rem +} + +; Function Attrs: norecurse nounwind readnone +define dso_local i64 @rem_i(i64 %a) local_unnamed_addr #0 { +entry: + %rem = urem i64 %a, 15 +; CHECK: mod64 r{{[0-9]+}}, 15 + ret i64 %rem +} \ No newline at end of file diff --git a/llvm/test/CodeGen/SBF/pqr-class.ll b/llvm/test/CodeGen/SBF/pqr-class.ll index 7c8e01093a4ed4..c9adcda5b79e9e 100644 --- a/llvm/test/CodeGen/SBF/pqr-class.ll +++ b/llvm/test/CodeGen/SBF/pqr-class.ll @@ -16,15 +16,13 @@ entry: ; CHECK-v2: lmul64 r{{[0-9]+}}, r2 ; CHECK-V2: lmul64 r{{[0-9]+}}, 7 +; CHECK-v1: mod64 r{{[0-9]+}}, r{{[0-9]+}} ; CHECK-v1: div64 r{{[0-9]+}}, r{{[0-9]+}} -; CHECK-v1: mul64 r{{[0-9]+}}, r{{[0-9]+}} -; CHECK-v1: sub64 r{{[0-9]+}}, r{{[0-9]+}} ; CHECK-v1: add64 r{{[0-9]+}}, r{{[0-9]+}} -; CHECK-v1: div64 r{{[0-9]+}}, 17 -; CHECK-v1: mul64 r{{[0-9]+}}, 17 ; CHECK-v1: mov64 r{{[0-9]+}}, r{{[0-9]+}} -; CHECK-v1: sub64 r{{[0-9]+}}, r{{[0-9]+}} +; CHECK-v1: mod64 r{{[0-9]+}}, 17 ; CHECK-v1: div64 r{{[0-9]+}}, 7 +; CHECK-v1: add64 r{{[0-9]+}}, r{{[0-9]+}} ; CHECK-v1: mul64 r{{[0-9]+}}, r{{[0-9]+}} ; CHECK-v1: mul64 r{{[0-9]+}}, 7 @@ -79,14 +77,11 @@ entry: ; CHECK-v2: lmul32 w{{[0-9]+}}, w{{[0-9]+}} ; CHECK-v2: lmul32 w{{[0-9]+}}, 7 +; CHECK-v1: mod32 w{{[0-9]+}}, w{{[0-9]+}} ; CHECK-v1: div32 w{{[0-9]+}}, w{{[0-9]+}} -; CHECK-v1: mul32 w{{[0-9]+}}, w{{[0-9]+}} -; CHECK-v1: sub32 w{{[0-9]+}}, w{{[0-9]+}} ; CHECK-v1: add32 w{{[0-9]+}}, w{{[0-9]+}} -; CHECK-v1: div32 w{{[0-9]+}}, 17 -; CHECK-v1: mul32 w{{[0-9]+}}, 17 ; CHECK-v1: mov32 w{{[0-9]+}}, w{{[0-9]+}} -; CHECK-v1: sub32 w{{[0-9]+}}, w{{[0-9]+}} +; CHECK-v1: mod32 w{{[0-9]+}}, 17 ; CHECK-v1: div32 w{{[0-9]+}}, 7 ; CHECK-v1: add32 w{{[0-9]+}}, w{{[0-9]+}} ; CHECK-v1: mul32 w{{[0-9]+}}, w{{[0-9]+}} diff --git a/llvm/test/MC/Disassembler/SBF/sbf-alu.txt b/llvm/test/MC/Disassembler/SBF/sbf-alu.txt index 20e3f701c0d8f6..58dc229c7cdc9e 100644 --- a/llvm/test/MC/Disassembler/SBF/sbf-alu.txt +++ b/llvm/test/MC/Disassembler/SBF/sbf-alu.txt @@ -241,3 +241,17 @@ 0xdc,0x00,0x00,0x00,0x10,0x00,0x00,0x00 0xdc,0x01,0x00,0x00,0x20,0x00,0x00,0x00 0xdc,0x02,0x00,0x00,0x40,0x00,0x00,0x00 + + +# CHECK-NEW: mod64 r3, r1 +0x9f,0x13,0x00,0x00,0x00,0x00,0x00,0x00 + +# CHECK-NEW: mod64 r3, 123 +0x97,0x03,0x00,0x00,0x7b,0x00,0x00,0x00 + +# CHECK-NEW: mod32 w6, w2 +0x9c,0x26,0x00,0x00,0x00,0x00,0x00,0x00 + +# CHECK-NEW: mod32 w5, -12 +0x94,0x05,0x00,0x00,0x85,0xff,0xff,0xff + diff --git a/llvm/test/MC/SBF/sbf-alu.s b/llvm/test/MC/SBF/sbf-alu.s index eb0d5da9de0411..7e29513cbf2dad 100644 --- a/llvm/test/MC/SBF/sbf-alu.s +++ b/llvm/test/MC/SBF/sbf-alu.s @@ -318,3 +318,20 @@ mov32 w5, -123 be16 r0 be32 r1 be64 r2 + + +# CHECK-OBJ-NEW: mod64 r3, r1 +# CHECK-ASM-NEW: encoding: [0x9f,0x13,0x00,0x00,0x00,0x00,0x00,0x00] +mod64 r3, r1 + +# CHECK-OBJ-NEW: mod64 r3, 0x7b +# CHECK-ASM-NEW: encoding: [0x97,0x03,0x00,0x00,0x7b,0x00,0x00,0x00] +mod64 r3, 123 + +# CHECK-OBJ-NEW: mod32 w6, w2 +# CHECK-ASM-NEW: encoding: [0x9c,0x26,0x00,0x00,0x00,0x00,0x00,0x00] +mod32 w6, w2 + +# CHECK-OBJ-NEW: mod32 w5, -0x7b +# CHECK-ASM-NEW: encoding: [0x94,0x05,0x00,0x00,0x85,0xff,0xff,0xff] +mod32 w5, -123 \ No newline at end of file