Skip to content

Commit f162d7e

Browse files
committed
[CHERIoT] Fold csetboundsexact to csetboundsimm when the bounds is a constant less than 512.
This is guaranteed always to be exact, and it saves materializing the constant.
1 parent 724c9a1 commit f162d7e

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoXCheri.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,14 @@ def : PatGpcrGpcr<int_cheri_cap_type_copy, CCopyType>;
14501450
def : PatGpcrGpcr<int_cheri_cap_conditional_seal, CCSeal>;
14511451
def : PatGpcr<int_cheri_cap_seal_entry, CSealEntry, CLenVT>;
14521452

1453+
def uimm12_lt512 : Operand<XLenVT>,
1454+
ImmLeaf<XLenVT, "return isUInt<12>(Imm) && (Imm < 512);">;
1455+
1456+
let Predicates =
1457+
[HasCheriot] in def : Pat<(int_cheri_cap_bounds_set_exact GPCR:$rs1,
1458+
uimm12_lt512:$imm12),
1459+
(CSetBoundsImm GPCR:$rs1, uimm12_lt512:$imm12)>;
1460+
14531461
// TODO: Make this rematerialisable like MIPS
14541462
def : PatGpcrGpr<int_cheri_bounded_stack_cap, CSetBounds>;
14551463
def : PatGpcrUimm12<int_cheri_bounded_stack_cap, CSetBoundsImm>;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=riscv32cheriot --mcpu=cheriot -target-abi=cheriot -mattr=+xcheri,+cap-mode,+xcheriot -o - %s | FileCheck %s
3+
4+
define i8 addrspace(200)* @test1(i8 addrspace(200)* %cap, i32 %bounds) nounwind {
5+
; CHECK-LABEL: test1:
6+
; CHECK: # %bb.0:
7+
; CHECK-NEXT: ct.csetbounds ca0, ca0, 3
8+
; CHECK-NEXT: ct.cret
9+
%newcap = call i8 addrspace(200)* @llvm.cheri.cap.bounds.set.exact.i32(i8 addrspace(200)* %cap, i32 3)
10+
ret i8 addrspace(200)* %newcap
11+
}
12+
13+
define i8 addrspace(200)* @test2(i8 addrspace(200)* %cap, i32 %bounds) nounwind {
14+
; CHECK-LABEL: test2:
15+
; CHECK: # %bb.0:
16+
; CHECK-NEXT: ct.csetbounds ca0, ca0, 511
17+
; CHECK-NEXT: ct.cret
18+
%newcap = call i8 addrspace(200)* @llvm.cheri.cap.bounds.set.exact.i32(i8 addrspace(200)* %cap, i32 511)
19+
ret i8 addrspace(200)* %newcap
20+
}
21+
22+
define i8 addrspace(200)* @test3(i8 addrspace(200)* %cap, i32 %bounds) nounwind {
23+
; CHECK-LABEL: test3:
24+
; CHECK: # %bb.0:
25+
; CHECK-NEXT: li a1, 512
26+
; CHECK-NEXT: ct.csetboundsexact ca0, ca0, a1
27+
; CHECK-NEXT: ct.cret
28+
%newcap = call i8 addrspace(200)* @llvm.cheri.cap.bounds.set.exact.i32(i8 addrspace(200)* %cap, i32 512)
29+
ret i8 addrspace(200)* %newcap
30+
}
31+
32+
declare i8 addrspace(200)* @llvm.cheri.cap.bounds.set.exact.i32(i8 addrspace(200)*, i32)

0 commit comments

Comments
 (0)