Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions llvm/lib/Target/RISCV/RISCVInstrInfoXCheri.td
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,14 @@ def : PatGpcrGpcr<int_cheri_cap_type_copy, CCopyType>;
def : PatGpcrGpcr<int_cheri_cap_conditional_seal, CCSeal>;
def : PatGpcr<int_cheri_cap_seal_entry, CSealEntry, CLenVT>;

def uimm12_lt512 : Operand<XLenVT>,
ImmLeaf<XLenVT, "return isUInt<12>(Imm) && (Imm < 512);">;

let Predicates =
[HasCheriot] in def : Pat<(int_cheri_cap_bounds_set_exact GPCR:$rs1,
uimm12_lt512:$imm12),
(CSetBoundsImm GPCR:$rs1, uimm12_lt512:$imm12)>;

// TODO: Make this rematerialisable like MIPS
def : PatGpcrGpr<int_cheri_bounded_stack_cap, CSetBounds>;
def : PatGpcrUimm12<int_cheri_bounded_stack_cap, CSetBoundsImm>;
Expand Down
32 changes: 32 additions & 0 deletions llvm/test/CodeGen/RISCV/cheri/cheriot-csetboundsexact.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc -mtriple=riscv32cheriot --mcpu=cheriot -target-abi=cheriot -mattr=+xcheri,+cap-mode,+xcheriot -o - %s | FileCheck %s

define i8 addrspace(200)* @test1(i8 addrspace(200)* %cap, i32 %bounds) nounwind {
; CHECK-LABEL: test1:
; CHECK: # %bb.0:
; CHECK-NEXT: ct.csetbounds ca0, ca0, 3
; CHECK-NEXT: ct.cret
%newcap = call i8 addrspace(200)* @llvm.cheri.cap.bounds.set.exact.i32(i8 addrspace(200)* %cap, i32 3)
ret i8 addrspace(200)* %newcap
}

define i8 addrspace(200)* @test2(i8 addrspace(200)* %cap, i32 %bounds) nounwind {
; CHECK-LABEL: test2:
; CHECK: # %bb.0:
; CHECK-NEXT: ct.csetbounds ca0, ca0, 511
; CHECK-NEXT: ct.cret
%newcap = call i8 addrspace(200)* @llvm.cheri.cap.bounds.set.exact.i32(i8 addrspace(200)* %cap, i32 511)
ret i8 addrspace(200)* %newcap
}

define i8 addrspace(200)* @test3(i8 addrspace(200)* %cap, i32 %bounds) nounwind {
; CHECK-LABEL: test3:
; CHECK: # %bb.0:
; CHECK-NEXT: li a1, 512
; CHECK-NEXT: ct.csetboundsexact ca0, ca0, a1
; CHECK-NEXT: ct.cret
%newcap = call i8 addrspace(200)* @llvm.cheri.cap.bounds.set.exact.i32(i8 addrspace(200)* %cap, i32 512)
ret i8 addrspace(200)* %newcap
}

declare i8 addrspace(200)* @llvm.cheri.cap.bounds.set.exact.i32(i8 addrspace(200)*, i32)