llvm.org GIT mirror llvm / 90f3f15
Introduce a 'nonnull' metadata on Load instructions. The newly introduced 'nonnull' metadata is analogous to existing 'nonnull' attributes, but applies to load instructions rather than call arguments or returns. Long term, it would be nice to combine these into a single construct. The value of the load is allowed to vary between successive loads, but null is not a valid value to be loaded by any load marked nonnull. Reviewed by: Hal Finkel Differential Revision: http://reviews.llvm.org/D5220 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220240 91177308-0d34-0410-b5e6-96231b3b80d8 Philip Reames 5 years ago
3 changed file(s) with 36 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
51565156
51575157 ::
51585158
5159 = load [volatile] * [, align ][, !nontemporal !][, !invariant.load !]
5159 = load [volatile] * [, align ][, !nontemporal !][, !invariant.load !][, !nonnull !]
51605160 = load atomic [volatile] * [singlethread] , align
51615161 ! = !{ i32 1 }
51625162
52115211 address points to memory which does not change value during program
52125212 execution. The optimizer may then move this load around, for example, by
52135213 hoisting it out of loops using loop invariant code motion.
5214
5215 The optional ``!nonnull`` metadata must reference a single
5216 metadata name ```` corresponding to a metadata node with no
5217 entries. The existence of the ``!nonnull`` metadata on the
5218 instruction tells the optimizer that the value loaded is known to
5219 never be null. This is analogous to the ''nonnull'' attribute
5220 on parameters and return values. This metadata can only be applied
5221 to loads of a pointer type.
52145222
52155223 Semantics:
52165224 """"""""""
26212621 if (const GlobalValue *GV = dyn_cast(V))
26222622 return !GV->hasExternalWeakLinkage();
26232623
2624 // A Load tagged w/nonnull metadata is never null.
2625 if (const LoadInst *LI = dyn_cast(V))
2626 return LI->getMetadata("nonnull");
2627
26242628 if (ImmutableCallSite CS = V)
26252629 if (CS.isReturnNonNull())
26262630 return true;
948948 ; CHECK: ret
949949 }
950950
951 define i1 @nonnull_load(i32** %addr) {
952 %ptr = load i32** %addr, !nonnull !{}
953 %cmp = icmp eq i32* %ptr, null
954 ret i1 %cmp
955 ; CHECK-LABEL: @nonnull_load
956 ; CHECK: ret i1 false
957 }
958
959 define i1 @nonnull_load_as_outer(i32* addrspace(1)* %addr) {
960 %ptr = load i32* addrspace(1)* %addr, !nonnull !{}
961 %cmp = icmp eq i32* %ptr, null
962 ret i1 %cmp
963 ; CHECK-LABEL: @nonnull_load_as_outer
964 ; CHECK: ret i1 false
965 }
966 define i1 @nonnull_load_as_inner(i32 addrspace(1)** %addr) {
967 %ptr = load i32 addrspace(1)** %addr, !nonnull !{}
968 %cmp = icmp eq i32 addrspace(1)* %ptr, null
969 ret i1 %cmp
970 ; CHECK-LABEL: @nonnull_load_as_inner
971 ; CHECK: ret i1 false
972 }
973
951974 ; If a bit is known to be zero for A and known to be one for B,
952975 ; then A and B cannot be equal.
953976 define i1 @icmp_eq_const(i32 %a) nounwind {