1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -passes=instsimplify -S | FileCheck %s 3 4; Overflow on a float to int or int to float conversion is undefined (PR21130). 5 6define i8 @overflow_fptosi() { 7; CHECK-LABEL: @overflow_fptosi( 8; CHECK-NEXT: ret i8 poison 9; 10 %i = fptosi double 1.56e+02 to i8 11 ret i8 %i 12} 13 14define i8 @overflow_fptoui() { 15; CHECK-LABEL: @overflow_fptoui( 16; CHECK-NEXT: ret i8 poison 17; 18 %i = fptoui double 2.56e+02 to i8 19 ret i8 %i 20} 21 22; The maximum float is approximately 2 ** 128 which is 3.4E38. 23; The constant below is 4E38. Use a 130 bit integer to hold that 24; number; 129-bits for the value + 1 bit for the sign. 25 26define float @overflow_uitofp() { 27; CHECK-LABEL: @overflow_uitofp( 28; CHECK-NEXT: ret float 0x7FF0000000000000 29; 30 %i = uitofp i130 400000000000000000000000000000000000000 to float 31 ret float %i 32} 33 34define float @overflow_sitofp() { 35; CHECK-LABEL: @overflow_sitofp( 36; CHECK-NEXT: ret float 0x7FF0000000000000 37; 38 %i = sitofp i130 400000000000000000000000000000000000000 to float 39 ret float %i 40} 41 42; https://llvm.org/PR43907 - make sure that NaN doesn't morph into Inf. 43; SNaN becomes QNaN. 44 45define float @nan_f64_trunc() { 46; CHECK-LABEL: @nan_f64_trunc( 47; CHECK-NEXT: ret float 0x7FF8000000000000 48; 49 %f = fptrunc double 0x7FF0000000000001 to float 50 ret float %f 51} 52 53; Verify again with a vector and different destination type. 54; SNaN becomes SNaN (first two elements). 55; QNaN remains QNaN (third element). 56; Lower 42 bits of NaN source payload are lost. 57 58define <3 x half> @nan_v3f64_trunc() { 59; CHECK-LABEL: @nan_v3f64_trunc( 60; CHECK-NEXT: ret <3 x half> splat (half 0xH7E00) 61; 62 %f = fptrunc <3 x double> <double 0x7FF0020000000000, double 0x7FF003FFFFFFFFFF, double 0x7FF8000000000001> to <3 x half> 63 ret <3 x half> %f 64} 65 66define bfloat @nan_bf16_trunc() { 67; CHECK-LABEL: @nan_bf16_trunc( 68; CHECK-NEXT: ret bfloat 0xR7FC0 69; 70 %f = fptrunc double 0x7FF0000000000001 to bfloat 71 ret bfloat %f 72} 73 74define float @trunc_denorm_lost_fraction0() { 75; CHECK-LABEL: @trunc_denorm_lost_fraction0( 76; CHECK-NEXT: ret float 0.000000e+00 77; 78 %b = fptrunc double 0x0000000010000000 to float 79 ret float %b 80} 81 82define float @trunc_denorm_lost_fraction1() { 83; CHECK-LABEL: @trunc_denorm_lost_fraction1( 84; CHECK-NEXT: ret float 0.000000e+00 85; 86 %b = fptrunc double 0x0000000010000001 to float 87 ret float %b 88} 89 90define float @trunc_denorm_lost_fraction2() { 91; CHECK-LABEL: @trunc_denorm_lost_fraction2( 92; CHECK-NEXT: ret float 0.000000e+00 93; 94 %b = fptrunc double 0x000000001fffffff to float 95 ret float %b 96} 97 98define float @trunc_denorm_lost_fraction3() { 99; CHECK-LABEL: @trunc_denorm_lost_fraction3( 100; CHECK-NEXT: ret float 0.000000e+00 101; 102 %b = fptrunc double 0x0000000020000000 to float 103 ret float %b 104} 105 106define float @trunc_denorm_lost_fraction4() { 107; CHECK-LABEL: @trunc_denorm_lost_fraction4( 108; CHECK-NEXT: ret float -0.000000e+00 109; 110 %b = fptrunc double 0x8000000010000001 to float 111 ret float %b 112} 113