1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
6 ; Tests folding constants from two similar selects that feed a add
8 define float @test1a(i1 zeroext %arg) #0 {
9 ; CHECK-LABEL: @test1a(
10 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[ARG:%.*]], float 6.000000e+00, float 1.500000e+01
11 ; CHECK-NEXT: ret float [[TMP2]]
13 %tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+00
14 %tmp1 = select i1 %arg, float 1.000000e+00, float 9.000000e+00
15 %tmp2 = fadd float %tmp, %tmp1
19 ; Tests folding multiple expression constants from similar selects that feed a adds
21 define float @test1b(i1 zeroext %arg) #0 {
22 ; CHECK-LABEL: @test1b(
23 ; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[ARG:%.*]], float 7.250000e+00, float 2.800000e+01
24 ; CHECK-NEXT: ret float [[TMP5]]
26 %tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+00
27 %tmp1 = select i1 %arg, float 1.000000e+00, float 9.000000e+00
28 %tmp2 = select i1 %arg, float 2.500000e-01, float 4.000000e+00
29 %tmp3 = fadd float %tmp, %tmp1
30 %tmp4 = fadd float %tmp2, %tmp1
31 %tmp5 = fadd float %tmp4, %tmp3
35 ; Tests folding constants from two similar selects that feed a sub
37 define float @test2(i1 zeroext %arg) #0 {
38 ; CHECK-LABEL: @test2(
39 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[ARG:%.*]], float 4.000000e+00, float -3.000000e+00
40 ; CHECK-NEXT: ret float [[TMP2]]
42 %tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+00
43 %tmp1 = select i1 %arg, float 1.000000e+00, float 9.000000e+00
44 %tmp2 = fsub float %tmp, %tmp1
48 ; Tests folding constants from two similar selects that feed a mul
50 define float @test3(i1 zeroext %arg) #0 {
51 ; CHECK-LABEL: @test3(
52 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[ARG:%.*]], float 5.000000e+00, float 5.400000e+01
53 ; CHECK-NEXT: ret float [[TMP2]]
55 %tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+00
56 %tmp1 = select i1 %arg, float 1.000000e+00, float 9.000000e+00
57 %tmp2 = fmul float %tmp, %tmp1
61 declare void @use_float(float)
63 ; Tests folding constants if the selects have multiple uses but
64 ; we can fold away the binary op with a select.
66 define float @test4(i1 zeroext %arg) #0 {
67 ; CHECK-LABEL: @test4(
68 ; CHECK-NEXT: [[TMP:%.*]] = select i1 [[ARG:%.*]], float 5.000000e+00, float 6.000000e+00
69 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[ARG]], float 5.000000e+00, float 5.400000e+01
70 ; CHECK-NEXT: call void @use_float(float [[TMP]])
71 ; CHECK-NEXT: ret float [[TMP2]]
73 %tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+00
74 %tmp1 = select i1 %arg, float 1.000000e+00, float 9.000000e+00
75 %tmp2 = fmul float %tmp, %tmp1
76 call void @use_float(float %tmp)
80 ; Tests not folding constants if we cannot fold away any of the selects.
82 define float @test5(i1 zeroext %arg, float %div) {
83 ; CHECK-LABEL: @test5(
84 ; CHECK-NEXT: [[TMP:%.*]] = select i1 [[ARG:%.*]], float [[DIV:%.*]], float 5.000000e+00
85 ; CHECK-NEXT: [[MUL:%.*]] = fmul contract float [[TMP]], [[TMP]]
86 ; CHECK-NEXT: call void @use_float(float [[TMP]])
87 ; CHECK-NEXT: ret float [[MUL]]
89 %tmp = select i1 %arg, float %div, float 5.000000e+00
90 %mul = fmul contract float %tmp, %tmp
91 call void @use_float(float %tmp)