diff options
author | Manman Ren <mren@apple.com> | 2012-09-20 22:37:36 +0000 |
---|---|---|
committer | Manman Ren <mren@apple.com> | 2012-09-20 22:37:36 +0000 |
commit | 554da1a222eaeea71636700ca2b7dd931e81ade6 (patch) | |
tree | 867b1c2a0de8a793ea3ce06e9009a95c85e3423b /test/Transforms/SimplifyCFG/sink-common-code.ll | |
parent | 2dad6b501b5148faef16b85cfea59d7462bad0fd (diff) | |
download | external_llvm-554da1a222eaeea71636700ca2b7dd931e81ade6.zip external_llvm-554da1a222eaeea71636700ca2b7dd931e81ade6.tar.gz external_llvm-554da1a222eaeea71636700ca2b7dd931e81ade6.tar.bz2 |
SimplifyCFG: sink common codes from IF, ELSE blocks down to END block.
We already have HoistThenElseCodeToIf, this patch implements
SinkThenElseCodeToEnd. When END block has only two predecessors and each
predecessor terminates with unconditional branches, we compare instructions in
IF and ELSE blocks backwards and check whether we can sink the common
instructions down.
rdar://12191395
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164325 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms/SimplifyCFG/sink-common-code.ll')
-rw-r--r-- | test/Transforms/SimplifyCFG/sink-common-code.ll | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/Transforms/SimplifyCFG/sink-common-code.ll b/test/Transforms/SimplifyCFG/sink-common-code.ll new file mode 100644 index 0000000..28d7279 --- /dev/null +++ b/test/Transforms/SimplifyCFG/sink-common-code.ll @@ -0,0 +1,53 @@ +; RUN: opt < %s -simplifycfg -S | FileCheck %s + +define zeroext i1 @test1(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) { +entry: + br i1 %flag, label %if.then, label %if.else + +; CHECK: test1 +; CHECK: add +; CHECK: select +; CHECK: icmp +; CHECK-NOT: br +if.then: + %cmp = icmp uge i32 %blksA, %nblks + %frombool1 = zext i1 %cmp to i8 + br label %if.end + +if.else: + %add = add i32 %nblks, %blksB + %cmp2 = icmp ule i32 %add, %blksA + %frombool3 = zext i1 %cmp2 to i8 + br label %if.end + +if.end: + %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ] + %tobool4 = icmp ne i8 %obeys.0, 0 + ret i1 %tobool4 +} + +define zeroext i1 @test2(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) { +entry: + br i1 %flag, label %if.then, label %if.else + +; CHECK: test2 +; CHECK: add +; CHECK: select +; CHECK: icmp +; CHECK-NOT: br +if.then: + %cmp = icmp uge i32 %blksA, %nblks + %frombool1 = zext i1 %cmp to i8 + br label %if.end + +if.else: + %add = add i32 %nblks, %blksB + %cmp2 = icmp uge i32 %blksA, %add + %frombool3 = zext i1 %cmp2 to i8 + br label %if.end + +if.end: + %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ] + %tobool4 = icmp ne i8 %obeys.0, 0 + ret i1 %tobool4 +} |