Skip to content

Commit eaf7bb6

Browse files
committed
[squashme] Add llvm.launder.alignment intrinsic and use that to lower cheri_address_get
1 parent 806b441 commit eaf7bb6

File tree

5 files changed

+10
-3
lines changed

5 files changed

+10
-3
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6030,7 +6030,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
60306030
const auto *Arg = E->getArg(0);
60316031
auto *RArg = EmitScalarExpr(Arg);
60326032
if (Arg->getType()->isCHERISealedCapabilityType(getContext()))
6033-
RArg = Builder.CreateLaunderInvariantGroup(RArg);
6033+
RArg = Builder.CreateIntrinsic(llvm::Intrinsic::launder_alignment,
6034+
{UnqualPtrTy}, {RArg});
60346035
return RValue::get(Builder.CreateIntrinsic(
60356036
llvm::Intrinsic::cheri_cap_address_get, {IntPtrTy}, {RArg}));
60366037
}

clang/test/CodeGen/cheri/riscv/cheriot-static-sealed-value-attr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void func() {
4040
// This is because the CHERIoT RTOS uses the lower bits of the address to store the permissions of the sealed capability, and KnownBits can in turn
4141
// optimise away logical computations on lower parts of the address.
4242

43-
// CHECK: %0 = tail call ptr addrspace(200) @llvm.launder.invariant.group.p200(ptr addrspace(200) nonnull @Obj1)
43+
// CHECK: %0 = tail call ptr addrspace(200) @llvm.launder.alignment.p200(ptr addrspace(200) nonnull @Obj1)
4444
// CHECK: %1 = tail call i32 @llvm.cheri.cap.address.get.i32(ptr addrspace(200) nonnull %0)
4545
// CHECK: tail call void @doSomethingWithAddr(i32 noundef %1) #5
4646
doSomethingWithAddr(__builtin_cheri_address_get(&Obj1));
@@ -51,6 +51,6 @@ void func() {
5151

5252
// CHECK: declare void @doSomething(ptr addrspace(200) noundef) local_unnamed_addr addrspace(200) #2
5353
// CHECK: declare void @doSomethingWithAddr(i32 noundef) local_unnamed_addr addrspace(200) #2
54-
// CHECK: declare ptr addrspace(200) @llvm.launder.invariant.group.p200(ptr addrspace(200)) addrspace(200) #3
54+
// CHECK: declare ptr addrspace(200) @llvm.launder.alignment.p200(ptr addrspace(200)) addrspace(200) #3
5555
// CHECK: declare i32 @llvm.cheri.cap.address.get.i32(ptr addrspace(200)) addrspace(200) #4
5656
// CHECK: declare void @doSomething2(ptr addrspace(200) noundef) local_unnamed_addr addrspace(200) #2

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,10 @@ def int_strip_invariant_group : DefaultAttrsIntrinsic<[llvm_anyptr_ty],
16991699
[LLVMMatchType<0>],
17001700
[IntrSpeculatable, IntrNoMem]>;
17011701

1702+
def int_launder_alignment : DefaultAttrsIntrinsic<[llvm_anyptr_ty],
1703+
[LLVMMatchType<0>],
1704+
[IntrInaccessibleMemOnly, IntrSpeculatable]>;
1705+
17021706
//===------------------------ Stackmap Intrinsics -------------------------===//
17031707
//
17041708
def int_experimental_stackmap : DefaultAttrsIntrinsic<[],

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6757,6 +6757,7 @@ bool llvm::isIntrinsicReturningPointerAliasingArgumentWithoutCapturing(
67576757
// MustPreserveNullness (and, at time of writing, they are not), but we
67586758
// document this fact out of an abundance of caution.
67596759
case Intrinsic::amdgcn_make_buffer_rsrc:
6760+
case Intrinsic::launder_alignment:
67606761
return true;
67616762
case Intrinsic::ptrmask:
67626763
return !MustPreserveNullness;

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7463,6 +7463,7 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
74637463
case Intrinsic::annotation:
74647464
case Intrinsic::ptr_annotation:
74657465
case Intrinsic::launder_invariant_group:
7466+
case Intrinsic::launder_alignment:
74667467
case Intrinsic::strip_invariant_group:
74677468
// Drop the intrinsic, but forward the value
74687469
setValue(&I, getValue(I.getOperand(0)));

0 commit comments

Comments
 (0)