2018-05-22 05:09:14 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
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() {
|
2018-05-22 05:09:14 +08:00
|
|
|
; CHECK-LABEL: @test1(
|
|
|
|
; CHECK-NEXT: ret i8 -1
|
|
|
|
;
|
|
|
|
%x = fptoui float 2.550000e+02 to i8
|
|
|
|
ret i8 %x
|
2006-11-27 09:05:10 +08:00
|
|
|
}
|
|
|
|
|
2008-03-09 16:16:40 +08:00
|
|
|
define i8 @test2() {
|
2018-05-22 05:09:14 +08:00
|
|
|
; CHECK-LABEL: @test2(
|
|
|
|
; CHECK-NEXT: ret i8 -1
|
|
|
|
;
|
|
|
|
%x = fptosi float -1.000000e+00 to i8
|
|
|
|
ret i8 %x
|
2006-11-27 09:05:10 +08:00
|
|
|
}
|
2008-03-09 16:16:40 +08:00
|
|
|
|
2013-01-11 06:06:52 +08:00
|
|
|
define half @test3(float %a) {
|
2018-05-22 05:09:14 +08:00
|
|
|
; CHECK-LABEL: @test3(
|
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
|
|
|
|
; CHECK-NEXT: [[C:%.*]] = call half @llvm.fabs.f16(half [[TMP1]])
|
|
|
|
; CHECK-NEXT: ret half [[C]]
|
|
|
|
;
|
2013-01-11 06:06:52 +08:00
|
|
|
%b = call float @llvm.fabs.f32(float %a)
|
|
|
|
%c = fptrunc float %b to half
|
|
|
|
ret half %c
|
|
|
|
}
|
|
|
|
|
|
|
|
define half @test4(float %a) {
|
2018-05-22 05:09:14 +08:00
|
|
|
; CHECK-LABEL: @test4(
|
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
|
|
|
|
; CHECK-NEXT: [[C:%.*]] = fsub half 0xH8000, [[TMP1]]
|
|
|
|
; CHECK-NEXT: ret half [[C]]
|
|
|
|
;
|
2013-01-11 06:06:52 +08:00
|
|
|
%b = fsub float -0.0, %a
|
|
|
|
%c = fptrunc float %b to half
|
|
|
|
ret half %c
|
|
|
|
}
|
|
|
|
|
2014-01-18 08:48:14 +08:00
|
|
|
define half @test4-fast(float %a) {
|
2018-05-22 05:09:14 +08:00
|
|
|
; CHECK-LABEL: @test4-fast(
|
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
|
|
|
|
; CHECK-NEXT: [[C:%.*]] = fsub fast half 0xH8000, [[TMP1]]
|
|
|
|
; CHECK-NEXT: ret half [[C]]
|
|
|
|
;
|
2014-01-18 08:48:14 +08:00
|
|
|
%b = fsub fast float -0.0, %a
|
|
|
|
%c = fptrunc float %b to half
|
|
|
|
ret half %c
|
|
|
|
}
|
|
|
|
|
2013-10-04 05:08:05 +08:00
|
|
|
define half @test5(float %a, float %b, float %c) {
|
2018-05-22 05:09:14 +08:00
|
|
|
; CHECK-LABEL: @test5(
|
|
|
|
; CHECK-NEXT: [[D:%.*]] = fcmp ogt float [[A:%.*]], [[B:%.*]]
|
2018-05-31 08:16:58 +08:00
|
|
|
; CHECK-NEXT: [[E:%.*]] = select i1 [[D]], float [[C:%.*]], float 1.000000e+00
|
|
|
|
; CHECK-NEXT: [[F:%.*]] = fptrunc float [[E]] to half
|
2018-05-22 05:09:14 +08:00
|
|
|
; CHECK-NEXT: ret half [[F]]
|
|
|
|
;
|
2013-10-04 05:08:05 +08:00
|
|
|
%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) {
|
2018-05-22 05:09:14 +08:00
|
|
|
; 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 05:30:02 +08:00
|
|
|
%frem = frem <1 x double> %V, %V
|
|
|
|
%trunc = fptrunc <1 x double> %frem to <1 x float>
|
|
|
|
ret <1 x float> %trunc
|
|
|
|
}
|
2014-11-19 06:06:45 +08:00
|
|
|
|
|
|
|
define float @test7(double %V) {
|
2018-05-22 05:09:14 +08:00
|
|
|
; 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-11-19 06:06:45 +08:00
|
|
|
%frem = frem double %V, 1.000000e+00
|
|
|
|
%trunc = fptrunc double %frem to float
|
|
|
|
ret float %trunc
|
|
|
|
}
|
2014-12-12 12:34:07 +08:00
|
|
|
|
|
|
|
define float @test8(float %V) {
|
2018-05-22 05:09:14 +08:00
|
|
|
; 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]]
|
|
|
|
;
|
2014-12-12 12:34:07 +08:00
|
|
|
%fext = fpext float %V to double
|
|
|
|
%frem = frem double %fext, 1.000000e-01
|
|
|
|
%trunc = fptrunc double %frem to float
|
|
|
|
ret float %trunc
|
|
|
|
}
|
2015-05-29 08:04:30 +08:00
|
|
|
|
|
|
|
define half @test_fptrunc_fptrunc(double %V) {
|
2018-05-22 05:09:14 +08:00
|
|
|
; CHECK-LABEL: @test_fptrunc_fptrunc(
|
|
|
|
; CHECK-NEXT: [[T1:%.*]] = fptrunc double [[V:%.*]] to float
|
|
|
|
; CHECK-NEXT: [[T2:%.*]] = fptrunc float [[T1]] to half
|
|
|
|
; CHECK-NEXT: ret half [[T2]]
|
|
|
|
;
|
2015-05-29 08:04:30 +08:00
|
|
|
%t1 = fptrunc double %V to float
|
|
|
|
%t2 = fptrunc float %t1 to half
|
|
|
|
ret half %t2
|
|
|
|
}
|
2018-05-22 05:09:14 +08:00
|
|
|
|