summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/InstCombine/select_arithmetic.ll
diff options
context:
space:
mode:
authorQuentin Colombet <qcolombet@apple.com>2017-09-20 17:32:16 +0000
committerQuentin Colombet <qcolombet@apple.com>2017-09-20 17:32:16 +0000
commitaa103b3d86c0bd9d1b4452244173990457af5a4e (patch)
treee757b8f0c038b9f2ef44896ab06283740aa5ac1a /llvm/test/Transforms/InstCombine/select_arithmetic.ll
parentd0320d528952991138fcc6f30ace0d8cada6d97b (diff)
downloadbcm5719-llvm-aa103b3d86c0bd9d1b4452244173990457af5a4e.tar.gz
bcm5719-llvm-aa103b3d86c0bd9d1b4452244173990457af5a4e.zip
[InstCombine] Add select simplifications
In these cases, two selects have constant selectable operands for both the true and false components and have the same conditional expression. We then create two arithmetic operations of the same type and feed a final select operation using the result of the true arithmetic for the true operand and the result of the false arithmetic for the false operand and reuse the original conditionl expression. The arithmetic operations are naturally folded as a consequence, leaving only the newly formed select to replace the old arithmetic operation. Patch by: Michael Berg <michael_c_berg@apple.com> Differential Revision: https://reviews.llvm.org/D37019 llvm-svn: 313774
Diffstat (limited to 'llvm/test/Transforms/InstCombine/select_arithmetic.ll')
-rw-r--r--llvm/test/Transforms/InstCombine/select_arithmetic.ll40
1 files changed, 40 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/select_arithmetic.ll b/llvm/test/Transforms/InstCombine/select_arithmetic.ll
new file mode 100644
index 00000000000..d33bbdd1d43
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/select_arithmetic.ll
@@ -0,0 +1,40 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+
+; Tests folding constants from two similar selects that feed a add
+define float @test1(i1 zeroext %arg) #0 {
+ %tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+00
+ %tmp1 = select i1 %arg, float 1.000000e+00, float 9.000000e+00
+ %tmp2 = fadd float %tmp, %tmp1
+ ret float %tmp2
+; CHECK-LABEL: @test1(
+; CHECK: %tmp2 = select i1 %arg, float 6.000000e+00, float 1.500000e+01
+; CHECK-NOT: fadd
+; CHECK: ret float %tmp2
+}
+
+; Tests folding constants from two similar selects that feed a sub
+define float @test2(i1 zeroext %arg) #0 {
+ %tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+00
+ %tmp1 = select i1 %arg, float 1.000000e+00, float 9.000000e+00
+ %tmp2 = fsub float %tmp, %tmp1
+ ret float %tmp2
+; CHECK-LABEL: @test2(
+; CHECK: %tmp2 = select i1 %arg, float 4.000000e+00, float -3.000000e+00
+; CHECK-NOT: fsub
+; CHECK: ret float %tmp2
+}
+
+; Tests folding constants from two similar selects that feed a mul
+define float @test3(i1 zeroext %arg) #0 {
+ %tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+00
+ %tmp1 = select i1 %arg, float 1.000000e+00, float 9.000000e+00
+ %tmp2 = fmul float %tmp, %tmp1
+ ret float %tmp2
+; CHECK-LABEL: @test3(
+; CHECK: %tmp2 = select i1 %arg, float 5.000000e+00, float 5.400000e+01
+; CHECK-NOT: fmul
+; CHECK: ret float %tmp2
+}
+
OpenPOWER on IntegriCloud