Home | History | Annotate | Download | only in InstCombine
      1 ; RUN: opt -instcombine -S < %s | FileCheck %s
      2 
      3 ; --------------------------------------------------------------------
      4 ; llvm.amdgcn.rcp
      5 ; --------------------------------------------------------------------
      6 
      7 declare float @llvm.amdgcn.rcp.f32(float) nounwind readnone
      8 declare double @llvm.amdgcn.rcp.f64(double) nounwind readnone
      9 
     10 
     11 ; CHECK-LABEL: @test_constant_fold_rcp_f32_1
     12 ; CHECK-NEXT: ret float 1.000000e+00
     13 define float @test_constant_fold_rcp_f32_1() nounwind {
     14   %val = call float @llvm.amdgcn.rcp.f32(float 1.0) nounwind readnone
     15   ret float %val
     16 }
     17 
     18 ; CHECK-LABEL: @test_constant_fold_rcp_f64_1
     19 ; CHECK-NEXT:  ret double 1.000000e+00
     20 define double @test_constant_fold_rcp_f64_1() nounwind {
     21   %val = call double @llvm.amdgcn.rcp.f64(double 1.0) nounwind readnone
     22   ret double %val
     23 }
     24 
     25 ; CHECK-LABEL: @test_constant_fold_rcp_f32_half
     26 ; CHECK-NEXT: ret float 2.000000e+00
     27 define float @test_constant_fold_rcp_f32_half() nounwind {
     28   %val = call float @llvm.amdgcn.rcp.f32(float 0.5) nounwind readnone
     29   ret float %val
     30 }
     31 
     32 ; CHECK-LABEL: @test_constant_fold_rcp_f64_half
     33 ; CHECK-NEXT:  ret double 2.000000e+00
     34 define double @test_constant_fold_rcp_f64_half() nounwind {
     35   %val = call double @llvm.amdgcn.rcp.f64(double 0.5) nounwind readnone
     36   ret double %val
     37 }
     38 
     39 ; CHECK-LABEL: @test_constant_fold_rcp_f32_43
     40 ; CHECK-NEXT: call float @llvm.amdgcn.rcp.f32(float 4.300000e+01)
     41 define float @test_constant_fold_rcp_f32_43() nounwind {
     42  %val = call float @llvm.amdgcn.rcp.f32(float 4.300000e+01) nounwind readnone
     43  ret float %val
     44 }
     45 
     46 ; CHECK-LABEL: @test_constant_fold_rcp_f64_43
     47 ; CHECK-NEXT: call double @llvm.amdgcn.rcp.f64(double 4.300000e+01)
     48 define double @test_constant_fold_rcp_f64_43() nounwind {
     49   %val = call double @llvm.amdgcn.rcp.f64(double 4.300000e+01) nounwind readnone
     50   ret double %val
     51 }
     52 
     53 
     54 ; --------------------------------------------------------------------
     55 ; llvm.amdgcn.frexp.mant
     56 ; --------------------------------------------------------------------
     57 
     58 declare float @llvm.amdgcn.frexp.mant.f32(float) nounwind readnone
     59 declare double @llvm.amdgcn.frexp.mant.f64(double) nounwind readnone
     60 
     61 
     62 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_undef(
     63 ; CHECK-NEXT: ret float undef
     64 define float @test_constant_fold_frexp_mant_f32_undef() nounwind {
     65   %val = call float @llvm.amdgcn.frexp.mant.f32(float undef)
     66   ret float %val
     67 }
     68 
     69 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_undef(
     70 ; CHECK-NEXT:  ret double undef
     71 define double @test_constant_fold_frexp_mant_f64_undef() nounwind {
     72   %val = call double @llvm.amdgcn.frexp.mant.f64(double undef)
     73   ret double %val
     74 }
     75 
     76 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_0(
     77 ; CHECK-NEXT: ret float 0.000000e+00
     78 define float @test_constant_fold_frexp_mant_f32_0() nounwind {
     79   %val = call float @llvm.amdgcn.frexp.mant.f32(float 0.0)
     80   ret float %val
     81 }
     82 
     83 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_0(
     84 ; CHECK-NEXT:  ret double 0.000000e+00
     85 define double @test_constant_fold_frexp_mant_f64_0() nounwind {
     86   %val = call double @llvm.amdgcn.frexp.mant.f64(double 0.0)
     87   ret double %val
     88 }
     89 
     90 
     91 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_n0(
     92 ; CHECK-NEXT: ret float -0.000000e+00
     93 define float @test_constant_fold_frexp_mant_f32_n0() nounwind {
     94   %val = call float @llvm.amdgcn.frexp.mant.f32(float -0.0)
     95   ret float %val
     96 }
     97 
     98 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_n0(
     99 ; CHECK-NEXT:  ret double -0.000000e+00
    100 define double @test_constant_fold_frexp_mant_f64_n0() nounwind {
    101   %val = call double @llvm.amdgcn.frexp.mant.f64(double -0.0)
    102   ret double %val
    103 }
    104 
    105 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_1(
    106 ; CHECK-NEXT: ret float 5.000000e-01
    107 define float @test_constant_fold_frexp_mant_f32_1() nounwind {
    108   %val = call float @llvm.amdgcn.frexp.mant.f32(float 1.0)
    109   ret float %val
    110 }
    111 
    112 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_1(
    113 ; CHECK-NEXT:  ret double 5.000000e-01
    114 define double @test_constant_fold_frexp_mant_f64_1() nounwind {
    115   %val = call double @llvm.amdgcn.frexp.mant.f64(double 1.0)
    116   ret double %val
    117 }
    118 
    119 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_n1(
    120 ; CHECK-NEXT: ret float -5.000000e-01
    121 define float @test_constant_fold_frexp_mant_f32_n1() nounwind {
    122   %val = call float @llvm.amdgcn.frexp.mant.f32(float -1.0)
    123   ret float %val
    124 }
    125 
    126 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_n1(
    127 ; CHECK-NEXT:  ret double -5.000000e-01
    128 define double @test_constant_fold_frexp_mant_f64_n1() nounwind {
    129   %val = call double @llvm.amdgcn.frexp.mant.f64(double -1.0)
    130   ret double %val
    131 }
    132 
    133 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_nan(
    134 ; CHECK-NEXT: ret float 0x7FF8000000000000
    135 define float @test_constant_fold_frexp_mant_f32_nan() nounwind {
    136   %val = call float @llvm.amdgcn.frexp.mant.f32(float 0x7FF8000000000000)
    137   ret float %val
    138 }
    139 
    140 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_nan(
    141 ; CHECK-NEXT:  ret double 0x7FF8000000000000
    142 define double @test_constant_fold_frexp_mant_f64_nan() nounwind {
    143   %val = call double @llvm.amdgcn.frexp.mant.f64(double 0x7FF8000000000000)
    144   ret double %val
    145 }
    146 
    147 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_inf(
    148 ; CHECK-NEXT: ret float 0x7FF0000000000000
    149 define float @test_constant_fold_frexp_mant_f32_inf() nounwind {
    150   %val = call float @llvm.amdgcn.frexp.mant.f32(float 0x7FF0000000000000)
    151   ret float %val
    152 }
    153 
    154 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_inf(
    155 ; CHECK-NEXT:  ret double 0x7FF0000000000000
    156 define double @test_constant_fold_frexp_mant_f64_inf() nounwind {
    157   %val = call double @llvm.amdgcn.frexp.mant.f64(double 0x7FF0000000000000)
    158   ret double %val
    159 }
    160 
    161 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_ninf(
    162 ; CHECK-NEXT: ret float 0xFFF0000000000000
    163 define float @test_constant_fold_frexp_mant_f32_ninf() nounwind {
    164   %val = call float @llvm.amdgcn.frexp.mant.f32(float 0xFFF0000000000000)
    165   ret float %val
    166 }
    167 
    168 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_ninf(
    169 ; CHECK-NEXT:  ret double 0xFFF0000000000000
    170 define double @test_constant_fold_frexp_mant_f64_ninf() nounwind {
    171   %val = call double @llvm.amdgcn.frexp.mant.f64(double 0xFFF0000000000000)
    172   ret double %val
    173 }
    174 
    175 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_max_num(
    176 ; CHECK-NEXT: ret float 0x3FEFFFFFE0000000
    177 define float @test_constant_fold_frexp_mant_f32_max_num() nounwind {
    178   %val = call float @llvm.amdgcn.frexp.mant.f32(float 0x47EFFFFFE0000000)
    179   ret float %val
    180 }
    181 
    182 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_max_num(
    183 ; CHECK-NEXT:  ret double 0x3FEFFFFFFFFFFFFF
    184 define double @test_constant_fold_frexp_mant_f64_max_num() nounwind {
    185   %val = call double @llvm.amdgcn.frexp.mant.f64(double 0x7FEFFFFFFFFFFFFF)
    186   ret double %val
    187 }
    188 
    189 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f32_min_num(
    190 ; CHECK-NEXT: ret float 5.000000e-01
    191 define float @test_constant_fold_frexp_mant_f32_min_num() nounwind {
    192   %val = call float @llvm.amdgcn.frexp.mant.f32(float 0x36A0000000000000)
    193   ret float %val
    194 }
    195 
    196 ; CHECK-LABEL: @test_constant_fold_frexp_mant_f64_min_num(
    197 ; CHECK-NEXT:  ret double 5.000000e-01
    198 define double @test_constant_fold_frexp_mant_f64_min_num() nounwind {
    199   %val = call double @llvm.amdgcn.frexp.mant.f64(double 4.940656e-324)
    200   ret double %val
    201 }
    202 
    203 
    204 ; --------------------------------------------------------------------
    205 ; llvm.amdgcn.frexp.exp
    206 ; --------------------------------------------------------------------
    207 
    208 declare i32 @llvm.amdgcn.frexp.exp.f32(float) nounwind readnone
    209 declare i32 @llvm.amdgcn.frexp.exp.f64(double) nounwind readnone
    210 
    211 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f32_undef(
    212 ; CHECK-NEXT: ret i32 undef
    213 define i32 @test_constant_fold_frexp_exp_f32_undef() nounwind {
    214   %val = call i32 @llvm.amdgcn.frexp.exp.f32(float undef)
    215   ret i32 %val
    216 }
    217 
    218 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f64_undef(
    219 ; CHECK-NEXT:  ret i32 undef
    220 define i32 @test_constant_fold_frexp_exp_f64_undef() nounwind {
    221   %val = call i32 @llvm.amdgcn.frexp.exp.f64(double undef)
    222   ret i32 %val
    223 }
    224 
    225 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f32_0(
    226 ; CHECK-NEXT: ret i32 0
    227 define i32 @test_constant_fold_frexp_exp_f32_0() nounwind {
    228   %val = call i32 @llvm.amdgcn.frexp.exp.f32(float 0.0)
    229   ret i32 %val
    230 }
    231 
    232 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f64_0(
    233 ; CHECK-NEXT:  ret i32 0
    234 define i32 @test_constant_fold_frexp_exp_f64_0() nounwind {
    235   %val = call i32 @llvm.amdgcn.frexp.exp.f64(double 0.0)
    236   ret i32 %val
    237 }
    238 
    239 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f32_n0(
    240 ; CHECK-NEXT: ret i32 0
    241 define i32 @test_constant_fold_frexp_exp_f32_n0() nounwind {
    242   %val = call i32 @llvm.amdgcn.frexp.exp.f32(float -0.0)
    243   ret i32 %val
    244 }
    245 
    246 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f64_n0(
    247 ; CHECK-NEXT:  ret i32 0
    248 define i32 @test_constant_fold_frexp_exp_f64_n0() nounwind {
    249   %val = call i32 @llvm.amdgcn.frexp.exp.f64(double -0.0)
    250   ret i32 %val
    251 }
    252 
    253 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f32_1024(
    254 ; CHECK-NEXT: ret i32 11
    255 define i32 @test_constant_fold_frexp_exp_f32_1024() nounwind {
    256   %val = call i32 @llvm.amdgcn.frexp.exp.f32(float 1024.0)
    257   ret i32 %val
    258 }
    259 
    260 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f64_1024(
    261 ; CHECK-NEXT:  ret i32 11
    262 define i32 @test_constant_fold_frexp_exp_f64_1024() nounwind {
    263   %val = call i32 @llvm.amdgcn.frexp.exp.f64(double 1024.0)
    264   ret i32 %val
    265 }
    266 
    267 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f32_n1024(
    268 ; CHECK-NEXT: ret i32 11
    269 define i32 @test_constant_fold_frexp_exp_f32_n1024() nounwind {
    270   %val = call i32 @llvm.amdgcn.frexp.exp.f32(float -1024.0)
    271   ret i32 %val
    272 }
    273 
    274 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f64_n1024(
    275 ; CHECK-NEXT:  ret i32 11
    276 define i32 @test_constant_fold_frexp_exp_f64_n1024() nounwind {
    277   %val = call i32 @llvm.amdgcn.frexp.exp.f64(double -1024.0)
    278   ret i32 %val
    279 }
    280 
    281 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f32_1_1024(
    282 ; CHECK-NEXT: ret i32 -9
    283 define i32 @test_constant_fold_frexp_exp_f32_1_1024() nounwind {
    284   %val = call i32 @llvm.amdgcn.frexp.exp.f32(float 0.0009765625)
    285   ret i32 %val
    286 }
    287 
    288 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f64_1_1024(
    289 ; CHECK-NEXT:  ret i32 -9
    290 define i32 @test_constant_fold_frexp_exp_f64_1_1024() nounwind {
    291   %val = call i32 @llvm.amdgcn.frexp.exp.f64(double 0.0009765625)
    292   ret i32 %val
    293 }
    294 
    295 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f32_nan(
    296 ; CHECK-NEXT: ret i32 0
    297 define i32 @test_constant_fold_frexp_exp_f32_nan() nounwind {
    298   %val = call i32 @llvm.amdgcn.frexp.exp.f32(float 0x7FF8000000000000)
    299   ret i32 %val
    300 }
    301 
    302 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f64_nan(
    303 ; CHECK-NEXT:  ret i32 0
    304 define i32 @test_constant_fold_frexp_exp_f64_nan() nounwind {
    305   %val = call i32 @llvm.amdgcn.frexp.exp.f64(double 0x7FF8000000000000)
    306   ret i32 %val
    307 }
    308 
    309 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f32_inf(
    310 ; CHECK-NEXT: ret i32 0
    311 define i32 @test_constant_fold_frexp_exp_f32_inf() nounwind {
    312   %val = call i32 @llvm.amdgcn.frexp.exp.f32(float 0x7FF0000000000000)
    313   ret i32 %val
    314 }
    315 
    316 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f64_inf(
    317 ; CHECK-NEXT:  ret i32 0
    318 define i32 @test_constant_fold_frexp_exp_f64_inf() nounwind {
    319   %val = call i32 @llvm.amdgcn.frexp.exp.f64(double 0x7FF0000000000000)
    320   ret i32 %val
    321 }
    322 
    323 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f32_ninf(
    324 ; CHECK-NEXT: ret i32 0
    325 define i32 @test_constant_fold_frexp_exp_f32_ninf() nounwind {
    326   %val = call i32 @llvm.amdgcn.frexp.exp.f32(float 0xFFF0000000000000)
    327   ret i32 %val
    328 }
    329 
    330 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f64_ninf(
    331 ; CHECK-NEXT:  ret i32 0
    332 define i32 @test_constant_fold_frexp_exp_f64_ninf() nounwind {
    333   %val = call i32 @llvm.amdgcn.frexp.exp.f64(double 0xFFF0000000000000)
    334   ret i32 %val
    335 }
    336 
    337 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f32_max_num(
    338 ; CHECK-NEXT: ret i32 128
    339 define i32 @test_constant_fold_frexp_exp_f32_max_num() nounwind {
    340   %val = call i32 @llvm.amdgcn.frexp.exp.f32(float 0x47EFFFFFE0000000)
    341   ret i32 %val
    342 }
    343 
    344 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f64_max_num(
    345 ; CHECK-NEXT:  ret i32 1024
    346 define i32 @test_constant_fold_frexp_exp_f64_max_num() nounwind {
    347   %val = call i32 @llvm.amdgcn.frexp.exp.f64(double 0x7FEFFFFFFFFFFFFF)
    348   ret i32 %val
    349 }
    350 
    351 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f32_min_num(
    352 ; CHECK-NEXT: ret i32 -148
    353 define i32 @test_constant_fold_frexp_exp_f32_min_num() nounwind {
    354   %val = call i32 @llvm.amdgcn.frexp.exp.f32(float 0x36A0000000000000)
    355   ret i32 %val
    356 }
    357 
    358 ; CHECK-LABEL: @test_constant_fold_frexp_exp_f64_min_num(
    359 ; CHECK-NEXT:  ret i32 -1073
    360 define i32 @test_constant_fold_frexp_exp_f64_min_num() nounwind {
    361   %val = call i32 @llvm.amdgcn.frexp.exp.f64(double 4.940656e-324)
    362   ret i32 %val
    363 }
    364 
    365