[PATCH] D45608: [CallSiteSplit] Make sure we remove any non-nullness if the paramater turns out to be a constant, i.e. more constrained than non-null
Xin Tong via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 12 22:04:24 PDT 2018
trentxintong created this revision.
trentxintong added reviewers: junbuml, davide.
We do not need nonull attribute if we know an argument is going to be constant.
Repository:
rL LLVM
https://reviews.llvm.org/D45608
Files:
lib/Transforms/Scalar/CallSiteSplitting.cpp
test/Transforms/CallSiteSplitting/callsite-split.ll
Index: test/Transforms/CallSiteSplitting/callsite-split.ll
===================================================================
--- test/Transforms/CallSiteSplitting/callsite-split.ll
+++ test/Transforms/CallSiteSplitting/callsite-split.ll
@@ -35,6 +35,38 @@
ret void
}
+; Make sure we remove the non-nullness on constant paramater.
+;
+;CHECK-LABEL: @caller2
+;CHECK-LABEL: Top1.split:
+;CHECK: call void @callee(%struct.bitmap* inttoptr (i64 4643 to %struct.bitmap*), %struct.bitmap* inttoptr (i64 4643 to %struct.bitmap*), %struct.bitmap* %b_elt, i1 false)
+
+define void @caller2(i1 %c, %struct.bitmap* %a_elt, %struct.bitmap* %b_elt) {
+entry:
+ br label %Top0
+
+Top0:
+ %tobool1 = icmp eq %struct.bitmap* %a_elt, inttoptr (i64 4643 to %struct.bitmap*)
+ br i1 %tobool1, label %Top1, label %NextCond
+
+Top1:
+ %tobool2 = icmp ne %struct.bitmap* %a_elt, null
+ br i1 %tobool2, label %CallSiteBB, label %NextCond
+
+NextCond:
+ %cmp = icmp ne %struct.bitmap* %b_elt, null
+ br i1 %cmp, label %CallSiteBB, label %End
+
+CallSiteBB:
+ %p = phi i1 [0, %Top1], [%c, %NextCond]
+ call void @callee(%struct.bitmap* %a_elt, %struct.bitmap* %a_elt, %struct.bitmap* %b_elt, i1 %p)
+ br label %End
+
+End:
+ ret void
+}
+
+
define void @callee(%struct.bitmap* %dst_elt, %struct.bitmap* %a_elt, %struct.bitmap* %b_elt, i1 %c) {
entry:
%tobool = icmp ne %struct.bitmap* %a_elt, null
@@ -68,15 +100,15 @@
declare void @dummy1(%struct.bitmap*, %struct.bitmap*, %struct.bitmap*, %struct.bitmap*, %struct.bitmap*, %struct.bitmap*)
-;CHECK-LABEL: @caller2
+;CHECK-LABEL: @caller3
;CHECK-LABEL: Top.split:
;CHECK: call void @dummy4()
;CHECK-LABEL: NextCond.split:
;CHECK: call void @dummy3()
;CheCK-LABEL: CallSiteBB:
;CHECK: %phi.call = phi i1 [ true, %NextCond.split ], [ false, %Top.split ]
;CHECK: call void @foo(i1 %phi.call)
-define void @caller2(i1 %c, %struct.bitmap* %a_elt, %struct.bitmap* %b_elt, %struct.bitmap* %c_elt) {
+define void @caller3(i1 %c, %struct.bitmap* %a_elt, %struct.bitmap* %b_elt, %struct.bitmap* %c_elt) {
entry:
br label %Top
Index: lib/Transforms/Scalar/CallSiteSplitting.cpp
===================================================================
--- lib/Transforms/Scalar/CallSiteSplitting.cpp
+++ lib/Transforms/Scalar/CallSiteSplitting.cpp
@@ -97,8 +97,12 @@
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;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45608.142330.patch
Type: text/x-patch
Size: 2741 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180413/be95a3db/attachment.bin>
More information about the llvm-commits
mailing list