diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXCheri.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXCheri.td index 0b0cf06d16d44..84455c9d3507f 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoXCheri.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXCheri.td @@ -1450,6 +1450,14 @@ def : PatGpcrGpcr; def : PatGpcrGpcr; def : PatGpcr; +def uimm12_lt512 : Operand, + ImmLeaf(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; def : PatGpcrUimm12; diff --git a/llvm/test/CodeGen/RISCV/cheri/cheriot-csetboundsexact.ll b/llvm/test/CodeGen/RISCV/cheri/cheriot-csetboundsexact.ll new file mode 100644 index 0000000000000..801e5818bea11 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/cheri/cheriot-csetboundsexact.ll @@ -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)