[llvm] r247356 - [InstCombineCalls] Use isKnownNonNullAt() to check nullness of passing arguments at callsite
Chen Li via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 10 16:04:49 PDT 2015
Author: chenli
Date: Thu Sep 10 18:04:49 2015
New Revision: 247356
URL: http://llvm.org/viewvc/llvm-project?rev=247356&view=rev
Log:
[InstCombineCalls] Use isKnownNonNullAt() to check nullness of passing arguments at callsite
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
Added:
llvm/trunk/test/Transforms/InstCombine/call_nonnull_arg.ll
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=247356&r1=247355&r2=247356&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Thu Sep 10 18:04:49 2015
@@ -1537,7 +1537,7 @@ Instruction *InstCombiner::visitCallSite
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);
Added: llvm/trunk/test/Transforms/InstCombine/call_nonnull_arg.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/call_nonnull_arg.ll?rev=247356&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/call_nonnull_arg.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/call_nonnull_arg.ll Thu Sep 10 18:04:49 2015
@@ -0,0 +1,17 @@
+; 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
+}
More information about the llvm-commits
mailing list