Skip to content

Commit ae9dd3b

Browse files
committed
!fixup undo nonnull assumption, clarify docs
1 parent 914cfc4 commit ae9dd3b

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,7 +2764,7 @@ Query for this feature with ``__has_builtin(__builtin_assume_separate_storage)``
27642764
``__builtin_assume_dereferenceable``
27652765
-------------------------------------
27662766
2767-
``__builtin_assume_derefernceable`` is used to provide the optimizer with the
2767+
``__builtin_assume_dereferenceable`` is used to provide the optimizer with the
27682768
knowledge that the pointer argument P is dereferenceable up to the specified
27692769
number of bytes.
27702770
@@ -2779,20 +2779,26 @@ number of bytes.
27792779
.. code-block:: c++
27802780
27812781
int foo(int *x, int y) {
2782-
__builtin_assume_dereferenceable(x, 4);
2782+
__builtin_assume_dereferenceable(x, sizeof(int));
27832783
int z = 0;
27842784
if (y == 1) {
2785-
// The optimizer may execute the load of x unconditionally.
2785+
// The optimizer may execute the load of x unconditionally due to
2786+
// __builtin_assume_dereferenceable guaranteeing sizeof(int) bytes can
2787+
// be loaded speculatively without trapping.
27862788
z = *x;
2787-
}
2789+
}
27882790
return z;
27892791
}
27902792
27912793
**Description**:
27922794
27932795
The arguments to this function provide a start pointer ``P`` and a size ``S``.
2794-
``P`` must be non-null and ``S`` at least 1. The optimizer may assume that
2795-
``S`` bytes are dereferenceable starting at ``P``.
2796+
``S`` must be at least 1 and a constant. The optimizer may assume that ``S``
2797+
bytes are dereferenceable starting at ``P``. Note that this does not necessarily
2798+
imply that ``P`` is non-null as ``nullptr`` can be dereferenced in some cases.
2799+
The assumption also does not imply that ``P`` is not dereferenceable past ``S``
2800+
bytes.
2801+
27962802
27972803
Query for this feature with ``__has_builtin(__builtin_assume_dereferenceable)``.
27982804

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3723,7 +3723,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
37233723
SizeValue =
37243724
Builder.CreateIntCast(SizeValue, IntPtrTy, false, "casted.size");
37253725
Builder.CreateDereferenceableAssumption(PtrValue, SizeValue);
3726-
Builder.CreateNonNullAssumption(PtrValue);
37273726
return RValue::get(nullptr);
37283727
}
37293728
case Builtin::BI__assume:

clang/test/CodeGen/builtin-assume-dereferenceable.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// CHECK-NEXT: store ptr [[A:%.*]], ptr [[A_ADDR]], align 8
88
// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[A_ADDR]], align 8
99
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "dereferenceable"(ptr [[TMP0]], i64 10) ]
10-
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "nonnull"(ptr [[TMP0]]) ]
1110
// CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[A_ADDR]], align 8
1211
// CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[TMP1]], i64 0
1312
// CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
@@ -24,7 +23,6 @@ int test1(int *a) {
2423
// CHECK-NEXT: store ptr [[A:%.*]], ptr [[A_ADDR]], align 8
2524
// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[A_ADDR]], align 8
2625
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "dereferenceable"(ptr [[TMP0]], i64 32) ]
27-
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "nonnull"(ptr [[TMP0]]) ]
2826
// CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[A_ADDR]], align 8
2927
// CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[TMP1]], i64 0
3028
// CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[ARRAYIDX]], align 4

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,10 +2687,6 @@ class IRBuilderBase {
26872687
/// Create an assume intrinsic call that represents an dereferencable
26882688
/// assumption on the provided pointer.
26892689
CallInst *CreateDereferenceableAssumption(Value *PtrValue, Value *SizeValue);
2690-
2691-
/// Create an assume intrinsic call that represents a nonnull assumption
2692-
/// on the provided pointer.
2693-
CallInst *CreateNonNullAssumption(Value *PtrValue);
26942690
};
26952691

26962692
/// This provides a uniform API for creating instructions and inserting

0 commit comments

Comments
 (0)