Skip to content

Commit b2e443c

Browse files
committed
!fixup undo nonnull assumption, clarify docs
1 parent 6604a44 commit b2e443c

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
@@ -2869,7 +2869,7 @@ Query for this feature with ``__has_builtin(__builtin_assume_separate_storage)``
28692869
``__builtin_assume_dereferenceable``
28702870
-------------------------------------
28712871
2872-
``__builtin_assume_derefernceable`` is used to provide the optimizer with the
2872+
``__builtin_assume_dereferenceable`` is used to provide the optimizer with the
28732873
knowledge that the pointer argument P is dereferenceable up to the specified
28742874
number of bytes.
28752875
@@ -2884,20 +2884,26 @@ number of bytes.
28842884
.. code-block:: c++
28852885
28862886
int foo(int *x, int y) {
2887-
__builtin_assume_dereferenceable(x, 4);
2887+
__builtin_assume_dereferenceable(x, sizeof(int));
28882888
int z = 0;
28892889
if (y == 1) {
2890-
// The optimizer may execute the load of x unconditionally.
2890+
// The optimizer may execute the load of x unconditionally due to
2891+
// __builtin_assume_dereferenceable guaranteeing sizeof(int) bytes can
2892+
// be loaded speculatively without trapping.
28912893
z = *x;
2892-
}
2894+
}
28932895
return z;
28942896
}
28952897
28962898
**Description**:
28972899
28982900
The arguments to this function provide a start pointer ``P`` and a size ``S``.
2899-
``P`` must be non-null and ``S`` at least 1. The optimizer may assume that
2900-
``S`` bytes are dereferenceable starting at ``P``.
2901+
``S`` must be at least 1 and a constant. The optimizer may assume that ``S``
2902+
bytes are dereferenceable starting at ``P``. Note that this does not necessarily
2903+
imply that ``P`` is non-null as ``nullptr`` can be dereferenced in some cases.
2904+
The assumption also does not imply that ``P`` is not dereferenceable past ``S``
2905+
bytes.
2906+
29012907
29022908
Query for this feature with ``__has_builtin(__builtin_assume_dereferenceable)``.
29032909

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3848,7 +3848,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
38483848
SizeValue =
38493849
Builder.CreateIntCast(SizeValue, IntPtrTy, false, "casted.size");
38503850
Builder.CreateDereferenceableAssumption(PtrValue, SizeValue);
3851-
Builder.CreateNonNullAssumption(PtrValue);
38523851
return RValue::get(nullptr);
38533852
}
38543853
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
@@ -2688,10 +2688,6 @@ class IRBuilderBase {
26882688
/// Create an assume intrinsic call that represents an dereferencable
26892689
/// assumption on the provided pointer.
26902690
CallInst *CreateDereferenceableAssumption(Value *PtrValue, Value *SizeValue);
2691-
2692-
/// Create an assume intrinsic call that represents a nonnull assumption
2693-
/// on the provided pointer.
2694-
CallInst *CreateNonNullAssumption(Value *PtrValue);
26952691
};
26962692

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

0 commit comments

Comments
 (0)