summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/JumpThreading
diff options
context:
space:
mode:
authorPablo Barrio <pablo.barrio@arm.com>2016-11-08 14:53:30 +0000
committerPablo Barrio <pablo.barrio@arm.com>2016-11-08 14:53:30 +0000
commit9f4525413887f1d7328279823ef816d4c4ff200f (patch)
tree76958fd10cb12557d5221e7397473fdf8035e3c1 /llvm/test/Transforms/JumpThreading
parent1a5411238ef5f259404e6703af745256f2c39bca (diff)
downloadbcm5719-llvm-9f4525413887f1d7328279823ef816d4c4ff200f.tar.gz
bcm5719-llvm-9f4525413887f1d7328279823ef816d4c4ff200f.zip
[JumpThreading] Unfold selects that depend on the same condition
Summary: These are good candidates for jump threading. This enables later opts (such as InstCombine) to combine instructions from the selects with instructions out of the selects. SimplifyCFG will fold the select again if unfolding wasn't worth it. Patch by James Molloy and Pablo Barrio. Reviewers: rengolin, haicheng, sebpop Subscribers: jojo, jmolloy, llvm-commits Differential Revision: https://reviews.llvm.org/D26391 llvm-svn: 286236
Diffstat (limited to 'llvm/test/Transforms/JumpThreading')
-rw-r--r--llvm/test/Transforms/JumpThreading/unfold-selects-same-cond.ll45
1 files changed, 45 insertions, 0 deletions
diff --git a/llvm/test/Transforms/JumpThreading/unfold-selects-same-cond.ll b/llvm/test/Transforms/JumpThreading/unfold-selects-same-cond.ll
new file mode 100644
index 00000000000..ef01b0d1990
--- /dev/null
+++ b/llvm/test/Transforms/JumpThreading/unfold-selects-same-cond.ll
@@ -0,0 +1,45 @@
+; RUN: opt < %s -jump-threading -instcombine -simplifycfg -S | FileCheck %s
+
+; The three selects are jump-threaded so that instcombine can optimize, and
+; simplifycfg should turn the result into a single select.
+define i32 @f(i32 %a, i32 %b) {
+; CHECK: select
+; CHECK-NOT: select
+entry:
+ %0 = and i32 %a, 1
+ %1 = and i32 %b, 1
+ %xor = xor i32 %1, %a
+ %shr32 = lshr i32 %a, 1
+ %cmp10 = icmp eq i32 %xor, 1
+ %2 = xor i32 %b, 12345
+ %b.addr.1 = select i1 %cmp10, i32 %2, i32 %b
+ %shr1633 = lshr i32 %b.addr.1, 1
+ %3 = or i32 %shr1633, 54321
+ %b.addr.2 = select i1 %cmp10, i32 %3, i32 %shr1633
+ %shr1634 = lshr i32 %b.addr.2, 2
+ %4 = or i32 %shr1634, 54320
+ %b.addr.3 = select i1 %cmp10, i32 %4, i32 %shr1634
+ ret i32 %b.addr.3
+}
+
+; Case where the condition is not only used as condition but also as the
+; true or false value in at least one of the selects.
+define i1 @g(i32 %a, i32 %b) {
+; CHECK: select
+; CHECK-NOT: select
+entry:
+ %0 = and i32 %a, 1
+ %1 = and i32 %b, 1
+ %xor = xor i32 %1, %a
+ %shr32 = lshr i32 %a, 1
+ %cmp10 = icmp eq i32 %xor, 1
+ %2 = xor i32 %b, 12345
+ %b.addr.1 = select i1 %cmp10, i32 %2, i32 %b
+ %shr1633 = lshr i32 %b.addr.1, 1
+ %3 = or i32 %shr1633, 54321
+ %b.addr.2 = select i1 %cmp10, i32 %3, i32 %shr1633
+ %shr1634 = lshr i32 %b.addr.2, 2
+ %4 = icmp eq i32 %shr1634, 54320
+ %b.addr.3 = select i1 %cmp10, i1 %4, i1 %cmp10
+ ret i1 %b.addr.3
+}
OpenPOWER on IntegriCloud