Skip to content

Commit

Permalink
[SOL] Enable mod instruction (anza-xyz#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte authored Feb 23, 2024
1 parent 9003b43 commit afc2d3d
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 11 deletions.
1 change: 0 additions & 1 deletion llvm/lib/Target/SBF/SBFISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/SBF/SBFInstrFormats.td
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/SBF/SBFInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ let Constraints = "$dst = $src2" in {
let Predicates = [SBFNoPqrInstr] in {
defm MUL : ALU<SBF_MUL, "mul", mul>;
defm DIV : ALU<SBF_DIV, "div", udiv>;
defm MOD : ALU<SBF_MOD, "mod", urem>;
}

let Predicates = [SBFPqrInstr] in {
Expand Down
26 changes: 26 additions & 0 deletions llvm/test/CodeGen/SBF/32-bit-subreg-alu.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions llvm/test/CodeGen/SBF/mod-64.ll
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 5 additions & 10 deletions llvm/test/CodeGen/SBF/pqr-class.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]+}}
Expand Down
14 changes: 14 additions & 0 deletions llvm/test/MC/Disassembler/SBF/sbf-alu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

17 changes: 17 additions & 0 deletions llvm/test/MC/SBF/sbf-alu.s
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit afc2d3d

Please sign in to comment.