Some tests for APFloat conversions.
[oota-llvm.git] / test / CodeGen / X86 / nancvt.ll
1 ; RUN: llvm-as < %s | opt -std-compile-opts | llc | grep 2147027116 | count 3
2 ; RUN: llvm-as < %s | opt -std-compile-opts | llc | grep 2147228864 | count 3
3 ; RUN: llvm-as < %s | opt -std-compile-opts | llc | grep 2146502828 | count 3
4 ; RUN: llvm-as < %s | opt -std-compile-opts | llc | grep 2143034560 | count 3
5 ; Compile time conversions of NaNs.
6 ; ModuleID = 'nan2.c'
7 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
8 target triple = "i686-apple-darwin8"
9         %struct..0anon = type { float }
10         %struct..1anon = type { double }
11 @fnan = constant [3 x i32] [ i32 2143831397, i32 2143831396, i32 2143831398 ]           ; <[3 x i32]*> [#uses=1]
12 @dnan = constant [3 x i64] [ i64 9223235251041752696, i64 9223235251041752697, i64 9223235250773317239 ], align 8               ; <[3 x i64]*> [#uses=1]
13 @fsnan = constant [3 x i32] [ i32 2139637093, i32 2139637092, i32 2139637094 ]          ; <[3 x i32]*> [#uses=1]
14 @dsnan = constant [3 x i64] [ i64 9220983451228067448, i64 9220983451228067449, i64 9220983450959631991 ], align 8              ; <[3 x i64]*> [#uses=1]
15 @.str = internal constant [10 x i8] c"%08x%08x\0A\00"           ; <[10 x i8]*> [#uses=2]
16 @.str1 = internal constant [6 x i8] c"%08x\0A\00"               ; <[6 x i8]*> [#uses=2]
17
18 define i32 @main() {
19 entry:
20         %retval = alloca i32, align 4           ; <i32*> [#uses=1]
21         %i = alloca i32, align 4                ; <i32*> [#uses=20]
22         %uf = alloca %struct..0anon, align 4            ; <%struct..0anon*> [#uses=8]
23         %ud = alloca %struct..1anon, align 8            ; <%struct..1anon*> [#uses=10]
24         %"alloca point" = bitcast i32 0 to i32          ; <i32> [#uses=0]
25         store i32 0, i32* %i, align 4
26         br label %bb23
27
28 bb:             ; preds = %bb23
29         %tmp = load i32* %i, align 4            ; <i32> [#uses=1]
30         %tmp1 = getelementptr [3 x i32]* @fnan, i32 0, i32 %tmp         ; <i32*> [#uses=1]
31         %tmp2 = load i32* %tmp1, align 4                ; <i32> [#uses=1]
32         %tmp3 = getelementptr %struct..0anon* %uf, i32 0, i32 0         ; <float*> [#uses=1]
33         %tmp34 = bitcast float* %tmp3 to i32*           ; <i32*> [#uses=1]
34         store i32 %tmp2, i32* %tmp34, align 4
35         %tmp5 = getelementptr %struct..0anon* %uf, i32 0, i32 0         ; <float*> [#uses=1]
36         %tmp6 = load float* %tmp5, align 4              ; <float> [#uses=1]
37         %tmp67 = fpext float %tmp6 to double            ; <double> [#uses=1]
38         %tmp8 = getelementptr %struct..1anon* %ud, i32 0, i32 0         ; <double*> [#uses=1]
39         store double %tmp67, double* %tmp8, align 8
40         %tmp9 = getelementptr %struct..1anon* %ud, i32 0, i32 0         ; <double*> [#uses=1]
41         %tmp910 = bitcast double* %tmp9 to i64*         ; <i64*> [#uses=1]
42         %tmp11 = load i64* %tmp910, align 8             ; <i64> [#uses=1]
43         %tmp1112 = trunc i64 %tmp11 to i32              ; <i32> [#uses=1]
44         %tmp13 = and i32 %tmp1112, -1           ; <i32> [#uses=1]
45         %tmp14 = getelementptr %struct..1anon* %ud, i32 0, i32 0                ; <double*> [#uses=1]
46         %tmp1415 = bitcast double* %tmp14 to i64*               ; <i64*> [#uses=1]
47         %tmp16 = load i64* %tmp1415, align 8            ; <i64> [#uses=1]
48         %.cast = zext i32 32 to i64             ; <i64> [#uses=1]
49         %tmp17 = ashr i64 %tmp16, %.cast                ; <i64> [#uses=1]
50         %tmp1718 = trunc i64 %tmp17 to i32              ; <i32> [#uses=1]
51         %tmp19 = getelementptr [10 x i8]* @.str, i32 0, i32 0           ; <i8*> [#uses=1]
52         %tmp20 = call i32 (i8*, ...)* @printf( i8* %tmp19, i32 %tmp1718, i32 %tmp13 )           ; <i32> [#uses=0]
53         %tmp21 = load i32* %i, align 4          ; <i32> [#uses=1]
54         %tmp22 = add i32 %tmp21, 1              ; <i32> [#uses=1]
55         store i32 %tmp22, i32* %i, align 4
56         br label %bb23
57
58 bb23:           ; preds = %bb, %entry
59         %tmp24 = load i32* %i, align 4          ; <i32> [#uses=1]
60         %tmp25 = icmp sle i32 %tmp24, 2         ; <i1> [#uses=1]
61         %tmp2526 = zext i1 %tmp25 to i8         ; <i8> [#uses=1]
62         %toBool = icmp ne i8 %tmp2526, 0                ; <i1> [#uses=1]
63         br i1 %toBool, label %bb, label %bb27
64
65 bb27:           ; preds = %bb23
66         store i32 0, i32* %i, align 4
67         br label %bb46
68
69 bb28:           ; preds = %bb46
70         %tmp29 = load i32* %i, align 4          ; <i32> [#uses=1]
71         %tmp30 = getelementptr [3 x i64]* @dnan, i32 0, i32 %tmp29              ; <i64*> [#uses=1]
72         %tmp31 = load i64* %tmp30, align 8              ; <i64> [#uses=1]
73         %tmp32 = getelementptr %struct..1anon* %ud, i32 0, i32 0                ; <double*> [#uses=1]
74         %tmp3233 = bitcast double* %tmp32 to i64*               ; <i64*> [#uses=1]
75         store i64 %tmp31, i64* %tmp3233, align 8
76         %tmp35 = getelementptr %struct..1anon* %ud, i32 0, i32 0                ; <double*> [#uses=1]
77         %tmp36 = load double* %tmp35, align 8           ; <double> [#uses=1]
78         %tmp3637 = fptrunc double %tmp36 to float               ; <float> [#uses=1]
79         %tmp38 = getelementptr %struct..0anon* %uf, i32 0, i32 0                ; <float*> [#uses=1]
80         store float %tmp3637, float* %tmp38, align 4
81         %tmp39 = getelementptr %struct..0anon* %uf, i32 0, i32 0                ; <float*> [#uses=1]
82         %tmp3940 = bitcast float* %tmp39 to i32*                ; <i32*> [#uses=1]
83         %tmp41 = load i32* %tmp3940, align 4            ; <i32> [#uses=1]
84         %tmp42 = getelementptr [6 x i8]* @.str1, i32 0, i32 0           ; <i8*> [#uses=1]
85         %tmp43 = call i32 (i8*, ...)* @printf( i8* %tmp42, i32 %tmp41 )         ; <i32> [#uses=0]
86         %tmp44 = load i32* %i, align 4          ; <i32> [#uses=1]
87         %tmp45 = add i32 %tmp44, 1              ; <i32> [#uses=1]
88         store i32 %tmp45, i32* %i, align 4
89         br label %bb46
90
91 bb46:           ; preds = %bb28, %bb27
92         %tmp47 = load i32* %i, align 4          ; <i32> [#uses=1]
93         %tmp48 = icmp sle i32 %tmp47, 2         ; <i1> [#uses=1]
94         %tmp4849 = zext i1 %tmp48 to i8         ; <i8> [#uses=1]
95         %toBool50 = icmp ne i8 %tmp4849, 0              ; <i1> [#uses=1]
96         br i1 %toBool50, label %bb28, label %bb51
97
98 bb51:           ; preds = %bb46
99         store i32 0, i32* %i, align 4
100         br label %bb78
101
102 bb52:           ; preds = %bb78
103         %tmp53 = load i32* %i, align 4          ; <i32> [#uses=1]
104         %tmp54 = getelementptr [3 x i32]* @fsnan, i32 0, i32 %tmp53             ; <i32*> [#uses=1]
105         %tmp55 = load i32* %tmp54, align 4              ; <i32> [#uses=1]
106         %tmp56 = getelementptr %struct..0anon* %uf, i32 0, i32 0                ; <float*> [#uses=1]
107         %tmp5657 = bitcast float* %tmp56 to i32*                ; <i32*> [#uses=1]
108         store i32 %tmp55, i32* %tmp5657, align 4
109         %tmp58 = getelementptr %struct..0anon* %uf, i32 0, i32 0                ; <float*> [#uses=1]
110         %tmp59 = load float* %tmp58, align 4            ; <float> [#uses=1]
111         %tmp5960 = fpext float %tmp59 to double         ; <double> [#uses=1]
112         %tmp61 = getelementptr %struct..1anon* %ud, i32 0, i32 0                ; <double*> [#uses=1]
113         store double %tmp5960, double* %tmp61, align 8
114         %tmp62 = getelementptr %struct..1anon* %ud, i32 0, i32 0                ; <double*> [#uses=1]
115         %tmp6263 = bitcast double* %tmp62 to i64*               ; <i64*> [#uses=1]
116         %tmp64 = load i64* %tmp6263, align 8            ; <i64> [#uses=1]
117         %tmp6465 = trunc i64 %tmp64 to i32              ; <i32> [#uses=1]
118         %tmp66 = and i32 %tmp6465, -1           ; <i32> [#uses=1]
119         %tmp68 = getelementptr %struct..1anon* %ud, i32 0, i32 0                ; <double*> [#uses=1]
120         %tmp6869 = bitcast double* %tmp68 to i64*               ; <i64*> [#uses=1]
121         %tmp70 = load i64* %tmp6869, align 8            ; <i64> [#uses=1]
122         %.cast71 = zext i32 32 to i64           ; <i64> [#uses=1]
123         %tmp72 = ashr i64 %tmp70, %.cast71              ; <i64> [#uses=1]
124         %tmp7273 = trunc i64 %tmp72 to i32              ; <i32> [#uses=1]
125         %tmp74 = getelementptr [10 x i8]* @.str, i32 0, i32 0           ; <i8*> [#uses=1]
126         %tmp75 = call i32 (i8*, ...)* @printf( i8* %tmp74, i32 %tmp7273, i32 %tmp66 )           ; <i32> [#uses=0]
127         %tmp76 = load i32* %i, align 4          ; <i32> [#uses=1]
128         %tmp77 = add i32 %tmp76, 1              ; <i32> [#uses=1]
129         store i32 %tmp77, i32* %i, align 4
130         br label %bb78
131
132 bb78:           ; preds = %bb52, %bb51
133         %tmp79 = load i32* %i, align 4          ; <i32> [#uses=1]
134         %tmp80 = icmp sle i32 %tmp79, 2         ; <i1> [#uses=1]
135         %tmp8081 = zext i1 %tmp80 to i8         ; <i8> [#uses=1]
136         %toBool82 = icmp ne i8 %tmp8081, 0              ; <i1> [#uses=1]
137         br i1 %toBool82, label %bb52, label %bb83
138
139 bb83:           ; preds = %bb78
140         store i32 0, i32* %i, align 4
141         br label %bb101
142
143 bb84:           ; preds = %bb101
144         %tmp85 = load i32* %i, align 4          ; <i32> [#uses=1]
145         %tmp86 = getelementptr [3 x i64]* @dsnan, i32 0, i32 %tmp85             ; <i64*> [#uses=1]
146         %tmp87 = load i64* %tmp86, align 8              ; <i64> [#uses=1]
147         %tmp88 = getelementptr %struct..1anon* %ud, i32 0, i32 0                ; <double*> [#uses=1]
148         %tmp8889 = bitcast double* %tmp88 to i64*               ; <i64*> [#uses=1]
149         store i64 %tmp87, i64* %tmp8889, align 8
150         %tmp90 = getelementptr %struct..1anon* %ud, i32 0, i32 0                ; <double*> [#uses=1]
151         %tmp91 = load double* %tmp90, align 8           ; <double> [#uses=1]
152         %tmp9192 = fptrunc double %tmp91 to float               ; <float> [#uses=1]
153         %tmp93 = getelementptr %struct..0anon* %uf, i32 0, i32 0                ; <float*> [#uses=1]
154         store float %tmp9192, float* %tmp93, align 4
155         %tmp94 = getelementptr %struct..0anon* %uf, i32 0, i32 0                ; <float*> [#uses=1]
156         %tmp9495 = bitcast float* %tmp94 to i32*                ; <i32*> [#uses=1]
157         %tmp96 = load i32* %tmp9495, align 4            ; <i32> [#uses=1]
158         %tmp97 = getelementptr [6 x i8]* @.str1, i32 0, i32 0           ; <i8*> [#uses=1]
159         %tmp98 = call i32 (i8*, ...)* @printf( i8* %tmp97, i32 %tmp96 )         ; <i32> [#uses=0]
160         %tmp99 = load i32* %i, align 4          ; <i32> [#uses=1]
161         %tmp100 = add i32 %tmp99, 1             ; <i32> [#uses=1]
162         store i32 %tmp100, i32* %i, align 4
163         br label %bb101
164
165 bb101:          ; preds = %bb84, %bb83
166         %tmp102 = load i32* %i, align 4         ; <i32> [#uses=1]
167         %tmp103 = icmp sle i32 %tmp102, 2               ; <i1> [#uses=1]
168         %tmp103104 = zext i1 %tmp103 to i8              ; <i8> [#uses=1]
169         %toBool105 = icmp ne i8 %tmp103104, 0           ; <i1> [#uses=1]
170         br i1 %toBool105, label %bb84, label %bb106
171
172 bb106:          ; preds = %bb101
173         br label %return
174
175 return:         ; preds = %bb106
176         %retval107 = load i32* %retval          ; <i32> [#uses=1]
177         ret i32 %retval107
178 }
179
180 declare i32 @printf(i8*, ...)