1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; Test some floating point casting cases 3; RUN: opt < %s -instcombine -S | FileCheck %s 4 5define i8 @test1() { 6; CHECK-LABEL: @test1( 7; CHECK-NEXT: ret i8 -1 8; 9 %x = fptoui float 2.550000e+02 to i8 10 ret i8 %x 11} 12 13define i8 @test2() { 14; CHECK-LABEL: @test2( 15; CHECK-NEXT: ret i8 -1 16; 17 %x = fptosi float -1.000000e+00 to i8 18 ret i8 %x 19} 20 21define half @test3(float %a) { 22; CHECK-LABEL: @test3( 23; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half 24; CHECK-NEXT: [[C:%.*]] = call half @llvm.fabs.f16(half [[TMP1]]) 25; CHECK-NEXT: ret half [[C]] 26; 27 %b = call float @llvm.fabs.f32(float %a) 28 %c = fptrunc float %b to half 29 ret half %c 30} 31 32define half @test4(float %a) { 33; CHECK-LABEL: @test4( 34; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half 35; CHECK-NEXT: [[C:%.*]] = fsub half 0xH8000, [[TMP1]] 36; CHECK-NEXT: ret half [[C]] 37; 38 %b = fsub float -0.0, %a 39 %c = fptrunc float %b to half 40 ret half %c 41} 42 43define half @test4-fast(float %a) { 44; CHECK-LABEL: @test4-fast( 45; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half 46; CHECK-NEXT: [[C:%.*]] = fsub fast half 0xH8000, [[TMP1]] 47; CHECK-NEXT: ret half [[C]] 48; 49 %b = fsub fast float -0.0, %a 50 %c = fptrunc float %b to half 51 ret half %c 52} 53 54define half @test5(float %a, float %b, float %c) { 55; CHECK-LABEL: @test5( 56; CHECK-NEXT: [[D:%.*]] = fcmp ogt float [[A:%.*]], [[B:%.*]] 57; CHECK-NEXT: [[E:%.*]] = select i1 [[D]], float [[C:%.*]], float 1.000000e+00 58; CHECK-NEXT: [[F:%.*]] = fptrunc float [[E]] to half 59; CHECK-NEXT: ret half [[F]] 60; 61 %d = fcmp ogt float %a, %b 62 %e = select i1 %d, float %c, float 1.0 63 %f = fptrunc float %e to half 64 ret half %f 65} 66 67declare float @llvm.fabs.f32(float) nounwind readonly 68 69define <1 x float> @test6(<1 x double> %V) { 70; CHECK-LABEL: @test6( 71; CHECK-NEXT: [[FREM:%.*]] = frem <1 x double> [[V:%.*]], [[V]] 72; CHECK-NEXT: [[TRUNC:%.*]] = fptrunc <1 x double> [[FREM]] to <1 x float> 73; CHECK-NEXT: ret <1 x float> [[TRUNC]] 74; 75 %frem = frem <1 x double> %V, %V 76 %trunc = fptrunc <1 x double> %frem to <1 x float> 77 ret <1 x float> %trunc 78} 79 80define float @test7(double %V) { 81; CHECK-LABEL: @test7( 82; CHECK-NEXT: [[FREM:%.*]] = frem double [[V:%.*]], 1.000000e+00 83; CHECK-NEXT: [[TRUNC:%.*]] = fptrunc double [[FREM]] to float 84; CHECK-NEXT: ret float [[TRUNC]] 85; 86 %frem = frem double %V, 1.000000e+00 87 %trunc = fptrunc double %frem to float 88 ret float %trunc 89} 90 91define float @test8(float %V) { 92; CHECK-LABEL: @test8( 93; CHECK-NEXT: [[FEXT:%.*]] = fpext float [[V:%.*]] to double 94; CHECK-NEXT: [[FREM:%.*]] = frem double [[FEXT]], 1.000000e-01 95; CHECK-NEXT: [[TRUNC:%.*]] = fptrunc double [[FREM]] to float 96; CHECK-NEXT: ret float [[TRUNC]] 97; 98 %fext = fpext float %V to double 99 %frem = frem double %fext, 1.000000e-01 100 %trunc = fptrunc double %frem to float 101 ret float %trunc 102} 103 104define half @test_fptrunc_fptrunc(double %V) { 105; CHECK-LABEL: @test_fptrunc_fptrunc( 106; CHECK-NEXT: [[T1:%.*]] = fptrunc double [[V:%.*]] to float 107; CHECK-NEXT: [[T2:%.*]] = fptrunc float [[T1]] to half 108; CHECK-NEXT: ret half [[T2]] 109; 110 %t1 = fptrunc double %V to float 111 %t2 = fptrunc float %t1 to half 112 ret half %t2 113} 114 115