Home | History | Annotate | Download | only in InstCombine
      1 ; RUN: opt -S -instcombine < %s | FileCheck %s
      2 
      3 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_0_uitofp(
      4 ; CHECK-NEXT: icmp eq i32 %i, 0
      5 ; CHECK-NEXT: ret
      6 define i1 @i32_cast_cmp_oeq_int_0_uitofp(i32 %i) {
      7   %f = uitofp i32 %i to float
      8   %cmp = fcmp oeq float %f, 0.0
      9   ret i1 %cmp
     10 }
     11 
     12 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_n0_uitofp(
     13 ; CHECK-NEXT: icmp eq i32 %i, 0
     14 ; CHECK-NEXT: ret
     15 define i1 @i32_cast_cmp_oeq_int_n0_uitofp(i32 %i) {
     16   %f = uitofp i32 %i to float
     17   %cmp = fcmp oeq float %f, -0.0
     18   ret i1 %cmp
     19 }
     20 
     21 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_0_sitofp(
     22 ; CHECK-NEXT: icmp eq i32 %i, 0
     23 ; CHECK-NEXT: ret
     24 define i1 @i32_cast_cmp_oeq_int_0_sitofp(i32 %i) {
     25   %f = sitofp i32 %i to float
     26   %cmp = fcmp oeq float %f, 0.0
     27   ret i1 %cmp
     28 }
     29 
     30 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_n0_sitofp(
     31 ; CHECK-NEXT: icmp eq i32 %i, 0
     32 ; CHECK-NEXT: ret
     33 define i1 @i32_cast_cmp_oeq_int_n0_sitofp(i32 %i) {
     34   %f = sitofp i32 %i to float
     35   %cmp = fcmp oeq float %f, -0.0
     36   ret i1 %cmp
     37 }
     38 
     39 ; CHECK-LABEL: @i32_cast_cmp_one_int_0_uitofp(
     40 ; CHECK-NEXT: icmp ne i32 %i, 0
     41 ; CHECK-NEXT: ret
     42 define i1 @i32_cast_cmp_one_int_0_uitofp(i32 %i) {
     43   %f = uitofp i32 %i to float
     44   %cmp = fcmp one float %f, 0.0
     45   ret i1 %cmp
     46 }
     47 
     48 ; CHECK-LABEL: @i32_cast_cmp_one_int_n0_uitofp(
     49 ; CHECK-NEXT: icmp ne i32 %i, 0
     50 ; CHECK-NEXT: ret
     51 define i1 @i32_cast_cmp_one_int_n0_uitofp(i32 %i) {
     52   %f = uitofp i32 %i to float
     53   %cmp = fcmp one float %f, -0.0
     54   ret i1 %cmp
     55 }
     56 
     57 ; CHECK-LABEL: @i32_cast_cmp_one_int_0_sitofp(
     58 ; CHECK-NEXT: icmp ne i32 %i, 0
     59 ; CHECK-NEXT: ret
     60 define i1 @i32_cast_cmp_one_int_0_sitofp(i32 %i) {
     61   %f = sitofp i32 %i to float
     62   %cmp = fcmp one float %f, 0.0
     63   ret i1 %cmp
     64 }
     65 
     66 ; CHECK-LABEL: @i32_cast_cmp_one_int_n0_sitofp(
     67 ; CHECK-NEXT: icmp ne i32 %i, 0
     68 ; CHECK-NEXT: ret
     69 define i1 @i32_cast_cmp_one_int_n0_sitofp(i32 %i) {
     70   %f = sitofp i32 %i to float
     71   %cmp = fcmp one float %f, -0.0
     72   ret i1 %cmp
     73 }
     74 
     75 ; CHECK-LABEL: @i32_cast_cmp_ueq_int_0_uitofp(
     76 ; CHECK-NEXT: icmp eq i32 %i, 0
     77 ; CHECK-NEXT: ret
     78 define i1 @i32_cast_cmp_ueq_int_0_uitofp(i32 %i) {
     79   %f = uitofp i32 %i to float
     80   %cmp = fcmp ueq float %f, 0.0
     81   ret i1 %cmp
     82 }
     83 
     84 ; CHECK-LABEL: @i32_cast_cmp_ueq_int_n0_uitofp(
     85 ; CHECK-NEXT: icmp eq i32 %i, 0
     86 ; CHECK-NEXT: ret
     87 define i1 @i32_cast_cmp_ueq_int_n0_uitofp(i32 %i) {
     88   %f = uitofp i32 %i to float
     89   %cmp = fcmp ueq float %f, -0.0
     90   ret i1 %cmp
     91 }
     92 
     93 ; CHECK-LABEL: @i32_cast_cmp_ueq_int_0_sitofp(
     94 ; CHECK-NEXT: icmp eq i32 %i, 0
     95 ; CHECK-NEXT: ret
     96 define i1 @i32_cast_cmp_ueq_int_0_sitofp(i32 %i) {
     97   %f = sitofp i32 %i to float
     98   %cmp = fcmp ueq float %f, 0.0
     99   ret i1 %cmp
    100 }
    101 
    102 ; CHECK-LABEL: @i32_cast_cmp_ueq_int_n0_sitofp(
    103 ; CHECK-NEXT: icmp eq i32 %i, 0
    104 ; CHECK-NEXT: ret
    105 define i1 @i32_cast_cmp_ueq_int_n0_sitofp(i32 %i) {
    106   %f = sitofp i32 %i to float
    107   %cmp = fcmp ueq float %f, -0.0
    108   ret i1 %cmp
    109 }
    110 
    111 ; CHECK-LABEL: @i32_cast_cmp_une_int_0_uitofp(
    112 ; CHECK-NEXT: icmp ne i32 %i, 0
    113 ; CHECK-NEXT: ret
    114 define i1 @i32_cast_cmp_une_int_0_uitofp(i32 %i) {
    115   %f = uitofp i32 %i to float
    116   %cmp = fcmp une float %f, 0.0
    117   ret i1 %cmp
    118 }
    119 
    120 ; CHECK-LABEL: @i32_cast_cmp_une_int_n0_uitofp(
    121 ; CHECK-NEXT: icmp ne i32 %i, 0
    122 ; CHECK-NEXT: ret
    123 define i1 @i32_cast_cmp_une_int_n0_uitofp(i32 %i) {
    124   %f = uitofp i32 %i to float
    125   %cmp = fcmp une float %f, -0.0
    126   ret i1 %cmp
    127 }
    128 
    129 ; CHECK-LABEL: @i32_cast_cmp_une_int_0_sitofp(
    130 ; CHECK-NEXT: icmp ne i32 %i, 0
    131 ; CHECK-NEXT: ret
    132 define i1 @i32_cast_cmp_une_int_0_sitofp(i32 %i) {
    133   %f = sitofp i32 %i to float
    134   %cmp = fcmp une float %f, 0.0
    135   ret i1 %cmp
    136 }
    137 
    138 ; CHECK-LABEL: @i32_cast_cmp_une_int_n0_sitofp(
    139 ; CHECK-NEXT: icmp ne i32 %i, 0
    140 ; CHECK-NEXT: ret
    141 define i1 @i32_cast_cmp_une_int_n0_sitofp(i32 %i) {
    142   %f = sitofp i32 %i to float
    143   %cmp = fcmp une float %f, -0.0
    144   ret i1 %cmp
    145 }
    146 
    147 ; CHECK-LABEL: @i32_cast_cmp_ogt_int_0_uitofp(
    148 ; CHECK: icmp ne i32 %i, 0
    149 ; CHECK-NEXT: ret
    150 define i1 @i32_cast_cmp_ogt_int_0_uitofp(i32 %i) {
    151   %f = uitofp i32 %i to float
    152   %cmp = fcmp ogt float %f, 0.0
    153   ret i1 %cmp
    154 }
    155 
    156 ; CHECK-LABEL: @i32_cast_cmp_ogt_int_n0_uitofp(
    157 ; CHECK: icmp ne i32 %i, 0
    158 ; CHECK-NEXT: ret
    159 define i1 @i32_cast_cmp_ogt_int_n0_uitofp(i32 %i) {
    160   %f = uitofp i32 %i to float
    161   %cmp = fcmp ogt float %f, -0.0
    162   ret i1 %cmp
    163 }
    164 
    165 ; CHECK-LABEL: @i32_cast_cmp_ogt_int_0_sitofp(
    166 ; CHECK: icmp sgt i32 %i, 0
    167 ; CHECK-NEXT: ret
    168 define i1 @i32_cast_cmp_ogt_int_0_sitofp(i32 %i) {
    169   %f = sitofp i32 %i to float
    170   %cmp = fcmp ogt float %f, 0.0
    171   ret i1 %cmp
    172 }
    173 
    174 ; CHECK-LABEL: @i32_cast_cmp_ogt_int_n0_sitofp(
    175 ; CHECK: icmp sgt i32 %i, 0
    176 ; CHECK-NEXT: ret
    177 define i1 @i32_cast_cmp_ogt_int_n0_sitofp(i32 %i) {
    178   %f = sitofp i32 %i to float
    179   %cmp = fcmp ogt float %f, -0.0
    180   ret i1 %cmp
    181 }
    182 
    183 ; CHECK-LABEL: @i32_cast_cmp_ole_int_0_uitofp(
    184 ; CHECK: icmp eq i32 %i, 0
    185 ; CHECK-NEXT: ret
    186 define i1 @i32_cast_cmp_ole_int_0_uitofp(i32 %i) {
    187   %f = uitofp i32 %i to float
    188   %cmp = fcmp ole float %f, 0.0
    189   ret i1 %cmp
    190 }
    191 
    192 ; CHECK-LABEL: @i32_cast_cmp_ole_int_0_sitofp(
    193 ; CHECK: icmp slt i32 %i, 1
    194 ; CHECK-NEXT: ret
    195 define i1 @i32_cast_cmp_ole_int_0_sitofp(i32 %i) {
    196   %f = sitofp i32 %i to float
    197   %cmp = fcmp ole float %f, 0.0
    198   ret i1 %cmp
    199 }
    200 
    201 ; CHECK-LABEL: @i32_cast_cmp_olt_int_0_uitofp(
    202 ; CHECK: ret i1 false
    203 define i1 @i32_cast_cmp_olt_int_0_uitofp(i32 %i) {
    204   %f = uitofp i32 %i to float
    205   %cmp = fcmp olt float %f, 0.0
    206   ret i1 %cmp
    207 }
    208 
    209 ; CHECK-LABEL: @i32_cast_cmp_olt_int_0_sitofp(
    210 ; CHECK: icmp slt i32 %i, 0
    211 ; CHECK-NEXT: ret
    212 define i1 @i32_cast_cmp_olt_int_0_sitofp(i32 %i) {
    213   %f = sitofp i32 %i to float
    214   %cmp = fcmp olt float %f, 0.0
    215   ret i1 %cmp
    216 }
    217 
    218 ; CHECK-LABEL: @i64_cast_cmp_oeq_int_0_uitofp(
    219 ; CHECK-NEXT: icmp eq i64 %i, 0
    220 ; CHECK-NEXT: ret
    221 define i1 @i64_cast_cmp_oeq_int_0_uitofp(i64 %i) {
    222   %f = uitofp i64 %i to float
    223   %cmp = fcmp oeq float %f, 0.0
    224   ret i1 %cmp
    225 }
    226 
    227 ; CHECK-LABEL: @i64_cast_cmp_oeq_int_0_sitofp(
    228 ; CHECK-NEXT: icmp eq i64 %i, 0
    229 ; CHECK-NEXT: ret
    230 define i1 @i64_cast_cmp_oeq_int_0_sitofp(i64 %i) {
    231   %f = sitofp i64 %i to float
    232   %cmp = fcmp oeq float %f, 0.0
    233   ret i1 %cmp
    234 }
    235 
    236 ; CHECK-LABEL: @i64_cast_cmp_oeq_int_0_uitofp_half(
    237 ; CHECK-NEXT: icmp eq i64 %i, 0
    238 ; CHECK-NEXT: ret
    239 define i1 @i64_cast_cmp_oeq_int_0_uitofp_half(i64 %i) {
    240   %f = uitofp i64 %i to half
    241   %cmp = fcmp oeq half %f, 0.0
    242   ret i1 %cmp
    243 }
    244 
    245 ; CHECK-LABEL: @i64_cast_cmp_oeq_int_0_sitofp_half(
    246 ; CHECK-NEXT: icmp eq i64 %i, 0
    247 ; CHECK-NEXT: ret
    248 define i1 @i64_cast_cmp_oeq_int_0_sitofp_half(i64 %i) {
    249   %f = sitofp i64 %i to half
    250   %cmp = fcmp oeq half %f, 0.0
    251   ret i1 %cmp
    252 }
    253 
    254 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_0_uitofp_ppcf128(
    255 ; CHECK: uitofp
    256 ; CHECK: fcmp oeq
    257 ; CHECK-NEXT: ret
    258 define i1 @i32_cast_cmp_oeq_int_0_uitofp_ppcf128(i32 %i) {
    259   %f = uitofp i32 %i to ppc_fp128
    260   %cmp = fcmp oeq ppc_fp128 %f, 0xM00000000000000000000000000000000
    261   ret i1 %cmp
    262 }
    263 
    264 ; Since 0xFFFFFF fits in a float, and one less and 
    265 ; one more than it also fits without rounding, the 
    266 ; test can be optimized to an integer compare.
    267 
    268 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i24max_uitofp(
    269 ; CHECK: icmp eq i32 %i, 16777215
    270 ; CHECK-NEXT: ret
    271 define i1 @i32_cast_cmp_oeq_int_i24max_uitofp(i32 %i) {
    272   %f = uitofp i32 %i to float
    273   %cmp = fcmp oeq float %f, 0x416FFFFFE0000000
    274   ret i1 %cmp
    275 }
    276 
    277 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i24max_sitofp(
    278 ; CHECK: icmp eq i32 %i, 16777215
    279 ; CHECK-NEXT: ret
    280 define i1 @i32_cast_cmp_oeq_int_i24max_sitofp(i32 %i) {
    281   %f = sitofp i32 %i to float
    282   %cmp = fcmp oeq float %f, 0x416FFFFFE0000000
    283   ret i1 %cmp
    284 }
    285 
    286 ; Though 0x1000000 fits in a float, one more than it 
    287 ; would round to it too, hence a single integer comparison 
    288 ; does not suffice.
    289 
    290 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i24maxp1_uitofp(
    291 ; CHECK: uitofp
    292 ; CHECK: fcmp oeq
    293 
    294 ; XCHECK: icmp eq i32 %i, 16777216
    295 ; XCHECK-NEXT: ret
    296 define i1 @i32_cast_cmp_oeq_int_i24maxp1_uitofp(i32 %i) {
    297   %f = uitofp i32 %i to float
    298   %cmp = fcmp oeq float %f, 0x4170000000000000
    299   ret i1 %cmp
    300 }
    301 
    302 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i24maxp1_sitofp(
    303 ; CHECK: sitofp
    304 ; CHECK: fcmp oeq
    305 
    306 ; XCHECK: icmp eq i32 %i, 16777216
    307 ; XCHECK-NEXT: ret
    308 define i1 @i32_cast_cmp_oeq_int_i24maxp1_sitofp(i32 %i) {
    309   %f = sitofp i32 %i to float
    310   %cmp = fcmp oeq float %f, 0x4170000000000000
    311   ret i1 %cmp
    312 }
    313 
    314 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32umax_uitofp(
    315 ; CHECK: uitofp
    316 ; CHECK: fcmp oeq
    317 ; CHECK-NEXT: ret
    318 define i1 @i32_cast_cmp_oeq_int_i32umax_uitofp(i32 %i) {
    319   %f = uitofp i32 %i to float
    320   %cmp = fcmp oeq float %f, 0x41F0000000000000
    321   ret i1 %cmp
    322 }
    323 
    324 ; 32-bit unsigned integer cannot possibly round up to 1<<33
    325 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_big_uitofp(
    326 ; CHECK-NEXT: ret i1 false
    327 define i1 @i32_cast_cmp_oeq_int_big_uitofp(i32 %i) {
    328   %f = uitofp i32 %i to float
    329   %cmp = fcmp oeq float %f, 0x4200000000000000
    330   ret i1 %cmp
    331 }
    332 
    333 ; 32-bit signed integer cannot possibly round up to 1<<32
    334 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32umax_sitofp(
    335 ; CHECK-NEXT: ret i1 false
    336 define i1 @i32_cast_cmp_oeq_int_i32umax_sitofp(i32 %i) {
    337   %f = sitofp i32 %i to float
    338   %cmp = fcmp oeq float %f, 0x41F0000000000000
    339   ret i1 %cmp
    340 }
    341 
    342 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32imin_uitofp(
    343 ; CHECK: uitofp
    344 ; CHECK: fcmp oeq
    345 ; CHECK-NEXT: ret
    346 define i1 @i32_cast_cmp_oeq_int_i32imin_uitofp(i32 %i) {
    347   %f = uitofp i32 %i to float
    348   %cmp = fcmp oeq float %f, 0xC1E0000000000000
    349   ret i1 %cmp
    350 }
    351 
    352 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32imin_sitofp(
    353 ; CHECK: sitofp
    354 ; CHECK: fcmp oeq
    355 ; CHECK-NEXT: ret
    356 define i1 @i32_cast_cmp_oeq_int_i32imin_sitofp(i32 %i) {
    357   %f = sitofp i32 %i to float
    358   %cmp = fcmp oeq float %f, 0xC1E0000000000000
    359   ret i1 %cmp
    360 }
    361 
    362 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32imax_uitofp(
    363 ; CHECK: uitofp
    364 ; CHECK: fcmp oeq
    365 ; CHECK-NEXT: ret
    366 define i1 @i32_cast_cmp_oeq_int_i32imax_uitofp(i32 %i) {
    367   %f = uitofp i32 %i to float
    368   %cmp = fcmp oeq float %f, 0x41E0000000000000
    369   ret i1 %cmp
    370 }
    371 
    372 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32imax_sitofp(
    373 ; CHECK: sitofp
    374 ; CHECK: fcmp oeq
    375 ; CHECK-NEXT: ret
    376 define i1 @i32_cast_cmp_oeq_int_i32imax_sitofp(i32 %i) {
    377   %f = sitofp i32 %i to float
    378   %cmp = fcmp oeq float %f, 0x41E0000000000000
    379   ret i1 %cmp
    380 }
    381 
    382 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_negi32umax_uitofp(
    383 ; CHECK: uitofp
    384 ; CHECK: fcmp oeq
    385 ; CHECK-NEXT: ret
    386 define i1 @i32_cast_cmp_oeq_int_negi32umax_uitofp(i32 %i) {
    387   %f = uitofp i32 %i to float
    388   %cmp = fcmp oeq float %f, 0xC1F0000000000000
    389   ret i1 %cmp
    390 }
    391 
    392 ; 32-bit signed integer cannot possibly round to -1<<32
    393 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_negi32umax_sitofp(
    394 ; CHECK-NEXT: ret i1 false
    395 define i1 @i32_cast_cmp_oeq_int_negi32umax_sitofp(i32 %i) {
    396   %f = sitofp i32 %i to float
    397   %cmp = fcmp oeq float %f, 0xC1F0000000000000
    398   ret i1 %cmp
    399 }
    400 
    401 ; CHECK-LABEL: @i32_cast_cmp_oeq_half_uitofp(
    402 ; CHECK: ret i1 false
    403 define i1 @i32_cast_cmp_oeq_half_uitofp(i32 %i) {
    404   %f = uitofp i32 %i to float
    405   %cmp = fcmp oeq float %f, 0.5
    406   ret i1 %cmp
    407 }
    408 
    409 ; CHECK-LABEL: @i32_cast_cmp_oeq_half_sitofp(
    410 ; CHECK: ret i1 false
    411 define i1 @i32_cast_cmp_oeq_half_sitofp(i32 %i) {
    412   %f = sitofp i32 %i to float
    413   %cmp = fcmp oeq float %f, 0.5
    414   ret i1 %cmp
    415 }
    416 
    417 ; CHECK-LABEL: @i32_cast_cmp_one_half_uitofp(
    418 ; CHECK: ret i1 true
    419 define i1 @i32_cast_cmp_one_half_uitofp(i32 %i) {
    420   %f = uitofp i32 %i to float
    421   %cmp = fcmp one float %f, 0.5
    422   ret i1 %cmp
    423 }
    424 
    425 ; CHECK-LABEL: @i32_cast_cmp_one_half_sitofp(
    426 ; CHECK: ret i1 true
    427 define i1 @i32_cast_cmp_one_half_sitofp(i32 %i) {
    428   %f = sitofp i32 %i to float
    429   %cmp = fcmp one float %f, 0.5
    430   ret i1 %cmp
    431 }
    432 
    433 ; CHECK-LABEL: @i32_cast_cmp_ueq_half_uitofp(
    434 ; CHECK: ret i1 false
    435 define i1 @i32_cast_cmp_ueq_half_uitofp(i32 %i) {
    436   %f = uitofp i32 %i to float
    437   %cmp = fcmp ueq float %f, 0.5
    438   ret i1 %cmp
    439 }
    440 
    441 ; CHECK-LABEL: @i32_cast_cmp_ueq_half_sitofp(
    442 ; CHECK: ret i1 false
    443 define i1 @i32_cast_cmp_ueq_half_sitofp(i32 %i) {
    444   %f = sitofp i32 %i to float
    445   %cmp = fcmp ueq float %f, 0.5
    446   ret i1 %cmp
    447 }
    448 
    449 ; CHECK-LABEL: @i32_cast_cmp_une_half_uitofp(
    450 ; CHECK: ret i1 true
    451 define i1 @i32_cast_cmp_une_half_uitofp(i32 %i) {
    452   %f = uitofp i32 %i to float
    453   %cmp = fcmp une float %f, 0.5
    454   ret i1 %cmp
    455 }
    456 
    457 ; CHECK-LABEL: @i32_cast_cmp_une_half_sitofp(
    458 ; CHECK: ret i1 true
    459 define i1 @i32_cast_cmp_une_half_sitofp(i32 %i) {
    460   %f = sitofp i32 %i to float
    461   %cmp = fcmp une float %f, 0.5
    462   ret i1 %cmp
    463 }
    464 
    465 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_inf_uitofp(
    466 ; CHECK-NEXT: ret i1 false
    467 define i1 @i32_cast_cmp_oeq_int_inf_uitofp(i32 %i) {
    468   %f = uitofp i32 %i to float
    469   %cmp = fcmp oeq float %f, 0x7FF0000000000000
    470   ret i1 %cmp
    471 }
    472 
    473 ; CHECK-LABEL: @i32_cast_cmp_oeq_int_inf_sitofp(
    474 ; CHECK-NEXT: ret i1 false
    475 define i1 @i32_cast_cmp_oeq_int_inf_sitofp(i32 %i) {
    476   %f = sitofp i32 %i to float
    477   %cmp = fcmp oeq float %f, 0x7FF0000000000000
    478   ret i1 %cmp
    479 }
    480 
    481 ; An i128 could round to an IEEE single-precision infinity.
    482 ; CHECK-LABEL: @i128_cast_cmp_oeq_int_inf_uitofp(
    483 ; CHECK: uitofp
    484 ; CHECK: fcmp oeq
    485 ; CHECK-NEXT: ret
    486 define i1 @i128_cast_cmp_oeq_int_inf_uitofp(i128 %i) {
    487   %f = uitofp i128 %i to float
    488   %cmp = fcmp oeq float %f, 0x7FF0000000000000
    489   ret i1 %cmp
    490 }
    491