Skip to content

Commit 6f6cbe9

Browse files
committed
Use assume operand bundles for assume_nonnull.
1 parent 63f6845 commit 6f6cbe9

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,26 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
782782
*self = Self::build(self.cx, next_bb);
783783
}
784784

785+
fn assume_nonnull(&mut self, val: Self::Value) {
786+
let (ty, f) = self.cx.get_intrinsic("llvm.assume".into(), &[]);
787+
let const_true = self.cx.const_bool(true);
788+
let meta = llvm::OperandBundleBox::new("nonnull", &[val]);
789+
let args = [const_true];
790+
let bundles = [meta.as_ref()];
791+
unsafe {
792+
llvm::LLVMBuildCallWithOperandBundles(
793+
self.llbuilder,
794+
ty,
795+
f,
796+
args.as_ptr(),
797+
1,
798+
bundles.as_ptr(),
799+
1,
800+
c"".as_ptr(),
801+
);
802+
}
803+
}
804+
785805
fn range_metadata(&mut self, load: &'ll Value, range: WrappingRange) {
786806
if self.cx.sess().opts.optimize == OptLevel::No {
787807
// Don't emit metadata we're not going to use

tests/codegen-llvm/intrinsics/transmute-niched.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ pub unsafe fn check_bool_to_ordering(x: bool) -> std::cmp::Ordering {
193193
pub unsafe fn check_nonnull_to_ptr(x: NonNull<u8>) -> *const u8 {
194194
// CHECK-NOT: icmp
195195
// CHECK-NOT: assume
196-
// OPT: %0 = icmp ne ptr %x, null
197-
// OPT: call void @llvm.assume(i1 %0)
196+
// OPT: call void @llvm.assume(i1 true) [ "nonnull"(ptr %x) ]
198197
// CHECK-NOT: icmp
199198
// CHECK-NOT: assume
200199
// CHECK: ret ptr %x
@@ -207,8 +206,7 @@ pub unsafe fn check_nonnull_to_ptr(x: NonNull<u8>) -> *const u8 {
207206
pub unsafe fn check_ptr_to_nonnull(x: *const u8) -> NonNull<u8> {
208207
// CHECK-NOT: icmp
209208
// CHECK-NOT: assume
210-
// OPT: %0 = icmp ne ptr %x, null
211-
// OPT: call void @llvm.assume(i1 %0)
209+
// OPT: call void @llvm.assume(i1 true) [ "nonnull"(ptr %x) ]
212210
// CHECK-NOT: icmp
213211
// CHECK-NOT: assume
214212
// CHECK: ret ptr %x

tests/codegen-llvm/intrinsics/transmute.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,10 @@ pub unsafe fn check_issue_110005(x: (usize, bool)) -> Option<Box<[u8]>> {
379379
#[no_mangle]
380380
pub unsafe fn check_pair_to_dst_ref<'a>(x: (usize, usize)) -> &'a [u8] {
381381
// CHECK: %_0.0 = getelementptr i8, ptr null, i64 %x.0
382-
// CHECK: %0 = icmp ne ptr %_0.0, null
383-
// CHECK: call void @llvm.assume(i1 %0)
384-
// CHECK: %1 = insertvalue { ptr, i64 } poison, ptr %_0.0, 0
385-
// CHECK: %2 = insertvalue { ptr, i64 } %1, i64 %x.1, 1
386-
// CHECK: ret { ptr, i64 } %2
382+
// CHECK: call void @llvm.assume(i1 true) [ "nonnull"(ptr %_0.0) ]
383+
// CHECK: %0 = insertvalue { ptr, i64 } poison, ptr %_0.0, 0
384+
// CHECK: %1 = insertvalue { ptr, i64 } %0, i64 %x.1, 1
385+
// CHECK: ret { ptr, i64 } %1
387386
transmute(x)
388387
}
389388

0 commit comments

Comments
 (0)