[llvm] r330641 - [CallSiteSplit] Make sure we remove nonnull if the parameter turns out to be a constant.
Xin Tong via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 23 13:09:08 PDT 2018
Author: trentxintong
Date: Mon Apr 23 13:09:08 2018
New Revision: 330641
URL: http://llvm.org/viewvc/llvm-project?rev=330641&view=rev
Log:
[CallSiteSplit] Make sure we remove nonnull if the parameter turns out to be a constant.
Summary: We do not need nonull attribute if we know an argument is going to be constant.
Reviewers: junbuml, davide, fhahn
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D45608
Modified:
llvm/trunk/lib/Transforms/Scalar/CallSiteSplitting.cpp
llvm/trunk/test/Transforms/CallSiteSplitting/callsite-split-or-phi.ll
Modified: llvm/trunk/lib/Transforms/Scalar/CallSiteSplitting.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CallSiteSplitting.cpp?rev=330641&r1=330640&r2=330641&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/CallSiteSplitting.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/CallSiteSplitting.cpp Mon Apr 23 13:09:08 2018
@@ -97,8 +97,12 @@ static void setConstantInArgument(CallSi
Constant *ConstValue) {
unsigned ArgNo = 0;
for (auto &I : CS.args()) {
- if (&*I == Op)
+ if (&*I == Op) {
+ // It is possible we have already added the non-null attribute to the
+ // parameter by using an earlier constraining condition.
+ CS.removeParamAttr(ArgNo, Attribute::NonNull);
CS.setArgument(ArgNo, ConstValue);
+ }
++ArgNo;
}
}
Modified: llvm/trunk/test/Transforms/CallSiteSplitting/callsite-split-or-phi.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/CallSiteSplitting/callsite-split-or-phi.ll?rev=330641&r1=330640&r2=330641&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/CallSiteSplitting/callsite-split-or-phi.ll (original)
+++ llvm/trunk/test/Transforms/CallSiteSplitting/callsite-split-or-phi.ll Mon Apr 23 13:09:08 2018
@@ -532,3 +532,32 @@ End:
declare void @dummy(i32*, i32)
declare void @dummy2(i32, i32)
+
+; Make sure we remove the non-nullness on constant paramater.
+;
+;CHECK-LABEL: @caller2
+;CHECK-LABEL: Top1.split:
+;CHECK: call i32 @callee(i32* inttoptr (i64 4643 to i32*)
+define void @caller2(i32 %c, i32* %a_elt, i32* %b_elt) {
+entry:
+ br label %Top0
+
+Top0:
+ %tobool1 = icmp eq i32* %a_elt, inttoptr (i64 4643 to i32*)
+ br i1 %tobool1, label %Top1, label %NextCond
+
+Top1:
+ %tobool2 = icmp ne i32* %a_elt, null
+ br i1 %tobool2, label %CallSiteBB, label %NextCond
+
+NextCond:
+ %cmp = icmp ne i32* %b_elt, null
+ br i1 %cmp, label %CallSiteBB, label %End
+
+CallSiteBB:
+ call i32 @callee(i32* %a_elt, i32 %c, i32 %c)
+ br label %End
+
+End:
+ ret void
+}
More information about the llvm-commits
mailing list