[PATCH] D41782: [CallSiteSplitting]use constrained argument from single predecessors
Jun Bum Lim via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 5 11:46:23 PST 2018
junbuml created this revision.
junbuml added reviewers: fhahn, davide, davidxl.
Herald added a subscriber: mcrosier.
If a call-site has a single predecessor, we can simply use more constrained
arguments if its argument is predicated from the single predecessor.
https://reviews.llvm.org/D41782
Files:
lib/Transforms/Scalar/CallSiteSplitting.cpp
test/Transforms/CallSiteSplitting/callsite-no-or-structure.ll
Index: test/Transforms/CallSiteSplitting/callsite-no-or-structure.ll
===================================================================
--- test/Transforms/CallSiteSplitting/callsite-no-or-structure.ll
+++ test/Transforms/CallSiteSplitting/callsite-no-or-structure.ll
@@ -134,6 +134,51 @@
ret i32 %v
}
+; CHECK-LABEL: @test_single_pred
+; CHECK-LABEL: Tail:
+; CHECK: %[[CALL:.*]] = call i32 @callee(i32* nonnull %a, i32 %v, i32 %p)
+; CHECK: ret i32 %[[CALL]]
+define i32 @test_single_pred(i1 %c, i32* %a, i32 %v, i32 %p) {
+Header:
+ br i1 %c, label %TBB, label %End
+
+TBB:
+ %cmp = icmp ne i32* %a, null
+ br i1 %cmp, 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_single_pred_pred
+; CHECK-LABEL: Tail:
+; CHECK: %[[CALL:.*]] = call i32 @callee(i32* nonnull %a, i32 1, i32 %p)
+; CHECK: ret i32 %[[CALL]]
+define i32 @test_single_pred_pred(i1 %c, i32* %a, i32 %v, i32 %p) {
+Header:
+ br i1 %c, label %TBB, label %End
+
+TBB:
+ %cmp = icmp ne i32* %a, null
+ br i1 %cmp, label %TBB2, label %End
+
+TBB2:
+ %cmp2 = icmp eq i32 %v, 1
+ 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
+}
+
+
define i32 @callee(i32* %a, i32 %v, i32 %p) {
ret i32 10
}
Index: lib/Transforms/Scalar/CallSiteSplitting.cpp
===================================================================
--- lib/Transforms/Scalar/CallSiteSplitting.cpp
+++ lib/Transforms/Scalar/CallSiteSplitting.cpp
@@ -348,9 +348,30 @@
return true;
}
+static bool tryToUseConstrainedArgument(CallSite CS, BasicBlock *SinglePred) {
+ SmallVector<std::pair<ICmpInst *, unsigned>, 2> Cmps;
+ recordConditions(CS, SinglePred, Cmps);
+ if (Instruction *NewCI = addConditions(CS, Cmps)) {
+ Instruction *Instr = CS.getInstruction();
+ NewCI->insertBefore(Instr);
+ Instr->replaceAllUsesWith(NewCI);
+ Instr->eraseFromParent();
+ return true;
+ }
+ return false;
+}
+
static bool tryToSplitCallSite(CallSite CS) {
- if (!CS.arg_size() || !canSplitCallSite(CS))
+ if (!CS.arg_size())
return false;
+
+ if (BasicBlock *SinglePred =
+ CS.getInstruction()->getParent()->getSinglePredecessor())
+ return tryToUseConstrainedArgument(CS, SinglePred);
+
+ if (!canSplitCallSite(CS))
+ return false;
+
return tryToSplitOnPredicatedArgument(CS) ||
tryToSplitOnPHIPredicatedArgument(CS);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41782.128774.patch
Type: text/x-patch
Size: 2493 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180105/4f676db6/attachment.bin>
More information about the llvm-commits
mailing list