1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instsimplify -S | FileCheck %s
4 ; X == 42.0 ? X : 42.0 --> 42.0
6 define double @oeq(double %x) {
8 ; CHECK-NEXT: ret double 4.200000e+01
10 %cmp = fcmp oeq double %x, 42.0
11 %cond = select i1 %cmp, double %x, double 42.0
15 ; X == 42.0 ? 42.0 : X --> X
17 define float @oeq_swapped(float %x) {
18 ; CHECK-LABEL: @oeq_swapped(
19 ; CHECK-NEXT: ret float [[X:%.*]]
21 %cmp = fcmp oeq float %x, 42.0
22 %cond = select i1 %cmp, float 42.0, float %x
26 ; x != y ? x : y -> x if it's the right kind of != and at least
27 ; one of x and y is not negative zero.
29 ; X != 42.0 ? X : 42.0 --> X
31 define double @une(double %x) {
33 ; CHECK-NEXT: ret double [[X:%.*]]
35 %cmp = fcmp une double %x, 42.0
36 %cond = select i1 %cmp, double %x, double 42.0
40 ; X != 42.0 ? 42.0 : X --> 42.0
42 define double @une_swapped(double %x) {
43 ; CHECK-LABEL: @une_swapped(
44 ; CHECK-NEXT: ret double 4.200000e+01
46 %cmp = fcmp une double %x, 42.0
47 %cond = select i1 %cmp, double 42.0, double %x
51 define double @une_could_be_negzero(double %x, double %y) {
52 ; CHECK-LABEL: @une_could_be_negzero(
53 ; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[X:%.*]], [[Y:%.*]]
54 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], double [[X]], double [[Y]]
55 ; CHECK-NEXT: ret double [[COND]]
57 %cmp = fcmp une double %x, %y
58 %cond = select i1 %cmp, double %x, double %y
62 define double @une_swapped_could_be_negzero(double %x, double %y) {
63 ; CHECK-LABEL: @une_swapped_could_be_negzero(
64 ; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[X:%.*]], [[Y:%.*]]
65 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], double [[Y]], double [[X]]
66 ; CHECK-NEXT: ret double [[COND]]
68 %cmp = fcmp une double %x, %y
69 %cond = select i1 %cmp, double %y, double %x
73 define double @one(double %x) {
75 ; CHECK-NEXT: [[CMP:%.*]] = fcmp one double [[X:%.*]], -1.000000e+00
76 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], double [[X]], double -1.000000e+00
77 ; CHECK-NEXT: ret double [[COND]]
79 %cmp = fcmp one double %x, -1.0
80 %cond = select i1 %cmp, double %x, double -1.0
84 define double @one_swapped(double %x) {
85 ; CHECK-LABEL: @one_swapped(
86 ; CHECK-NEXT: [[CMP:%.*]] = fcmp one double [[X:%.*]], -1.000000e+00
87 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], double -1.000000e+00, double [[X]]
88 ; CHECK-NEXT: ret double [[COND]]
90 %cmp = fcmp one double %x, -1.0
91 %cond = select i1 %cmp, double -1.0, double %x