summaryrefslogtreecommitdiff
path: root/tests/src/JIT/Regression/JitBlue/GitHub_21761/GitHub_21761.il
blob: 83e906a6bba42fa6580b362a19303bc288561953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

.assembly extern System.Runtime { }
.assembly extern System.Numerics.Vectors { }
.assembly GitHub_21761 { }

// Some basic tests to ensure that the JIT handles non-zero
// initialization correctly.

.class sequential sealed Point extends [System.Runtime]System.ValueType
{
    .field public int32 X
    .field public int32 Y
}

.method static bool ConstFixedSizeInitBlk() cil managed noinlining
{
    .locals init (valuetype Point a)

    ldloca a
    ldc.i4 42
    sizeof Point
    initblk

    ldloca a
    ldind.i4
    ldc.i4 0x2a2a2a2a
    ceq
    ret
}

.method static bool NonConstFixedSizeInitBlk() cil managed noinlining
{
    .locals init (valuetype Point a, int32 s)

    ldloca a
    ldloc s
    sizeof Point
    initblk

    ldloca a
    ldfld int32 Point::X
    ldc.i4 0
    ceq
    ret
}

.class sequential sealed Point64 extends [System.Runtime]System.ValueType
{
    .field public int64 X
    .field public int64 Y
}

.method static bool ConstFixedSizeInitBlk64() cil managed noinlining
{
    .locals init (valuetype Point64 a)

    ldloca a
    ldc.i4 42
    sizeof Point64
    initblk

    ldloca a
    ldind.i8
    ldc.i8 0x2a2a2a2a2a2a2a2a
    ceq
    ret
}

.method static bool NonConstFixedSizeInitBlk64() cil managed noinlining
{
    .locals init (valuetype Point64 a, int32 s)

    ldloca a
    ldloc s
    sizeof Point64
    initblk

    ldloca a
    ldfld int64 Point64::X
    ldc.i8 0
    ceq
    ret
}

// Small int promoted fields are supposed to be "normalize on load" so
// no special care is needed when initializing them. Still, make sure
// that field by field initialization handles small ints correctly.

.class sequential sealed SmallInts extends [System.Runtime]System.ValueType
{
    .field public int8 I8;
    .field public uint8 U8;
    .field public int16 I16;
}

.method static bool SmallIntsInitBlk() cil managed noinlining
{
    .locals init (valuetype SmallInts a)

    ldloca a
    ldc.i4 42
    sizeof SmallInts
    initblk

    ldloca a
    ldind.i1
    ldc.i4 0x2a
    bne.un FAIL

    ldloca a
    ldind.u1
    ldc.i4 0x2a
    bne.un FAIL

    ldloca a
    ldind.i2
    ldc.i4 0x2a2a
    bne.un FAIL

    ldc.i4 1
    ret

FAIL:
    ldc.i4 0
    ret
}

.method static bool SmallIntsSignedInitBlk() cil managed noinlining
{
    .locals init (valuetype SmallInts a)

    ldloca a
    ldc.i4 0x8a
    sizeof SmallInts
    initblk

    ldloca a
    ldind.i1
    ldc.i4 0xFFFFFF8a
    bne.un FAIL

    ldloca a
    ldind.u1
    ldc.i4 0x8a
    bne.un FAIL

    ldloca a
    ldind.i2
    ldc.i4 0xFFFF8a8a
    bne.un FAIL

    ldc.i4 1
    ret

FAIL:
    ldc.i4 0
    ret
}

// If floating point fields are involved, special care is needed
// since floating point constants having a required bit pattern
// have to be generated.

.class sequential sealed F32Vec3 extends [System.Runtime]System.ValueType
{
    .field public float32 X
    .field public float32 Y
    .field public float32 Z
}

// Make sure that the JIT produces an appropiate floating point constant.
// JIT's internal representation uses doubles to store constants, even
// when constants are float-typed. This means that the JIT should first
// create a float value having the required bit pattern and then convert
// it double. Directly creating a double having the required bit pattern
// is not valid.

.method static bool Float32InitBlk() cil managed noinlining
{
    .locals init (valuetype F32Vec3 a)

    ldloca a
    ldc.i4 42
    sizeof F32Vec3
    initblk

    ldloca a
    ldind.i4
    ldc.i4 0x2a2a2a2a
    ceq
    ret
}

// Initializing a float value with 255, 255, 255... is a special case
// because the result is a NaN. And since the JIT uses double to store
// float constants, this means that the JIT may end up producing a float
// NaN value, convert it to double and then convert it back to float
// during codegen. Will the NaN payload be preserved through conversions?
// This may depend on the host's floating point implementation.

.method static bool Float32NaNInitBlk() cil managed noinlining
{
    .locals init (valuetype F32Vec3 a)

    ldloca a
    ldc.i4 255
    sizeof F32Vec3
    initblk

    ldloca a
    ldind.i4
    ldc.i4 0xFFFFFFFF
    ceq
    ret
}

// Non-zero initialization of a GC reference is not exactly a valid scenario.
// Still, the JIT shouldn't end up generating invalid IR (non-zero GC typed
// constant nodes).

.class sequential sealed Pair extends [System.Runtime]System.ValueType
{
    .field public int64 Key
    .field public class [System.Runtime]System.Object Value
}

.method static bool ObjRefInitBlk() cil managed noinlining
{
    .locals init (valuetype Pair a)

    ldloca a
    ldc.i4 1
    sizeof Pair
    initblk

    ldloca a
    ldind.i8
    ldc.i8 0x0101010101010101
    ceq
    ret
}

// Non-zero SIMD constants are not supported so field by field initialization
// should not be attempted.

.class sequential sealed Wrapper extends [System.Runtime]System.ValueType
{
    .field public valuetype [System.Numerics.Vectors]System.Numerics.Vector4 Value
}

.method static bool SimdInitBlk() cil managed noinlining
{
    .locals init (valuetype Wrapper a, valuetype [System.Numerics.Vectors]System.Numerics.Vector4 v, float32 len)

    ldloca a
    ldc.i4 42
    ldc.i4 16
    initblk

    ldloca a
    ldflda valuetype [System.Numerics.Vectors]System.Numerics.Vector4 Wrapper::Value
    call instance float32 [System.Numerics.Vectors]System.Numerics.Vector4::Length()
    stloc len

    ldloca a
    ldfld valuetype [System.Numerics.Vectors]System.Numerics.Vector4 Wrapper::Value
    stloc v

    ldloca v
    ldind.i4
    ldc.i4 0x2a2a2a2a
    ceq
    ret
}

.method hidebysig static int32 Main() cil managed
{
    .entrypoint
    .locals init (valuetype Point a)

    call bool ConstFixedSizeInitBlk()
    brfalse FAIL

    call bool NonConstFixedSizeInitBlk()
    brfalse FAIL

    call bool ConstFixedSizeInitBlk64()
    brfalse FAIL

    call bool NonConstFixedSizeInitBlk64()
    brfalse FAIL

    call bool SmallIntsInitBlk()
    brfalse FAIL

    call bool SmallIntsSignedInitBlk()
    brfalse FAIL

    call bool Float32InitBlk()
    brfalse FAIL

    call bool Float32NaNInitBlk()
    brfalse FAIL

    call bool ObjRefInitBlk()
    brfalse FAIL
    
    call bool SimdInitBlk()
    brfalse FAIL

    ldc.i4 100
    ret
 FAIL:
    ldc.i4 1
    ret
}