Index: lib/Transforms/InstCombine/InstCombineCalls.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineCalls.cpp +++ lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -1367,7 +1367,7 @@ } // isKnownNonNull -> nonnull attribute - if (isKnownNonNull(DerivedPtr)) + if (isKnownNonNullAt(DerivedPtr, II, DT, TLI)) II->addAttribute(AttributeSet::ReturnIndex, Attribute::NonNull); // isDereferenceablePointer -> deref attribute Index: test/Transforms/InstCombine/gc.relocate.ll =================================================================== --- test/Transforms/InstCombine/gc.relocate.ll +++ test/Transforms/InstCombine/gc.relocate.ll @@ -19,3 +19,30 @@ %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %tok, i32 7, i32 7) ret i32 addrspace(1)* %relocate } + +define i32 addrspace(1)* @explicit_nonnull(i32 addrspace(1)* nonnull %dparam) gc "statepoint-example" { +; Checks that a nonnull pointer +; CHECK-LABEL: @explicit_nonnull +; CHECK: call nonnull +entry: + %load = load i32, i32 addrspace(1)* %dparam + %tok = tail call i32 (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0, i32 addrspace(1)* %dparam) + %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %tok, i32 7, i32 7) + ret i32 addrspace(1)* %relocate +} + +define i32 addrspace(1)* @implicit_nonnull(i32 addrspace(1)* %dparam) gc "statepoint-example" { +; Checks that a nonnull pointer +; CHECK-LABEL: @implicit_nonnull +; CHECK: call nonnull +entry: + %cond = icmp eq i32 addrspace(1)* %dparam, null + br i1 %cond, label %no_gc, label %gc +gc: + %load = load i32, i32 addrspace(1)* %dparam + %tok = tail call i32 (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0, i32 addrspace(1)* %dparam) + %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %tok, i32 7, i32 7) + ret i32 addrspace(1)* %relocate +no_gc: + ret i32 addrspace(1)* %dparam +} \ No newline at end of file