|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6 |
| 2 | +; RUN: cat %S/floating-point-constants.ll %s | opt -passes=instcombine -S | FileCheck %s |
| 3 | + |
| 4 | +declare double @nexttoward(double noundef, fp128 noundef) #0 |
| 5 | +declare float @nexttowardf(float noundef, fp128 noundef) #0 |
| 6 | + |
| 7 | +attributes #0 = { willreturn memory(errnomem: write) } |
| 8 | + |
| 9 | +; ================== |
| 10 | +; nexttoward tests |
| 11 | +; ================== |
| 12 | + |
| 13 | +define double @nexttoward_can_constant_fold_up_direction() { |
| 14 | +; CHECK-LABEL: define double @nexttoward_can_constant_fold_up_direction() { |
| 15 | +; CHECK-NEXT: [[NEXT:%.*]] = call double @nexttoward(double noundef 1.000000e+00, fp128 0xL00000000000000004000000000000000) |
| 16 | +; CHECK-NEXT: ret double [[NEXT]] |
| 17 | +; |
| 18 | + %arg = fpext double 2.0 to fp128 |
| 19 | + %next = call double @nexttoward(double noundef 1.0, fp128 %arg) |
| 20 | + ret double %next |
| 21 | +} |
| 22 | +define double @nexttoward_can_constant_fold_down_direction() { |
| 23 | +; CHECK-LABEL: define double @nexttoward_can_constant_fold_down_direction() { |
| 24 | +; CHECK-NEXT: [[NEXT:%.*]] = call double @nexttoward(double noundef 1.000000e+00, fp128 0xL00000000000000000000000000000000) |
| 25 | +; CHECK-NEXT: ret double [[NEXT]] |
| 26 | +; |
| 27 | + %arg = fpext double 0.0 to fp128 |
| 28 | + %next = call double @nexttoward(double noundef 1.0, fp128 %arg) |
| 29 | + ret double %next |
| 30 | +} |
| 31 | +define double @nexttoward_can_constant_fold_equal_args() { |
| 32 | +; CHECK-LABEL: define double @nexttoward_can_constant_fold_equal_args() { |
| 33 | +; CHECK-NEXT: [[NEXT:%.*]] = call double @nexttoward(double 1.000000e+00, fp128 0xL00000000000000003FFF000000000000) |
| 34 | +; CHECK-NEXT: ret double [[NEXT]] |
| 35 | +; |
| 36 | + %arg = fpext double 1.0 to fp128 |
| 37 | + %next = call double @nexttoward(double 1.0, fp128 %arg) |
| 38 | + ret double %next |
| 39 | +} |
| 40 | +define double @nexttoward_can_constant_fold_with_nan_arg() { |
| 41 | +; CHECK-LABEL: define double @nexttoward_can_constant_fold_with_nan_arg() { |
| 42 | +; CHECK-NEXT: [[NEXT:%.*]] = call double @nexttoward(double 1.000000e+00, fp128 0xL00000000000000007FFF800000000000) |
| 43 | +; CHECK-NEXT: ret double [[NEXT]] |
| 44 | +; |
| 45 | + %nan = load double, double* @dbl_nan |
| 46 | + %arg = fpext double %nan to fp128 |
| 47 | + %next = call double @nexttoward(double 1.0, fp128 %arg) |
| 48 | + ret double %next |
| 49 | +} |
| 50 | +define double @nexttoward_not_marked_dead_on_pos_overflow() { |
| 51 | +; CHECK-LABEL: define double @nexttoward_not_marked_dead_on_pos_overflow() { |
| 52 | +; CHECK-NEXT: [[NEXT:%.*]] = call double @nexttoward(double 0x7FEFFFFFFFFFFFFF, fp128 0xL00000000000000007FFF000000000000) |
| 53 | +; CHECK-NEXT: ret double [[NEXT]] |
| 54 | +; |
| 55 | + %pos_max = load double, double* @dbl_pos_max |
| 56 | + %pos_inf = load double, double* @dbl_pos_infinity |
| 57 | + %ext_pos_inf = fpext double %pos_inf to fp128 |
| 58 | + %next = call double @nexttoward(double %pos_max, fp128 %ext_pos_inf) |
| 59 | + ret double %next |
| 60 | +} |
| 61 | +define double @nexttoward_not_marked_dead_on_neg_overflow() { |
| 62 | +; CHECK-LABEL: define double @nexttoward_not_marked_dead_on_neg_overflow() { |
| 63 | +; CHECK-NEXT: [[NEXT:%.*]] = call double @nexttoward(double 0xFFEFFFFFFFFFFFFF, fp128 0xL0000000000000000FFFF000000000000) |
| 64 | +; CHECK-NEXT: ret double [[NEXT]] |
| 65 | +; |
| 66 | + %neg_max = load double, double* @dbl_neg_max |
| 67 | + %neg_inf = load double, double* @dbl_neg_infinity |
| 68 | + %ext_neg_inf = fpext double %neg_inf to fp128 |
| 69 | + %next = call double @nexttoward(double %neg_max, fp128 %ext_neg_inf) |
| 70 | + ret double %next |
| 71 | +} |
| 72 | +define double @nexttoward_not_marked_dead_on_zero_from_above() { |
| 73 | +; CHECK-LABEL: define double @nexttoward_not_marked_dead_on_zero_from_above() { |
| 74 | +; CHECK-NEXT: [[NEXT:%.*]] = call double @nexttoward(double 4.940660e-324, fp128 0xL00000000000000000000000000000000) |
| 75 | +; CHECK-NEXT: ret double [[NEXT]] |
| 76 | +; |
| 77 | + %subnormal = load double, double* @dbl_pos_min_subnormal |
| 78 | + %zero = fpext double 0.0 to fp128 |
| 79 | + %next = call double @nexttoward(double %subnormal, fp128 %zero) |
| 80 | + ret double %next |
| 81 | +} |
| 82 | +define double @nexttoward_not_marked_dead_on_zero_from_below() { |
| 83 | +; CHECK-LABEL: define double @nexttoward_not_marked_dead_on_zero_from_below() { |
| 84 | +; CHECK-NEXT: [[NEXT:%.*]] = call double @nexttoward(double -4.940660e-324, fp128 0xL00000000000000000000000000000000) |
| 85 | +; CHECK-NEXT: ret double [[NEXT]] |
| 86 | +; |
| 87 | + %subnormal = load double, double* @dbl_neg_min_subnormal |
| 88 | + %zero = fpext double 0.0 to fp128 |
| 89 | + %next = call double @nexttoward(double %subnormal, fp128 %zero) |
| 90 | + ret double %next |
| 91 | +} |
| 92 | +define double @nexttoward_not_marked_dead_on_subnormal() { |
| 93 | +; CHECK-LABEL: define double @nexttoward_not_marked_dead_on_subnormal() { |
| 94 | +; CHECK-NEXT: [[NEXT:%.*]] = call double @nexttoward(double 4.940660e-324, fp128 0xL00000000000000003FFF000000000000) |
| 95 | +; CHECK-NEXT: ret double [[NEXT]] |
| 96 | +; |
| 97 | + %subnormal = load double, double* @dbl_pos_min_subnormal |
| 98 | + %target = fpext double 1.0 to fp128 |
| 99 | + %next = call double @nexttoward(double %subnormal, fp128 %target) |
| 100 | + ret double %next |
| 101 | +} |
| 102 | + |
| 103 | +; ================== |
| 104 | +; nexttowardf tests |
| 105 | +; ================== |
| 106 | + |
| 107 | +define float @nexttowardf_can_constant_fold_up_direction() { |
| 108 | +; CHECK-LABEL: define float @nexttowardf_can_constant_fold_up_direction() { |
| 109 | +; CHECK-NEXT: [[NEXT:%.*]] = call float @nexttowardf(float noundef 1.000000e+00, fp128 0xL00000000000000004000000000000000) |
| 110 | +; CHECK-NEXT: ret float [[NEXT]] |
| 111 | +; |
| 112 | + %arg = fpext float 2.0 to fp128 |
| 113 | + %next = call float @nexttowardf(float noundef 1.0, fp128 %arg) |
| 114 | + ret float %next |
| 115 | +} |
| 116 | +define float @nexttowardf_can_constant_fold_down_direction() { |
| 117 | +; CHECK-LABEL: define float @nexttowardf_can_constant_fold_down_direction() { |
| 118 | +; CHECK-NEXT: [[NEXT:%.*]] = call float @nexttowardf(float noundef 1.000000e+00, fp128 0xL00000000000000000000000000000000) |
| 119 | +; CHECK-NEXT: ret float [[NEXT]] |
| 120 | +; |
| 121 | + %arg = fpext float 0.0 to fp128 |
| 122 | + %next = call float @nexttowardf(float noundef 1.0, fp128 %arg) |
| 123 | + ret float %next |
| 124 | +} |
| 125 | +define float @nexttowardf_can_constant_fold_equal_args() { |
| 126 | +; CHECK-LABEL: define float @nexttowardf_can_constant_fold_equal_args() { |
| 127 | +; CHECK-NEXT: [[NEXT:%.*]] = call float @nexttoward(float 1.000000e+00, fp128 0xL00000000000000003FFF000000000000) |
| 128 | +; CHECK-NEXT: ret float [[NEXT]] |
| 129 | +; |
| 130 | + %arg = fpext float 1.0 to fp128 |
| 131 | + %next = call float @nexttoward(float 1.0, fp128 %arg) |
| 132 | + ret float %next |
| 133 | +} |
| 134 | +define float @nexttowardf_can_constant_fold_with_nan_arg() { |
| 135 | +; CHECK-LABEL: define float @nexttowardf_can_constant_fold_with_nan_arg() { |
| 136 | +; CHECK-NEXT: [[NEXT:%.*]] = call float @nexttowardf(float 1.000000e+00, fp128 0xL00000000000000007FFF800000000000) |
| 137 | +; CHECK-NEXT: ret float [[NEXT]] |
| 138 | +; |
| 139 | + %nan = load float, float* @flt_nan |
| 140 | + %ext_nan = fpext float %nan to fp128 |
| 141 | + %next = call float @nexttowardf(float 1.0, fp128 %ext_nan) |
| 142 | + ret float %next |
| 143 | +} |
| 144 | +define float @nexttowardf_not_marked_dead_on_pos_overflow () { |
| 145 | +; CHECK-LABEL: define float @nexttowardf_not_marked_dead_on_pos_overflow() { |
| 146 | +; CHECK-NEXT: [[NEXT:%.*]] = call float @nexttowardf(float 0x47EFFFFFE0000000, fp128 0xL00000000000000007FFF000000000000) |
| 147 | +; CHECK-NEXT: ret float [[NEXT]] |
| 148 | +; |
| 149 | + %pos_max = load float, float* @flt_pos_max |
| 150 | + %pos_inf = load float, float* @flt_pos_infinity |
| 151 | + %ext_pos_inf = fpext float %pos_inf to fp128 |
| 152 | + %next = call float @nexttowardf(float %pos_max, fp128 %ext_pos_inf) |
| 153 | + ret float %next |
| 154 | +} |
| 155 | +define float @nexttowardf_not_marked_dead_on_neg_overflow() { |
| 156 | +; CHECK-LABEL: define float @nexttowardf_not_marked_dead_on_neg_overflow() { |
| 157 | +; CHECK-NEXT: [[NEXT:%.*]] = call float @nexttowardf(float 0xC7EFFFFFE0000000, fp128 0xL0000000000000000FFFF000000000000) |
| 158 | +; CHECK-NEXT: ret float [[NEXT]] |
| 159 | +; |
| 160 | + %neg_max = load float, float* @flt_neg_max |
| 161 | + %neg_inf = load float, float* @flt_neg_infinity |
| 162 | + %ext_neg_inf = fpext float %neg_inf to fp128 |
| 163 | + %next = call float @nexttowardf(float %neg_max, fp128 %ext_neg_inf) |
| 164 | + ret float %next |
| 165 | +} |
| 166 | +define float @nexttowardf_not_marked_dead_on_zero_from_above() { |
| 167 | +; CHECK-LABEL: define float @nexttowardf_not_marked_dead_on_zero_from_above() { |
| 168 | +; CHECK-NEXT: [[NEXT:%.*]] = call float @nexttowardf(float 0x36A0000000000000, fp128 0xL00000000000000000000000000000000) |
| 169 | +; CHECK-NEXT: ret float [[NEXT]] |
| 170 | +; |
| 171 | + %min_subnormal = load float, float* @flt_pos_min_subnormal |
| 172 | + %zero = fpext float 0.0 to fp128 |
| 173 | + %next = call float @nexttowardf(float %min_subnormal, fp128 %zero) |
| 174 | + ret float %next |
| 175 | +} |
| 176 | +define float @nexttowardf_not_marked_dead_on_zero_from_below() { |
| 177 | +; CHECK-LABEL: define float @nexttowardf_not_marked_dead_on_zero_from_below() { |
| 178 | +; CHECK-NEXT: [[NEXT:%.*]] = call float @nexttowardf(float 0xB6A0000000000000, fp128 0xL00000000000000000000000000000000) |
| 179 | +; CHECK-NEXT: ret float [[NEXT]] |
| 180 | +; |
| 181 | + %min_subnormal = load float, float* @flt_neg_min_subnormal |
| 182 | + %zero = fpext float 0.0 to fp128 |
| 183 | + %next = call float @nexttowardf(float %min_subnormal, fp128 %zero) |
| 184 | + ret float %next |
| 185 | +} |
| 186 | +define float @nexttowardf_not_marked_dead_on_subnormal() { |
| 187 | +; CHECK-LABEL: define float @nexttowardf_not_marked_dead_on_subnormal() { |
| 188 | +; CHECK-NEXT: [[NEXT:%.*]] = call float @nexttowardf(float 0x36A0000000000000, fp128 0xL00000000000000003FFF000000000000) |
| 189 | +; CHECK-NEXT: ret float [[NEXT]] |
| 190 | +; |
| 191 | + %subnormal = load float, float* @flt_pos_min_subnormal |
| 192 | + %target = fpext float 1.0 to fp128 |
| 193 | + %next = call float @nexttowardf(float %subnormal, fp128 %target) |
| 194 | + ret float %next |
| 195 | +} |
0 commit comments