2006-11-27 09:05:10 +08:00
|
|
|
; Test some floating point casting cases
|
2009-10-12 15:18:14 +08:00
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
2006-11-27 09:05:10 +08:00
|
|
|
|
2008-03-09 16:16:40 +08:00
|
|
|
define i8 @test1() {
|
|
|
|
%x = fptoui float 2.550000e+02 to i8 ; <i8> [#uses=1]
|
|
|
|
ret i8 %x
|
2009-10-12 15:18:14 +08:00
|
|
|
; CHECK: ret i8 -1
|
2006-11-27 09:05:10 +08:00
|
|
|
}
|
|
|
|
|
2008-03-09 16:16:40 +08:00
|
|
|
define i8 @test2() {
|
|
|
|
%x = fptosi float -1.000000e+00 to i8 ; <i8> [#uses=1]
|
|
|
|
ret i8 %x
|
2009-10-12 15:18:14 +08:00
|
|
|
; CHECK: ret i8 -1
|
2006-11-27 09:05:10 +08:00
|
|
|
}
|
2008-03-09 16:16:40 +08:00
|
|
|
|
2013-01-11 06:06:52 +08:00
|
|
|
; CHECK: test3
|
|
|
|
define half @test3(float %a) {
|
|
|
|
; CHECK: fptrunc
|
|
|
|
; CHECK: llvm.fabs.f16
|
|
|
|
%b = call float @llvm.fabs.f32(float %a)
|
|
|
|
%c = fptrunc float %b to half
|
|
|
|
ret half %c
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK: test4
|
|
|
|
define half @test4(float %a) {
|
|
|
|
; CHECK: fptrunc
|
|
|
|
; CHECK: fsub
|
|
|
|
%b = fsub float -0.0, %a
|
|
|
|
%c = fptrunc float %b to half
|
|
|
|
ret half %c
|
|
|
|
}
|
|
|
|
|
2014-01-18 08:48:14 +08:00
|
|
|
; CHECK: test4-fast
|
|
|
|
define half @test4-fast(float %a) {
|
|
|
|
; CHECK: fptrunc
|
|
|
|
; CHECK: fsub fast
|
|
|
|
%b = fsub fast float -0.0, %a
|
|
|
|
%c = fptrunc float %b to half
|
|
|
|
ret half %c
|
|
|
|
}
|
|
|
|
|
2013-10-04 05:08:05 +08:00
|
|
|
; CHECK: test5
|
|
|
|
define half @test5(float %a, float %b, float %c) {
|
|
|
|
; CHECK: fcmp ogt
|
|
|
|
; CHECK: fptrunc
|
|
|
|
; CHECK: select
|
|
|
|
; CHECK: half 0xH3C00
|
|
|
|
%d = fcmp ogt float %a, %b
|
|
|
|
%e = select i1 %d, float %c, float 1.0
|
|
|
|
%f = fptrunc float %e to half
|
|
|
|
ret half %f
|
|
|
|
}
|
|
|
|
|
2013-01-11 06:06:52 +08:00
|
|
|
declare float @llvm.fabs.f32(float) nounwind readonly
|
2014-11-19 05:30:02 +08:00
|
|
|
|
|
|
|
define <1 x float> @test6(<1 x double> %V) {
|
|
|
|
%frem = frem <1 x double> %V, %V
|
|
|
|
%trunc = fptrunc <1 x double> %frem to <1 x float>
|
|
|
|
ret <1 x float> %trunc
|
|
|
|
; CHECK-LABEL: @test6
|
|
|
|
; CHECK-NEXT: %[[frem:.*]] = frem <1 x double> %V, %V
|
|
|
|
; CHECK-NEXT: %[[trunc:.*]] = fptrunc <1 x double> %[[frem]] to <1 x float>
|
|
|
|
; CHECK-NEXT: ret <1 x float> %trunc
|
|
|
|
}
|
2014-11-19 06:06:45 +08:00
|
|
|
|
|
|
|
define float @test7(double %V) {
|
|
|
|
%frem = frem double %V, 1.000000e+00
|
|
|
|
%trunc = fptrunc double %frem to float
|
|
|
|
ret float %trunc
|
|
|
|
; CHECK-LABEL: @test7
|
|
|
|
; CHECK-NEXT: %[[frem:.*]] = frem double %V, 1.000000e+00
|
|
|
|
; CHECK-NEXT: %[[trunc:.*]] = fptrunc double %frem to float
|
|
|
|
; CHECK-NEXT: ret float %trunc
|
|
|
|
}
|
2014-12-12 12:34:07 +08:00
|
|
|
|
|
|
|
define float @test8(float %V) {
|
|
|
|
%fext = fpext float %V to double
|
|
|
|
%frem = frem double %fext, 1.000000e-01
|
|
|
|
%trunc = fptrunc double %frem to float
|
|
|
|
ret float %trunc
|
|
|
|
; CHECK-LABEL: @test8
|
|
|
|
; CHECK-NEXT: %[[fext:.*]] = fpext float %V to double
|
|
|
|
; CHECK-NEXT: %[[frem:.*]] = frem double %fext, 1.000000e-01
|
|
|
|
; CHECK-NEXT: %[[trunc:.*]] = fptrunc double %frem to float
|
|
|
|
; CHECK-NEXT: ret float %trunc
|
|
|
|
}
|
2015-05-29 08:04:30 +08:00
|
|
|
|
|
|
|
; CHECK-LABEL: @test_fptrunc_fptrunc
|
|
|
|
; CHECK-NOT: fptrunc double {{.*}} to half
|
|
|
|
define half @test_fptrunc_fptrunc(double %V) {
|
|
|
|
%t1 = fptrunc double %V to float
|
|
|
|
%t2 = fptrunc float %t1 to half
|
|
|
|
ret half %t2
|
|
|
|
}
|