Summary: This patch replaces isKnownNonNull() with isKnownNonNullAt() when checking nullness of passing arguments at callsite. In this way it can handle cases where the argument does not have nonnull attribute but has a dominating null check from the CFG.
Reviewers: reames
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D12779
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247356
91177308-0d34-0410-b5e6-
96231b3b80d8
unsigned ArgNo = 0;
for (Value *V : CS.args()) {
if (!CS.paramHasAttr(ArgNo+1, Attribute::NonNull) &&
- isKnownNonNull(V)) {
+ isKnownNonNullAt(V, CS.getInstruction(), DT, TLI)) {
AttributeSet AS = CS.getAttributes();
AS = AS.addAttribute(CS.getInstruction()->getContext(), ArgNo+1,
Attribute::NonNull);
--- /dev/null
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; InstCombine should mark null-checked argument as nonnull at callsite
+declare void @dummy(i32*)
+
+define void @test(i32* %a) {
+; CHECK-LABEL: @test
+; CHECK: call void @dummy(i32* nonnull %a)
+entry:
+ %cond = icmp eq i32* %a, null
+ br i1 %cond, label %is_null, label %not_null
+not_null:
+ call void @dummy(i32* %a)
+ ret void
+is_null:
+ unreachable
+}