diff options
author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2015-10-28 21:27:08 +0000 |
---|---|---|
committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2015-10-28 21:27:08 +0000 |
commit | 13e63a2f21ebaf5f0b03b13d5e3deb630f37cfa9 (patch) | |
tree | 84539eb2a2b90654d6bc1e46d0a416ffe5bea4a1 /llvm/test/Transforms/JumpThreading/implied-cond.ll | |
parent | a83b6cc17612485c0636d909f998edebae396eb3 (diff) | |
download | bcm5719-llvm-13e63a2f21ebaf5f0b03b13d5e3deb630f37cfa9.tar.gz bcm5719-llvm-13e63a2f21ebaf5f0b03b13d5e3deb630f37cfa9.zip |
[JumpThreading] Use dominating conditions to prove implications
Summary:
If P branches to Q conditional on C and Q branches to R conditional on
C' and C => C' then the branch conditional on C' can be folded to an
unconditional branch.
Reviewers: reames
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D13972
llvm-svn: 251557
Diffstat (limited to 'llvm/test/Transforms/JumpThreading/implied-cond.ll')
-rw-r--r-- | llvm/test/Transforms/JumpThreading/implied-cond.ll | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/llvm/test/Transforms/JumpThreading/implied-cond.ll b/llvm/test/Transforms/JumpThreading/implied-cond.ll new file mode 100644 index 00000000000..3d1717e9126 --- /dev/null +++ b/llvm/test/Transforms/JumpThreading/implied-cond.ll @@ -0,0 +1,98 @@ +; RUN: opt -jump-threading -S < %s | FileCheck %s + +declare void @side_effect(i32) + +define void @test0(i32 %i, i32 %len) { +; CHECK-LABEL: @test0( + entry: + call void @side_effect(i32 0) + %i.inc = add nuw i32 %i, 1 + %c0 = icmp ult i32 %i.inc, %len + br i1 %c0, label %left, label %right + + left: +; CHECK: entry: +; CHECK: br i1 %c0, label %left0, label %right + +; CHECK: left0: +; CHECK: call void @side_effect +; CHECK-NOT: br i1 %c1 +; CHECK: call void @side_effect + call void @side_effect(i32 0) + %c1 = icmp ult i32 %i, %len + br i1 %c1, label %left0, label %right + + left0: + call void @side_effect(i32 0) + ret void + + right: + %t = phi i32 [ 1, %left ], [ 2, %entry ] + call void @side_effect(i32 %t) + ret void +} + +define void @test1(i32 %i, i32 %len) { +; CHECK-LABEL: @test1( + entry: + call void @side_effect(i32 0) + %i.inc = add nsw i32 %i, 1 + %c0 = icmp slt i32 %i.inc, %len + br i1 %c0, label %left, label %right + + left: +; CHECK: entry: +; CHECK: br i1 %c0, label %left0, label %right + +; CHECK: left0: +; CHECK: call void @side_effect +; CHECK-NOT: br i1 %c1 +; CHECK: call void @side_effect + call void @side_effect(i32 0) + %c1 = icmp slt i32 %i, %len + br i1 %c1, label %left0, label %right + + left0: + call void @side_effect(i32 0) + ret void + + right: + %t = phi i32 [ 1, %left ], [ 2, %entry ] + call void @side_effect(i32 %t) + ret void +} + +define void @test2(i32 %i, i32 %len, i1* %c.ptr) { +; CHECK-LABEL: @test2( + +; CHECK: entry: +; CHECK: br i1 %c0, label %cont, label %right +; CHECK: cont: +; CHECK: br i1 %c, label %left0, label %right +; CHECK: left0: +; CHECK: call void @side_effect(i32 0) +; CHECK: call void @side_effect(i32 0) + entry: + call void @side_effect(i32 0) + %i.inc = add nsw i32 %i, 1 + %c0 = icmp slt i32 %i.inc, %len + br i1 %c0, label %cont, label %right + + cont: + %c = load i1, i1* %c.ptr + br i1 %c, label %left, label %right + + left: + call void @side_effect(i32 0) + %c1 = icmp slt i32 %i, %len + br i1 %c1, label %left0, label %right + + left0: + call void @side_effect(i32 0) + ret void + + right: + %t = phi i32 [ 1, %left ], [ 2, %entry ], [ 3, %cont ] + call void @side_effect(i32 %t) + ret void +} |