Revert r354244 "[DAGCombiner] Eliminate dead stores to stack."
[llvm-complete.git] / test / Transforms / InstCombine / fpcast.ll
blobbfc1de4ff6ddd576b6aa960096be177e0a8df958
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
5 define i8 @test1() {
6 ; CHECK-LABEL: @test1(
7 ; CHECK-NEXT:    ret i8 -1
9   %x = fptoui float 2.550000e+02 to i8
10   ret i8 %x
13 define i8 @test2() {
14 ; CHECK-LABEL: @test2(
15 ; CHECK-NEXT:    ret i8 -1
17   %x = fptosi float -1.000000e+00 to i8
18   ret i8 %x
21 define 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]]
27   %b = call float @llvm.fabs.f32(float %a)
28   %c = fptrunc float %b to half
29   ret half %c
32 define half @fneg_fptrunc(float %a) {
33 ; CHECK-LABEL: @fneg_fptrunc(
34 ; CHECK-NEXT:    [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
35 ; CHECK-NEXT:    [[C:%.*]] = fsub half 0xH8000, [[TMP1]]
36 ; CHECK-NEXT:    ret half [[C]]
38   %b = fsub float -0.0, %a
39   %c = fptrunc float %b to half
40   ret half %c
43 define <2 x half> @fneg_fptrunc_vec_undef(<2 x float> %a) {
44 ; CHECK-LABEL: @fneg_fptrunc_vec_undef(
45 ; CHECK-NEXT:    [[TMP1:%.*]] = fptrunc <2 x float> [[A:%.*]] to <2 x half>
46 ; CHECK-NEXT:    [[C:%.*]] = fsub <2 x half> <half 0xH8000, half 0xH8000>, [[TMP1]]
47 ; CHECK-NEXT:    ret <2 x half> [[C]]
49   %b = fsub <2 x float> <float -0.0, float undef>, %a
50   %c = fptrunc <2 x float> %b to <2 x half>
51   ret <2 x half> %c
54 define half @test4-fast(float %a) {
55 ; CHECK-LABEL: @test4-fast(
56 ; CHECK-NEXT:    [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
57 ; CHECK-NEXT:    [[C:%.*]] = fsub fast half 0xH8000, [[TMP1]]
58 ; CHECK-NEXT:    ret half [[C]]
60   %b = fsub fast float -0.0, %a
61   %c = fptrunc float %b to half
62   ret half %c
65 define half @test5(float %a, float %b, float %c) {
66 ; CHECK-LABEL: @test5(
67 ; CHECK-NEXT:    [[D:%.*]] = fcmp ogt float [[A:%.*]], [[B:%.*]]
68 ; CHECK-NEXT:    [[E:%.*]] = select i1 [[D]], float [[C:%.*]], float 1.000000e+00
69 ; CHECK-NEXT:    [[F:%.*]] = fptrunc float [[E]] to half
70 ; CHECK-NEXT:    ret half [[F]]
72   %d = fcmp ogt float %a, %b
73   %e = select i1 %d, float %c, float 1.0
74   %f = fptrunc float %e to half
75   ret half %f
78 declare float @llvm.fabs.f32(float) nounwind readonly
80 define <1 x float> @test6(<1 x double> %V) {
81 ; CHECK-LABEL: @test6(
82 ; CHECK-NEXT:    [[FREM:%.*]] = frem <1 x double> [[V:%.*]], [[V]]
83 ; CHECK-NEXT:    [[TRUNC:%.*]] = fptrunc <1 x double> [[FREM]] to <1 x float>
84 ; CHECK-NEXT:    ret <1 x float> [[TRUNC]]
86   %frem = frem <1 x double> %V, %V
87   %trunc = fptrunc <1 x double> %frem to <1 x float>
88   ret <1 x float> %trunc
91 define float @test7(double %V) {
92 ; CHECK-LABEL: @test7(
93 ; CHECK-NEXT:    [[FREM:%.*]] = frem double [[V:%.*]], 1.000000e+00
94 ; CHECK-NEXT:    [[TRUNC:%.*]] = fptrunc double [[FREM]] to float
95 ; CHECK-NEXT:    ret float [[TRUNC]]
97   %frem = frem double %V, 1.000000e+00
98   %trunc = fptrunc double %frem to float
99   ret float %trunc
102 define float @test8(float %V) {
103 ; CHECK-LABEL: @test8(
104 ; CHECK-NEXT:    [[FEXT:%.*]] = fpext float [[V:%.*]] to double
105 ; CHECK-NEXT:    [[FREM:%.*]] = frem double [[FEXT]], 1.000000e-01
106 ; CHECK-NEXT:    [[TRUNC:%.*]] = fptrunc double [[FREM]] to float
107 ; CHECK-NEXT:    ret float [[TRUNC]]
109   %fext = fpext float %V to double
110   %frem = frem double %fext, 1.000000e-01
111   %trunc = fptrunc double %frem to float
112   ret float %trunc
115 define half @test_fptrunc_fptrunc(double %V) {
116 ; CHECK-LABEL: @test_fptrunc_fptrunc(
117 ; CHECK-NEXT:    [[T1:%.*]] = fptrunc double [[V:%.*]] to float
118 ; CHECK-NEXT:    [[T2:%.*]] = fptrunc float [[T1]] to half
119 ; CHECK-NEXT:    ret half [[T2]]
121   %t1 = fptrunc double %V to float
122   %t2 = fptrunc float %t1 to half
123   ret half %t2