|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6 |
| 2 | +; RUN: opt -S -passes=instsimplify < %s | FileCheck %s |
| 3 | + |
| 4 | +declare float @roundevenf(float) #0 |
| 5 | +declare float @llvm.roundeven.f32(float) |
| 6 | +declare double @roundeven(double) #0 |
| 7 | +declare double @llvm.roundeven.f64(double) |
| 8 | + |
| 9 | +define float @constant_fold_roundeven_f32_01() #0 { |
| 10 | +; CHECK-LABEL: define float @constant_fold_roundeven_f32_01( |
| 11 | +; CHECK-SAME: ) #[[ATTR0:[0-9]+]] { |
| 12 | +; CHECK-NEXT: [[X:%.*]] = call float @roundevenf(float 1.250000e+00) #[[ATTR0]] |
| 13 | +; CHECK-NEXT: ret float [[X]] |
| 14 | +; |
| 15 | + %x = call float @roundevenf(float 1.25) #0 |
| 16 | + ret float %x |
| 17 | +} |
| 18 | + |
| 19 | +define float @constant_fold_roundeven_f32_02() #0 { |
| 20 | +; CHECK-LABEL: define float @constant_fold_roundeven_f32_02( |
| 21 | +; CHECK-SAME: ) #[[ATTR0]] { |
| 22 | +; CHECK-NEXT: ret float -1.000000e+00 |
| 23 | +; |
| 24 | + %x = call float @llvm.roundeven.f32(float -1.25) #0 |
| 25 | + ret float %x |
| 26 | +} |
| 27 | + |
| 28 | +; roundeven rounds ties to even, so 1.5 -> 2.0 (nearest even) |
| 29 | +define float @constant_fold_roundeven_f32_03() #0 { |
| 30 | +; CHECK-LABEL: define float @constant_fold_roundeven_f32_03( |
| 31 | +; CHECK-SAME: ) #[[ATTR0]] { |
| 32 | +; CHECK-NEXT: [[X:%.*]] = call float @roundevenf(float 1.500000e+00) #[[ATTR0]] |
| 33 | +; CHECK-NEXT: ret float [[X]] |
| 34 | +; |
| 35 | + %x = call float @roundevenf(float 1.5) #0 |
| 36 | + ret float %x |
| 37 | +} |
| 38 | + |
| 39 | +; roundeven rounds ties to even, so -1.5 -> -2.0 (nearest even) |
| 40 | +define float @constant_fold_roundeven_f32_04() #0 { |
| 41 | +; CHECK-LABEL: define float @constant_fold_roundeven_f32_04( |
| 42 | +; CHECK-SAME: ) #[[ATTR0]] { |
| 43 | +; CHECK-NEXT: ret float -2.000000e+00 |
| 44 | +; |
| 45 | + %x = call float @llvm.roundeven.f32(float -1.5) #0 |
| 46 | + ret float %x |
| 47 | +} |
| 48 | + |
| 49 | +; roundeven rounds ties to even, so 2.5 -> 2.0 (nearest even) |
| 50 | +define float @constant_fold_roundeven_f32_05() #0 { |
| 51 | +; CHECK-LABEL: define float @constant_fold_roundeven_f32_05( |
| 52 | +; CHECK-SAME: ) #[[ATTR0]] { |
| 53 | +; CHECK-NEXT: [[X:%.*]] = call float @roundevenf(float 2.500000e+00) #[[ATTR0]] |
| 54 | +; CHECK-NEXT: ret float [[X]] |
| 55 | +; |
| 56 | + %x = call float @roundevenf(float 2.5) #0 |
| 57 | + ret float %x |
| 58 | +} |
| 59 | + |
| 60 | +; roundeven rounds ties to even, so -2.5 -> -2.0 (nearest even) |
| 61 | +define float @constant_fold_roundeven_f32_06() #0 { |
| 62 | +; CHECK-LABEL: define float @constant_fold_roundeven_f32_06( |
| 63 | +; CHECK-SAME: ) #[[ATTR0]] { |
| 64 | +; CHECK-NEXT: ret float -2.000000e+00 |
| 65 | +; |
| 66 | + %x = call float @llvm.roundeven.f32(float -2.5) #0 |
| 67 | + ret float %x |
| 68 | +} |
| 69 | + |
| 70 | +define float @constant_fold_roundeven_f32_07() #0 { |
| 71 | +; CHECK-LABEL: define float @constant_fold_roundeven_f32_07( |
| 72 | +; CHECK-SAME: ) #[[ATTR0]] { |
| 73 | +; CHECK-NEXT: [[X:%.*]] = call float @roundevenf(float 2.750000e+00) #[[ATTR0]] |
| 74 | +; CHECK-NEXT: ret float [[X]] |
| 75 | +; |
| 76 | + %x = call float @roundevenf(float 2.75) #0 |
| 77 | + ret float %x |
| 78 | +} |
| 79 | + |
| 80 | +define float @constant_fold_roundeven_f32_08() #0 { |
| 81 | +; CHECK-LABEL: define float @constant_fold_roundeven_f32_08( |
| 82 | +; CHECK-SAME: ) #[[ATTR0]] { |
| 83 | +; CHECK-NEXT: ret float -3.000000e+00 |
| 84 | +; |
| 85 | + %x = call float @llvm.roundeven.f32(float -2.75) #0 |
| 86 | + ret float %x |
| 87 | +} |
| 88 | + |
| 89 | +define double @constant_fold_roundeven_f64_01() #0 { |
| 90 | +; CHECK-LABEL: define double @constant_fold_roundeven_f64_01( |
| 91 | +; CHECK-SAME: ) #[[ATTR0]] { |
| 92 | +; CHECK-NEXT: [[X:%.*]] = call double @roundeven(double 1.300000e+00) #[[ATTR0]] |
| 93 | +; CHECK-NEXT: ret double [[X]] |
| 94 | +; |
| 95 | + %x = call double @roundeven(double 1.3) #0 |
| 96 | + ret double %x |
| 97 | +} |
| 98 | + |
| 99 | +define double @constant_fold_roundeven_f64_02() #0 { |
| 100 | +; CHECK-LABEL: define double @constant_fold_roundeven_f64_02( |
| 101 | +; CHECK-SAME: ) #[[ATTR0]] { |
| 102 | +; CHECK-NEXT: ret double -1.000000e+00 |
| 103 | +; |
| 104 | + %x = call double @llvm.roundeven.f64(double -1.3) #0 |
| 105 | + ret double %x |
| 106 | +} |
| 107 | + |
| 108 | +define double @constant_fold_roundeven_f64_03() #0 { |
| 109 | +; CHECK-LABEL: define double @constant_fold_roundeven_f64_03( |
| 110 | +; CHECK-SAME: ) #[[ATTR0]] { |
| 111 | +; CHECK-NEXT: [[X:%.*]] = call double @roundeven(double 1.500000e+00) #[[ATTR0]] |
| 112 | +; CHECK-NEXT: ret double [[X]] |
| 113 | +; |
| 114 | + %x = call double @roundeven(double 1.5) #0 |
| 115 | + ret double %x |
| 116 | +} |
| 117 | + |
| 118 | +define double @constant_fold_roundeven_f64_04() #0 { |
| 119 | +; CHECK-LABEL: define double @constant_fold_roundeven_f64_04( |
| 120 | +; CHECK-SAME: ) #[[ATTR0]] { |
| 121 | +; CHECK-NEXT: ret double -2.000000e+00 |
| 122 | +; |
| 123 | + %x = call double @llvm.roundeven.f64(double -1.5) #0 |
| 124 | + ret double %x |
| 125 | +} |
| 126 | + |
| 127 | +define double @constant_fold_roundeven_f64_05() #0 { |
| 128 | +; CHECK-LABEL: define double @constant_fold_roundeven_f64_05( |
| 129 | +; CHECK-SAME: ) #[[ATTR0]] { |
| 130 | +; CHECK-NEXT: [[X:%.*]] = call double @roundeven(double 2.500000e+00) #[[ATTR0]] |
| 131 | +; CHECK-NEXT: ret double [[X]] |
| 132 | +; |
| 133 | + %x = call double @roundeven(double 2.5) #0 |
| 134 | + ret double %x |
| 135 | +} |
| 136 | + |
| 137 | +define double @constant_fold_roundeven_f64_06() #0 { |
| 138 | +; CHECK-LABEL: define double @constant_fold_roundeven_f64_06( |
| 139 | +; CHECK-SAME: ) #[[ATTR0]] { |
| 140 | +; CHECK-NEXT: ret double -2.000000e+00 |
| 141 | +; |
| 142 | + %x = call double @llvm.roundeven.f64(double -2.5) #0 |
| 143 | + ret double %x |
| 144 | +} |
| 145 | + |
| 146 | +define double @constant_fold_roundeven_f64_07() #0 { |
| 147 | +; CHECK-LABEL: define double @constant_fold_roundeven_f64_07( |
| 148 | +; CHECK-SAME: ) #[[ATTR0]] { |
| 149 | +; CHECK-NEXT: [[X:%.*]] = call double @roundeven(double 2.700000e+00) #[[ATTR0]] |
| 150 | +; CHECK-NEXT: ret double [[X]] |
| 151 | +; |
| 152 | + %x = call double @roundeven(double 2.7) #0 |
| 153 | + ret double %x |
| 154 | +} |
| 155 | + |
| 156 | +define double @constant_fold_roundeven_f64_08() #0 { |
| 157 | +; CHECK-LABEL: define double @constant_fold_roundeven_f64_08( |
| 158 | +; CHECK-SAME: ) #[[ATTR0]] { |
| 159 | +; CHECK-NEXT: ret double -3.000000e+00 |
| 160 | +; |
| 161 | + %x = call double @llvm.roundeven.f64(double -2.7) #0 |
| 162 | + ret double %x |
| 163 | +} |
| 164 | + |
| 165 | +attributes #0 = { nounwind readnone willreturn } |
0 commit comments