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-or-phi.ll =================================================================== --- test/Transforms/CallSiteSplitting/callsite-split-or-phi.ll +++ test/Transforms/CallSiteSplitting/callsite-split-or-phi.ll @@ -532,3 +532,64 @@ declare void @dummy(i32*, i32) declare void @dummy2(i32, i32) +declare void @dummy3(i32*, i32*, i32*, i32*, i32*, i32*) +declare void @dummy4(i32*) + +define void @callee2(i32* %dst_elt, i32* %a_elt, i32* %b_elt, i1 %c) { +entry: + %tobool = icmp ne i32* %a_elt, null + %tobool1 = icmp ne i32* %b_elt, null + %or.cond = and i1 %tobool, %tobool1 + br i1 %or.cond, label %Cond, label %Big + +Cond: + %cmp = icmp eq i32* %dst_elt, %a_elt + br i1 %cmp, label %Small, label %Big + +Small: + call void @dummy4(i32* %a_elt) + br label %End + +Big: + call void @dummy3(i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt) + call void @dummy3(i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt) + call void @dummy3(i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt) + call void @dummy3(i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt) + call void @dummy3(i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt) + call void @dummy3(i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt) + call void @dummy3(i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt, i32* %a_elt) + br label %End + +End: + ret void +} + +; Make sure we remove the non-nullness on constant paramater. +; +;CHECK-LABEL: @caller2 +;CHECK-LABEL: Top1.split: +;CHECK: call void @callee2(i32* inttoptr (i64 4643 to i32*), i32* inttoptr (i64 4643 to i32*), i32* %b_elt, i1 false) +define void @caller2(i1 %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: + %p = phi i1 [0, %Top1], [%c, %NextCond] + call void @callee2(i32* %a_elt, i32* %a_elt, i32* %b_elt, i1 %p) + br label %End + +End: + ret void +}