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 6define 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 15define 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 24define 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 33define 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 42define 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 51define 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 60define 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 69define 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 78define 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 87define 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 96define 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 105define 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 114define 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 123define 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 132define 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 141define 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 150define 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 159define 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 168define 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 177define 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 186define 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 195define 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_sitofp( 202; CHECK: icmp slt i32 %i, 0 203; CHECK-NEXT: ret 204define i1 @i32_cast_cmp_olt_int_0_sitofp(i32 %i) { 205 %f = sitofp i32 %i to float 206 %cmp = fcmp olt float %f, 0.0 207 ret i1 %cmp 208} 209 210; CHECK-LABEL: @i64_cast_cmp_oeq_int_0_uitofp( 211; CHECK-NEXT: icmp eq i64 %i, 0 212; CHECK-NEXT: ret 213define i1 @i64_cast_cmp_oeq_int_0_uitofp(i64 %i) { 214 %f = uitofp i64 %i to float 215 %cmp = fcmp oeq float %f, 0.0 216 ret i1 %cmp 217} 218 219; CHECK-LABEL: @i64_cast_cmp_oeq_int_0_sitofp( 220; CHECK-NEXT: icmp eq i64 %i, 0 221; CHECK-NEXT: ret 222define i1 @i64_cast_cmp_oeq_int_0_sitofp(i64 %i) { 223 %f = sitofp i64 %i to float 224 %cmp = fcmp oeq float %f, 0.0 225 ret i1 %cmp 226} 227 228; CHECK-LABEL: @i64_cast_cmp_oeq_int_0_uitofp_half( 229; CHECK-NEXT: icmp eq i64 %i, 0 230; CHECK-NEXT: ret 231define i1 @i64_cast_cmp_oeq_int_0_uitofp_half(i64 %i) { 232 %f = uitofp i64 %i to half 233 %cmp = fcmp oeq half %f, 0.0 234 ret i1 %cmp 235} 236 237; CHECK-LABEL: @i64_cast_cmp_oeq_int_0_sitofp_half( 238; CHECK-NEXT: icmp eq i64 %i, 0 239; CHECK-NEXT: ret 240define i1 @i64_cast_cmp_oeq_int_0_sitofp_half(i64 %i) { 241 %f = sitofp i64 %i to half 242 %cmp = fcmp oeq half %f, 0.0 243 ret i1 %cmp 244} 245 246; CHECK-LABEL: @i32_cast_cmp_oeq_int_0_uitofp_ppcf128( 247; CHECK: uitofp 248; CHECK: fcmp oeq 249; CHECK-NEXT: ret 250define i1 @i32_cast_cmp_oeq_int_0_uitofp_ppcf128(i32 %i) { 251 %f = uitofp i32 %i to ppc_fp128 252 %cmp = fcmp oeq ppc_fp128 %f, 0xM00000000000000000000000000000000 253 ret i1 %cmp 254} 255 256; Since 0xFFFFFF fits in a float, and one less and 257; one more than it also fits without rounding, the 258; test can be optimized to an integer compare. 259 260; CHECK-LABEL: @i32_cast_cmp_oeq_int_i24max_uitofp( 261; CHECK: icmp eq i32 %i, 16777215 262; CHECK-NEXT: ret 263define i1 @i32_cast_cmp_oeq_int_i24max_uitofp(i32 %i) { 264 %f = uitofp i32 %i to float 265 %cmp = fcmp oeq float %f, 0x416FFFFFE0000000 266 ret i1 %cmp 267} 268 269; CHECK-LABEL: @i32_cast_cmp_oeq_int_i24max_sitofp( 270; CHECK: icmp eq i32 %i, 16777215 271; CHECK-NEXT: ret 272define i1 @i32_cast_cmp_oeq_int_i24max_sitofp(i32 %i) { 273 %f = sitofp i32 %i to float 274 %cmp = fcmp oeq float %f, 0x416FFFFFE0000000 275 ret i1 %cmp 276} 277 278; Though 0x1000000 fits in a float, one more than it 279; would round to it too, hence a single integer comparison 280; does not suffice. 281 282; CHECK-LABEL: @i32_cast_cmp_oeq_int_i24maxp1_uitofp( 283; CHECK: uitofp 284; CHECK: fcmp oeq 285 286; XCHECK: icmp eq i32 %i, 16777216 287; XCHECK-NEXT: ret 288define i1 @i32_cast_cmp_oeq_int_i24maxp1_uitofp(i32 %i) { 289 %f = uitofp i32 %i to float 290 %cmp = fcmp oeq float %f, 0x4170000000000000 291 ret i1 %cmp 292} 293 294; CHECK-LABEL: @i32_cast_cmp_oeq_int_i24maxp1_sitofp( 295; CHECK: sitofp 296; CHECK: fcmp oeq 297 298; XCHECK: icmp eq i32 %i, 16777216 299; XCHECK-NEXT: ret 300define i1 @i32_cast_cmp_oeq_int_i24maxp1_sitofp(i32 %i) { 301 %f = sitofp i32 %i to float 302 %cmp = fcmp oeq float %f, 0x4170000000000000 303 ret i1 %cmp 304} 305 306; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32umax_uitofp( 307; CHECK: uitofp 308; CHECK: fcmp oeq 309; CHECK-NEXT: ret 310define i1 @i32_cast_cmp_oeq_int_i32umax_uitofp(i32 %i) { 311 %f = uitofp i32 %i to float 312 %cmp = fcmp oeq float %f, 0x41F0000000000000 313 ret i1 %cmp 314} 315 316; 32-bit unsigned integer cannot possibly round up to 1<<33 317; CHECK-LABEL: @i32_cast_cmp_oeq_int_big_uitofp( 318; CHECK-NEXT: ret i1 false 319define i1 @i32_cast_cmp_oeq_int_big_uitofp(i32 %i) { 320 %f = uitofp i32 %i to float 321 %cmp = fcmp oeq float %f, 0x4200000000000000 322 ret i1 %cmp 323} 324 325; 32-bit signed integer cannot possibly round up to 1<<32 326; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32umax_sitofp( 327; CHECK-NEXT: ret i1 false 328define i1 @i32_cast_cmp_oeq_int_i32umax_sitofp(i32 %i) { 329 %f = sitofp i32 %i to float 330 %cmp = fcmp oeq float %f, 0x41F0000000000000 331 ret i1 %cmp 332} 333 334; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32imin_sitofp( 335; CHECK: sitofp 336; CHECK: fcmp oeq 337; CHECK-NEXT: ret 338define i1 @i32_cast_cmp_oeq_int_i32imin_sitofp(i32 %i) { 339 %f = sitofp i32 %i to float 340 %cmp = fcmp oeq float %f, 0xC1E0000000000000 341 ret i1 %cmp 342} 343 344; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32imax_uitofp( 345; CHECK: uitofp 346; CHECK: fcmp oeq 347; CHECK-NEXT: ret 348define i1 @i32_cast_cmp_oeq_int_i32imax_uitofp(i32 %i) { 349 %f = uitofp i32 %i to float 350 %cmp = fcmp oeq float %f, 0x41E0000000000000 351 ret i1 %cmp 352} 353 354; CHECK-LABEL: @i32_cast_cmp_oeq_int_i32imax_sitofp( 355; CHECK: sitofp 356; CHECK: fcmp oeq 357; CHECK-NEXT: ret 358define i1 @i32_cast_cmp_oeq_int_i32imax_sitofp(i32 %i) { 359 %f = sitofp i32 %i to float 360 %cmp = fcmp oeq float %f, 0x41E0000000000000 361 ret i1 %cmp 362} 363 364; 32-bit signed integer cannot possibly round to -1<<32 365; CHECK-LABEL: @i32_cast_cmp_oeq_int_negi32umax_sitofp( 366; CHECK-NEXT: ret i1 false 367define i1 @i32_cast_cmp_oeq_int_negi32umax_sitofp(i32 %i) { 368 %f = sitofp i32 %i to float 369 %cmp = fcmp oeq float %f, 0xC1F0000000000000 370 ret i1 %cmp 371} 372 373; CHECK-LABEL: @i32_cast_cmp_oeq_half_uitofp( 374; CHECK: ret i1 false 375define i1 @i32_cast_cmp_oeq_half_uitofp(i32 %i) { 376 %f = uitofp i32 %i to float 377 %cmp = fcmp oeq float %f, 0.5 378 ret i1 %cmp 379} 380 381; CHECK-LABEL: @i32_cast_cmp_oeq_half_sitofp( 382; CHECK: ret i1 false 383define i1 @i32_cast_cmp_oeq_half_sitofp(i32 %i) { 384 %f = sitofp i32 %i to float 385 %cmp = fcmp oeq float %f, 0.5 386 ret i1 %cmp 387} 388 389; CHECK-LABEL: @i32_cast_cmp_one_half_uitofp( 390; CHECK: ret i1 true 391define i1 @i32_cast_cmp_one_half_uitofp(i32 %i) { 392 %f = uitofp i32 %i to float 393 %cmp = fcmp one float %f, 0.5 394 ret i1 %cmp 395} 396 397; CHECK-LABEL: @i32_cast_cmp_one_half_sitofp( 398; CHECK: ret i1 true 399define i1 @i32_cast_cmp_one_half_sitofp(i32 %i) { 400 %f = sitofp i32 %i to float 401 %cmp = fcmp one float %f, 0.5 402 ret i1 %cmp 403} 404 405; CHECK-LABEL: @i32_cast_cmp_ueq_half_uitofp( 406; CHECK: ret i1 false 407define i1 @i32_cast_cmp_ueq_half_uitofp(i32 %i) { 408 %f = uitofp i32 %i to float 409 %cmp = fcmp ueq float %f, 0.5 410 ret i1 %cmp 411} 412 413; CHECK-LABEL: @i32_cast_cmp_ueq_half_sitofp( 414; CHECK: ret i1 false 415define i1 @i32_cast_cmp_ueq_half_sitofp(i32 %i) { 416 %f = sitofp i32 %i to float 417 %cmp = fcmp ueq float %f, 0.5 418 ret i1 %cmp 419} 420 421; CHECK-LABEL: @i32_cast_cmp_une_half_uitofp( 422; CHECK: ret i1 true 423define i1 @i32_cast_cmp_une_half_uitofp(i32 %i) { 424 %f = uitofp i32 %i to float 425 %cmp = fcmp une float %f, 0.5 426 ret i1 %cmp 427} 428 429; CHECK-LABEL: @i32_cast_cmp_une_half_sitofp( 430; CHECK: ret i1 true 431define i1 @i32_cast_cmp_une_half_sitofp(i32 %i) { 432 %f = sitofp i32 %i to float 433 %cmp = fcmp une float %f, 0.5 434 ret i1 %cmp 435} 436 437; CHECK-LABEL: @i32_cast_cmp_oeq_int_inf_uitofp( 438; CHECK-NEXT: ret i1 false 439define i1 @i32_cast_cmp_oeq_int_inf_uitofp(i32 %i) { 440 %f = uitofp i32 %i to float 441 %cmp = fcmp oeq float %f, 0x7FF0000000000000 442 ret i1 %cmp 443} 444 445; CHECK-LABEL: @i32_cast_cmp_oeq_int_inf_sitofp( 446; CHECK-NEXT: ret i1 false 447define i1 @i32_cast_cmp_oeq_int_inf_sitofp(i32 %i) { 448 %f = sitofp i32 %i to float 449 %cmp = fcmp oeq float %f, 0x7FF0000000000000 450 ret i1 %cmp 451} 452 453; An i128 could round to an IEEE single-precision infinity. 454; CHECK-LABEL: @i128_cast_cmp_oeq_int_inf_uitofp( 455; CHECK: uitofp 456; CHECK: fcmp oeq 457; CHECK-NEXT: ret 458define i1 @i128_cast_cmp_oeq_int_inf_uitofp(i128 %i) { 459 %f = uitofp i128 %i to float 460 %cmp = fcmp oeq float %f, 0x7FF0000000000000 461 ret i1 %cmp 462} 463