aboutsummaryrefslogtreecommitdiffstats
path: root/test/Transforms/JumpThreading/select.ll
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2013-08-07 10:29:38 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2013-08-07 10:29:38 +0000
commitc11b107f21f8f1baf1021999fc7d01b93e00922b (patch)
tree30b40715cea776c60986056d6fbf36269c6557ff /test/Transforms/JumpThreading/select.ll
parente4a4aecffb25df25736fec328d9147ee43335c2b (diff)
downloadexternal_llvm-c11b107f21f8f1baf1021999fc7d01b93e00922b.zip
external_llvm-c11b107f21f8f1baf1021999fc7d01b93e00922b.tar.gz
external_llvm-c11b107f21f8f1baf1021999fc7d01b93e00922b.tar.bz2
JumpThreading: Turn a select instruction into branching if it allows to thread one half of the select.
This is a common pattern coming out of simplifycfg generating gross code. a: ; preds = %entry %sel = select i1 %cmp1, double %add, double 0.000000e+00 br label %b b: %cond5 = phi double [ %sel, %a ], [ %sub, %entry ] %cmp6 = fcmp oeq double %cond5, 0.000000e+00 br i1 %cmp6, label %if.then, label %if.end becomes a: br i1 %cmp1, label %b, label %if.then b: %cond5 = phi double [ %sub, %entry ], [ %add, %a ] %cmp6 = fcmp oeq double %cond5, 0.000000e+00 br i1 %cmp6, label %if.then, label %if.end Skipping block b completely if possible. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187880 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms/JumpThreading/select.ll')
-rw-r--r--test/Transforms/JumpThreading/select.ll63
1 files changed, 63 insertions, 0 deletions
diff --git a/test/Transforms/JumpThreading/select.ll b/test/Transforms/JumpThreading/select.ll
index 18f5e23..201e604 100644
--- a/test/Transforms/JumpThreading/select.ll
+++ b/test/Transforms/JumpThreading/select.ll
@@ -157,3 +157,66 @@ L3:
L4:
ret void
}
+
+define void @unfold1(double %x, double %y) nounwind {
+entry:
+ %sub = fsub double %x, %y
+ %cmp = fcmp ogt double %sub, 1.000000e+01
+ br i1 %cmp, label %cond.end4, label %cond.false
+
+cond.false: ; preds = %entry
+ %add = fadd double %x, %y
+ %cmp1 = fcmp ogt double %add, 1.000000e+01
+ %add. = select i1 %cmp1, double %add, double 0.000000e+00
+ br label %cond.end4
+
+cond.end4: ; preds = %entry, %cond.false
+ %cond5 = phi double [ %add., %cond.false ], [ %sub, %entry ]
+ %cmp6 = fcmp oeq double %cond5, 0.000000e+00
+ br i1 %cmp6, label %if.then, label %if.end
+
+if.then: ; preds = %cond.end4
+ call void @foo()
+ br label %if.end
+
+if.end: ; preds = %if.then, %cond.end4
+ ret void
+
+; CHECK-LABEL: @unfold1
+; CHECK: br i1 %cmp, label %cond.end4, label %cond.false
+; CHECK: br i1 %cmp1, label %cond.end4, label %if.then
+; CHECK: br i1 %cmp6, label %if.then, label %if.end
+; CHECK: br label %if.end
+}
+
+
+define void @unfold2(i32 %x, i32 %y) nounwind {
+entry:
+ %sub = sub nsw i32 %x, %y
+ %cmp = icmp sgt i32 %sub, 10
+ br i1 %cmp, label %cond.end4, label %cond.false
+
+cond.false: ; preds = %entry
+ %add = add nsw i32 %x, %y
+ %cmp1 = icmp sgt i32 %add, 10
+ %add. = select i1 %cmp1, i32 0, i32 %add
+ br label %cond.end4
+
+cond.end4: ; preds = %entry, %cond.false
+ %cond5 = phi i32 [ %add., %cond.false ], [ %sub, %entry ]
+ %cmp6 = icmp eq i32 %cond5, 0
+ br i1 %cmp6, label %if.then, label %if.end
+
+if.then: ; preds = %cond.end4
+ call void @foo()
+ br label %if.end
+
+if.end: ; preds = %if.then, %cond.end4
+ ret void
+
+; CHECK-LABEL: @unfold2
+; CHECK: br i1 %cmp, label %if.end, label %cond.false
+; CHECK: br i1 %cmp1, label %if.then, label %cond.end4
+; CHECK: br i1 %cmp6, label %if.then, label %if.end
+; CHECK: br label %if.end
+}