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; } } 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,7 +100,7 @@ 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: @@ -76,7 +108,7 @@ ;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