Index: lib/Transforms/Scalar/CallSiteSplitting.cpp =================================================================== --- lib/Transforms/Scalar/CallSiteSplitting.cpp +++ lib/Transforms/Scalar/CallSiteSplitting.cpp @@ -321,20 +321,9 @@ splitCallSite(CS, Preds[0], Preds[1], nullptr, nullptr); return true; } -// Check if one of the predecessors is a single predecessors of the other. -// This is a requirement for control flow modeling an OR. HeaderBB points to -// the single predecessor and OrBB points to other node. HeaderBB potentially -// contains the first compare of the OR and OrBB the second. -static bool isOrHeader(BasicBlock *HeaderBB, BasicBlock *OrBB) { - return OrBB->getSinglePredecessor() == HeaderBB && - HeaderBB->getTerminator()->getNumSuccessors() == 2; -} static bool tryToSplitOnOrPredicatedArgument(CallSite CS) { auto Preds = getTwoPredecessors(CS.getInstruction()->getParent()); - if (!isOrHeader(Preds[0], Preds[1]) && !isOrHeader(Preds[1], Preds[0])) - return false; - SmallVector, 2> C1, C2; recordConditions(CS, Preds[0], C1); recordConditions(CS, Preds[1], C2); 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 @@ -166,6 +166,99 @@ ret i32 %v } +;CHECK-LABEL: @test_eq_eq_eq_untaken +;CHECK-LABEL: Tail.predBB1.split: +;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* nonnull %a, i32 %v, i32 %p) +;CHECK-LABEL: Tail.predBB2.split: +;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* null, i32 1, i32 99) +;CHECK-LABEL: Tail +;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Tail.predBB1.split ], [ %[[CALL2]], %Tail.predBB2.split ] +;CHECK: ret i32 %[[MERGED]] +define i32 @test_eq_eq_eq_untaken(i32* %a, i32 %v, i32 %p) { +Header: + %tobool1 = icmp eq i32* %a, null + br i1 %tobool1, label %TBB1, label %Tail + +TBB1: + %cmp1 = icmp eq i32 %v, 1 + br i1 %cmp1, label %TBB2, label %End + +TBB2: + %cmp2 = icmp eq i32 %p, 99 + br i1 %cmp2, label %Tail, label %End + +Tail: + %r = call i32 @callee(i32* %a, i32 %v, i32 %p) + ret i32 %r + +End: + ret i32 %v +} + +;CHECK-LABEL: @test_eq_ne_eq_untaken +;CHECK-LABEL: Tail.predBB1.split: +;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* nonnull %a, i32 %v, i32 %p) +;CHECK-LABEL: Tail.predBB2.split: +;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* null, i32 %v, i32 99) +;CHECK-LABEL: Tail +;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Tail.predBB1.split ], [ %[[CALL2]], %Tail.predBB2.split ] +;CHECK: ret i32 %[[MERGED]] +define i32 @test_eq_ne_eq_untaken(i32* %a, i32 %v, i32 %p) { +Header: + %tobool1 = icmp eq i32* %a, null + br i1 %tobool1, label %TBB1, label %Tail + +TBB1: + %cmp1 = icmp ne i32 %v, 1 + br i1 %cmp1, label %TBB2, label %End + +TBB2: + %cmp2 = icmp eq i32 %p, 99 + br i1 %cmp2, label %Tail, label %End + +Tail: + %r = call i32 @callee(i32* %a, i32 %v, i32 %p) + ret i32 %r + +End: + ret i32 %v +} + +;CHECK-LABEL: @test_eq_eq_eq_eq_untaken +;CHECK-LABEL: Tail.predBB1.split: +;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* nonnull %a, i32 %v, i32 10) +;CHECK-LABEL: Tail.predBB2.split: +; NOTE: CallSiteSplitting cannot infer that %a is null here, as it currently +; only supports recording conditions along a single predecessor path. +;CHECK: %[[CALL2:.*]] = call i32 @callee(i32* %a, i32 1, i32 99) +;CHECK-LABEL: Tail +;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Tail.predBB1.split ], [ %[[CALL2]], %Tail.predBB2.split ] +;CHECK: ret i32 %[[MERGED]] +define i32 @test_eq_eq_eq_eq_untaken(i32* %a, i32 %v, i32 %p) { +Header: + %tobool1 = icmp eq i32* %a, null + br i1 %tobool1, label %TBB1, label %Header2 + +Header2: + %tobool2 = icmp eq i32 %p, 10 + br i1 %tobool2, label %Tail, label %TBB1 + +TBB1: + %cmp1 = icmp eq i32 %v, 1 + br i1 %cmp1, label %TBB2, label %End + +TBB2: + %cmp2 = icmp eq i32 %p, 99 + br i1 %cmp2, label %Tail, label %End + +Tail: + %r = call i32 @callee(i32* %a, i32 %v, i32 %p) + ret i32 %r + +End: + ret i32 %v +} + ;CHECK-LABEL: @test_nonconst_const_phi ;CHECK-LABEL: Tail.predBB1.split: ;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* %a, i32 %v, i32 1) @@ -343,7 +436,7 @@ } -;CHECK-LABEL: @test_eq_eq_eq_untaken +;CHECK-LABEL: @test_header_header2_tbb ;CHECK-LABEL: Tail.predBB1.split: ;CHECK: %[[CALL1:.*]] = call i32 @callee(i32* nonnull %a, i32 %v, i32 10) ;CHECK-LABEL: Tail.predBB2.split: @@ -351,7 +444,7 @@ ;CHECK-LABEL: Tail ;CHECK: %[[MERGED:.*]] = phi i32 [ %[[CALL1]], %Tail.predBB1.split ], [ %[[CALL2]], %Tail.predBB2.split ] ;CHECK: ret i32 %[[MERGED]] -define i32 @test_eq_eq_eq_untaken(i32* %a, i32 %v, i32 %p) { +define i32 @test_header_header2_tbb(i32* %a, i32 %v, i32 %p) { Header: %tobool1 = icmp eq i32* %a, null br i1 %tobool1, label %End, label %Header2