<div dir="ltr">Hi Philip,<div><br></div><div>This change has caused some Clang test failures, can you take a look? It's probably just some gold output that needs updating.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 15, 2015 at 5:43 PM, Philip Reames <span dir="ltr"><<a href="mailto:listmail@philipreames.com" target="_blank">listmail@philipreames.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: reames<br>
Date: Mon Jun 15 19:43:54 2015<br>
New Revision: 239795<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D239795-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=mLs8_vEWn-hOfVkTn3YX_27rRrxiVEs0CJA5y6c4bG8&s=Mb-QZiBcRtpLUqpan--O81RHpyXiWywr41gIGhbNE5E&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=239795&view=rev</a><br>
Log:<br>
[InstCombine] Propagate non-null facts to call parameters<br>
<br>
If a parameter to a function is known non-null, use the existing parameter attributes to record that fact at the call site. This has no optimization benefit by itself - that I know of - but is an enabling change for <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D9129&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=mLs8_vEWn-hOfVkTn3YX_27rRrxiVEs0CJA5y6c4bG8&s=Q-SyezrCAgh3oL7j5LYWxmnk9G0sybPtuxVHBnzyaHQ&e=" rel="noreferrer" target="_blank">http://reviews.llvm.org/D9129</a>.<br>
<br>
Differential Revision: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D9132&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=mLs8_vEWn-hOfVkTn3YX_27rRrxiVEs0CJA5y6c4bG8&s=ILCBzlh1SBgMjDRr26-oslaCMupOL3qhlpvt004oNgk&e=" rel="noreferrer" target="_blank">http://reviews.llvm.org/D9132</a><br>
<br>
<br>
Added:<br>
    llvm/trunk/test/Transforms/InstCombine/nonnull-param.ll<br>
Modified:<br>
    llvm/trunk/include/llvm/IR/CallSite.h<br>
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp<br>
    llvm/trunk/test/CodeGen/NVPTX/intrin-nocapture.ll<br>
    llvm/trunk/test/Transforms/Inline/byval-tail-call.ll<br>
    llvm/trunk/test/Transforms/InstCombine/select.ll<br>
<br>
Modified: llvm/trunk/include/llvm/IR/CallSite.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_include_llvm_IR_CallSite.h-3Frev-3D239795-26r1-3D239794-26r2-3D239795-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=mLs8_vEWn-hOfVkTn3YX_27rRrxiVEs0CJA5y6c4bG8&s=ubMRmtlcBMcm587iS2KPr0eDTQU39aw86m1nULT9xjk&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/CallSite.h?rev=239795&r1=239794&r2=239795&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/IR/CallSite.h (original)<br>
+++ llvm/trunk/include/llvm/IR/CallSite.h Mon Jun 15 19:43:54 2015<br>
@@ -27,6 +27,7 @@<br>
 #define LLVM_IR_CALLSITE_H<br>
<br>
 #include "llvm/ADT/PointerIntPair.h"<br>
+#include "llvm/ADT/iterator_range.h"<br>
 #include "llvm/IR/Attributes.h"<br>
 #include "llvm/IR/CallingConv.h"<br>
 #include "llvm/IR/Instructions.h"<br>
@@ -150,6 +151,9 @@ public:<br>
   }<br>
<br>
   IterTy arg_end() const { return (*this)->op_end() - getArgumentEndOffset(); }<br>
+  iterator_range<IterTy> args() const {<br>
+    return iterator_range<IterTy>(arg_begin(), arg_end());<br>
+  }<br>
   bool arg_empty() const { return arg_end() == arg_begin(); }<br>
   unsigned arg_size() const { return unsigned(arg_end() - arg_begin()); }<br>
<br>
<br>
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_Transforms_InstCombine_InstCombineCalls.cpp-3Frev-3D239795-26r1-3D239794-26r2-3D239795-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=mLs8_vEWn-hOfVkTn3YX_27rRrxiVEs0CJA5y6c4bG8&s=2FxtPJZkVvmLlf9Dgr2OmFnsU2Uy6OlpO8T9AushwzQ&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=239795&r1=239794&r2=239795&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Mon Jun 15 19:43:54 2015<br>
@@ -1391,6 +1391,24 @@ static IntrinsicInst *FindInitTrampoline<br>
 // visitCallSite - Improvements for call and invoke instructions.<br>
 //<br>
 Instruction *InstCombiner::visitCallSite(CallSite CS) {<br>
+<br>
+  // Mark any parameters that are known to be non-null with the nonnull<br>
+  // attribute.  This is helpful for inlining calls to functions with null<br>
+  // checks on their arguments.<br>
+  unsigned ArgNo = 0;<br>
+  for (Value *V : CS.args()) {<br>
+    if (!CS.paramHasAttr(ArgNo+1, Attribute::NonNull) &&<br>
+        isKnownNonNull(V)) {<br>
+      AttributeSet AS = CS.getAttributes();<br>
+      AS = AS.addAttribute(CS.getInstruction()->getContext(), ArgNo+1,<br>
+                           Attribute::NonNull);<br>
+      CS.setAttributes(AS);<br>
+      return CS.getInstruction();<br>
+    }<br>
+    ArgNo++;<br>
+  }<br>
+  assert(ArgNo == CS.arg_size() && "sanity check");<br>
+<br>
   if (isAllocLikeFn(CS.getInstruction(), TLI))<br>
     return visitAllocSite(*CS.getInstruction());<br>
<br>
<br>
Modified: llvm/trunk/test/CodeGen/NVPTX/intrin-nocapture.ll<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_CodeGen_NVPTX_intrin-2Dnocapture.ll-3Frev-3D239795-26r1-3D239794-26r2-3D239795-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=mLs8_vEWn-hOfVkTn3YX_27rRrxiVEs0CJA5y6c4bG8&s=DvefnlaKXpoZf9JAwlaTCl6dkeRK0qD2eOBlep5bBls&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/NVPTX/intrin-nocapture.ll?rev=239795&r1=239794&r2=239795&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/NVPTX/intrin-nocapture.ll (original)<br>
+++ llvm/trunk/test/CodeGen/NVPTX/intrin-nocapture.ll Mon Jun 15 19:43:54 2015<br>
@@ -11,7 +11,7 @@ declare i32 addrspace(1)* @llvm.nvvm.ptr<br>
 ; CHECK: @bar<br>
 define void @bar() {<br>
   %t1 = alloca i32<br>
-; CHECK: call i32 addrspace(1)* @llvm.nvvm.ptr.gen.to.global.p1i32.p0i32(i32* %t1)<br>
+; CHECK: call i32 addrspace(1)* @llvm.nvvm.ptr.gen.to.global.p1i32.p0i32(i32* nonnull %t1)<br>
 ; CHECK-NEXT: store i32 10, i32* %t1<br>
   %t2 = call i32 addrspace(1)* @llvm.nvvm.ptr.gen.to.global.p1i32.p0i32(i32* %t1)<br>
   store i32 10, i32* %t1<br>
<br>
Modified: llvm/trunk/test/Transforms/Inline/byval-tail-call.ll<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_Transforms_Inline_byval-2Dtail-2Dcall.ll-3Frev-3D239795-26r1-3D239794-26r2-3D239795-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=mLs8_vEWn-hOfVkTn3YX_27rRrxiVEs0CJA5y6c4bG8&s=Ss5NeaLkhTRTiYUhUrmmgfDQP2x2PjxnjeYgjTEElLQ&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/byval-tail-call.ll?rev=239795&r1=239794&r2=239795&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/Transforms/Inline/byval-tail-call.ll (original)<br>
+++ llvm/trunk/test/Transforms/Inline/byval-tail-call.ll Mon Jun 15 19:43:54 2015<br>
@@ -33,7 +33,7 @@ define void @frob(i32* %x) {<br>
 ; CHECK: %[[POS:.*]] = alloca i32<br>
 ; CHECK: %[[VAL:.*]] = load i32, i32* %x<br>
 ; CHECK: store i32 %[[VAL]], i32* %[[POS]]<br>
-; CHECK: {{^ *}}call void @ext(i32* %[[POS]]<br>
+; CHECK: {{^ *}}call void @ext(i32* nonnull %[[POS]]<br>
 ; CHECK: tail call void @ext(i32* null)<br>
 ; CHECK: ret void<br>
   tail call void @qux(i32* byval %x)<br>
<br>
Added: llvm/trunk/test/Transforms/InstCombine/nonnull-param.ll<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_Transforms_InstCombine_nonnull-2Dparam.ll-3Frev-3D239795-26view-3Dauto&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=mLs8_vEWn-hOfVkTn3YX_27rRrxiVEs0CJA5y6c4bG8&s=ajC6CrDOu0ZdoFZpfkq2Owebs8T6bV4WMRMQtg2mAmc&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/nonnull-param.ll?rev=239795&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/Transforms/InstCombine/nonnull-param.ll (added)<br>
+++ llvm/trunk/test/Transforms/InstCombine/nonnull-param.ll Mon Jun 15 19:43:54 2015<br>
@@ -0,0 +1,42 @@<br>
+; RUN: opt -S -instcombine < %s | FileCheck %s<br>
+<br>
+declare void @callee(i8* %arg)<br>
+<br>
+; Positive test - arg is known non null<br>
+define void @test(i8* nonnull %arg) {<br>
+; CHECK-LABEL: @test<br>
+; CHECK: call void @callee(i8* nonnull %arg)<br>
+  call void @callee(i8* %arg)<br>
+  ret void<br>
+}<br>
+<br>
+<br>
+; Negative test - arg is not known to be non null<br>
+define void @test2(i8* %arg) {<br>
+; CHECK-LABEL: @test2<br>
+; CHECK: call void @callee(i8* %arg)<br>
+  call void @callee(i8* %arg)<br>
+  ret void<br>
+}<br>
+<br>
+declare void @callee2(i8*, i8*, i8*)<br>
+<br>
+; Sanity check arg indexing<br>
+define void @test3(i8* %arg1, i8* nonnull %arg2, i8* %arg3) {<br>
+; CHECK-LABEL: @test3<br>
+; CHECK: call void @callee2(i8* %arg1, i8* nonnull %arg2, i8* %arg3)<br>
+  call void @callee2(i8* %arg1, i8* %arg2, i8* %arg3)<br>
+  ret void<br>
+}<br>
+<br>
+; Because of the way CallSite::paramHasAttribute looks at the callee<br>
+; directly, we will not set the attribute on the CallSite.  That's<br>
+; fine as long as all consumers use the same check.<br>
+define void @test4(i8* nonnull %arg) {<br>
+; CHECK-LABEL: @test4<br>
+; CHECK: call void @test4(i8* %arg)<br>
+  call void @test4(i8* %arg)<br>
+  ret void<br>
+}<br>
+<br>
+<br>
<br>
Modified: llvm/trunk/test/Transforms/InstCombine/select.ll<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_Transforms_InstCombine_select.ll-3Frev-3D239795-26r1-3D239794-26r2-3D239795-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=mLs8_vEWn-hOfVkTn3YX_27rRrxiVEs0CJA5y6c4bG8&s=hgiQaH1b2gN3THmi3Bp3kh9dTexkoVkUZqYv-lbt_NU&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/select.ll?rev=239795&r1=239794&r2=239795&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/Transforms/InstCombine/select.ll (original)<br>
+++ llvm/trunk/test/Transforms/InstCombine/select.ll Mon Jun 15 19:43:54 2015<br>
@@ -1265,7 +1265,7 @@ define i32 @test77(i1 %flag, i32* %x) {<br>
 ; load does.<br>
 ; CHECK-LABEL: @test77(<br>
 ; CHECK: %[[A:.*]] = alloca i32, align 1<br>
-; CHECK: call void @scribble_on_i32(i32* %[[A]])<br>
+; CHECK: call void @scribble_on_i32(i32* nonnull %[[A]])<br>
 ; CHECK: store i32 0, i32* %x<br>
 ; CHECK: %[[P:.*]] = select i1 %flag, i32* %[[A]], i32* %x<br>
 ; CHECK: load i32, i32* %[[P]]<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>