@@ -220,29 +220,22 @@ TEST(InstructionsTest, CastInst) {
220
220
Type *VScaleV4Int16Ty = ScalableVectorType::get (Int16Ty, 4 );
221
221
Type *VScaleV1Int16Ty = ScalableVectorType::get (Int16Ty, 1 );
222
222
223
- Type *Int32PtrTy = PointerType::get (Int32Ty , 0 );
224
- Type *Int64PtrTy = PointerType::get (Int64Ty, 0 );
223
+ Type *PtrTy = PointerType::get (C , 0 );
224
+ Type *PtrAS1Ty = PointerType::get (C, 1 );
225
225
226
- Type *Int32PtrAS1Ty = PointerType::get (Int32Ty, 1 );
227
- Type *Int64PtrAS1Ty = PointerType::get (Int64Ty, 1 );
226
+ Type *V2PtrAS1Ty = FixedVectorType::get (PtrAS1Ty, 2 );
227
+ Type *V4PtrAS1Ty = FixedVectorType::get (PtrAS1Ty, 4 );
228
+ Type *VScaleV4PtrAS1Ty = ScalableVectorType::get (PtrAS1Ty, 4 );
228
229
229
- Type *V2Int32PtrAS1Ty = FixedVectorType::get (Int32PtrAS1Ty, 2 );
230
- Type *V2Int64PtrAS1Ty = FixedVectorType::get (Int64PtrAS1Ty, 2 );
231
- Type *V4Int32PtrAS1Ty = FixedVectorType::get (Int32PtrAS1Ty, 4 );
232
- Type *VScaleV4Int32PtrAS1Ty = ScalableVectorType::get (Int32PtrAS1Ty, 4 );
233
- Type *V4Int64PtrAS1Ty = FixedVectorType::get (Int64PtrAS1Ty, 4 );
234
-
235
- Type *V2Int64PtrTy = FixedVectorType::get (Int64PtrTy, 2 );
236
- Type *V2Int32PtrTy = FixedVectorType::get (Int32PtrTy, 2 );
237
- Type *VScaleV2Int32PtrTy = ScalableVectorType::get (Int32PtrTy, 2 );
238
- Type *V4Int32PtrTy = FixedVectorType::get (Int32PtrTy, 4 );
239
- Type *VScaleV4Int32PtrTy = ScalableVectorType::get (Int32PtrTy, 4 );
240
- Type *VScaleV4Int64PtrTy = ScalableVectorType::get (Int64PtrTy, 4 );
230
+ Type *V2PtrTy = FixedVectorType::get (PtrTy, 2 );
231
+ Type *V4PtrTy = FixedVectorType::get (PtrTy, 4 );
232
+ Type *VScaleV2PtrTy = ScalableVectorType::get (PtrTy, 2 );
233
+ Type *VScaleV4PtrTy = ScalableVectorType::get (PtrTy, 4 );
241
234
242
235
const Constant* c8 = Constant::getNullValue (V8x8Ty);
243
236
const Constant* c64 = Constant::getNullValue (V8x64Ty);
244
237
245
- const Constant *v2ptr32 = Constant::getNullValue (V2Int32PtrTy );
238
+ const Constant *v2ptr32 = Constant::getNullValue (V2PtrTy );
246
239
247
240
EXPECT_EQ (CastInst::Trunc, CastInst::getCastOpcode (c64, true , V8x8Ty, true ));
248
241
EXPECT_EQ (CastInst::SExt, CastInst::getCastOpcode (c8, true , V8x64Ty, true ));
@@ -251,23 +244,21 @@ TEST(InstructionsTest, CastInst) {
251
244
EXPECT_FALSE (CastInst::isBitCastable (V8x8Ty, V8x64Ty));
252
245
253
246
// Check address space casts are rejected since we don't know the sizes here
254
- EXPECT_FALSE (CastInst::isBitCastable (Int32PtrTy, Int32PtrAS1Ty));
255
- EXPECT_FALSE (CastInst::isBitCastable (Int32PtrAS1Ty, Int32PtrTy));
256
- EXPECT_FALSE (CastInst::isBitCastable (V2Int32PtrTy, V2Int32PtrAS1Ty));
257
- EXPECT_FALSE (CastInst::isBitCastable (V2Int32PtrAS1Ty, V2Int32PtrTy));
258
- EXPECT_TRUE (CastInst::isBitCastable (V2Int32PtrAS1Ty, V2Int64PtrAS1Ty));
259
- EXPECT_EQ (CastInst::AddrSpaceCast, CastInst::getCastOpcode (v2ptr32, true ,
260
- V2Int32PtrAS1Ty,
261
- true ));
247
+ EXPECT_FALSE (CastInst::isBitCastable (PtrTy, PtrAS1Ty));
248
+ EXPECT_FALSE (CastInst::isBitCastable (PtrAS1Ty, PtrTy));
249
+ EXPECT_FALSE (CastInst::isBitCastable (V2PtrTy, V2PtrAS1Ty));
250
+ EXPECT_FALSE (CastInst::isBitCastable (V2PtrAS1Ty, V2PtrTy));
251
+ EXPECT_TRUE (CastInst::isBitCastable (V2PtrAS1Ty, V2PtrAS1Ty));
252
+ EXPECT_EQ (CastInst::AddrSpaceCast,
253
+ CastInst::getCastOpcode (v2ptr32, true , V2PtrAS1Ty, true ));
262
254
263
255
// Test mismatched number of elements for pointers
264
- EXPECT_FALSE (CastInst::isBitCastable (V2Int32PtrAS1Ty, V4Int64PtrAS1Ty));
265
- EXPECT_FALSE (CastInst::isBitCastable (V4Int64PtrAS1Ty, V2Int32PtrAS1Ty));
266
- EXPECT_FALSE (CastInst::isBitCastable (V2Int32PtrAS1Ty, V4Int32PtrAS1Ty));
267
- EXPECT_FALSE (CastInst::isBitCastable (Int32PtrTy, V2Int32PtrTy));
268
- EXPECT_FALSE (CastInst::isBitCastable (V2Int32PtrTy, Int32PtrTy));
256
+ EXPECT_FALSE (CastInst::isBitCastable (V2PtrAS1Ty, V4PtrAS1Ty));
257
+ EXPECT_FALSE (CastInst::isBitCastable (V4PtrAS1Ty, V2PtrAS1Ty));
258
+ EXPECT_FALSE (CastInst::isBitCastable (PtrTy, V2PtrTy));
259
+ EXPECT_FALSE (CastInst::isBitCastable (V2PtrTy, PtrTy));
269
260
270
- EXPECT_TRUE (CastInst::isBitCastable (Int32PtrTy, Int64PtrTy ));
261
+ EXPECT_TRUE (CastInst::isBitCastable (PtrTy, PtrTy ));
271
262
EXPECT_FALSE (CastInst::isBitCastable (DoubleTy, FloatTy));
272
263
EXPECT_FALSE (CastInst::isBitCastable (FloatTy, DoubleTy));
273
264
EXPECT_TRUE (CastInst::isBitCastable (FloatTy, FloatTy));
@@ -281,55 +272,48 @@ TEST(InstructionsTest, CastInst) {
281
272
EXPECT_FALSE (CastInst::isBitCastable (Int32Ty, Int64Ty));
282
273
EXPECT_FALSE (CastInst::isBitCastable (Int64Ty, Int32Ty));
283
274
284
- EXPECT_FALSE (CastInst::isBitCastable (V2Int32PtrTy, Int64Ty));
285
- EXPECT_FALSE (CastInst::isBitCastable (Int64Ty, V2Int32PtrTy));
286
- EXPECT_TRUE (CastInst::isBitCastable (V2Int64PtrTy, V2Int32PtrTy));
287
- EXPECT_TRUE (CastInst::isBitCastable (V2Int32PtrTy, V2Int64PtrTy));
275
+ EXPECT_FALSE (CastInst::isBitCastable (V2PtrTy, Int64Ty));
276
+ EXPECT_FALSE (CastInst::isBitCastable (Int64Ty, V2PtrTy));
288
277
EXPECT_FALSE (CastInst::isBitCastable (V2Int32Ty, V2Int64Ty));
289
278
EXPECT_FALSE (CastInst::isBitCastable (V2Int64Ty, V2Int32Ty));
290
279
291
-
292
280
EXPECT_FALSE (CastInst::castIsValid (Instruction::BitCast,
293
- Constant::getNullValue (V4Int32PtrTy),
294
- V2Int32PtrTy));
281
+ Constant::getNullValue (V4PtrTy), V2PtrTy));
295
282
EXPECT_FALSE (CastInst::castIsValid (Instruction::BitCast,
296
- Constant::getNullValue (V2Int32PtrTy),
297
- V4Int32PtrTy));
283
+ Constant::getNullValue (V2PtrTy), V4PtrTy));
298
284
299
- EXPECT_FALSE (CastInst::castIsValid (Instruction::AddrSpaceCast,
300
- Constant::getNullValue (V4Int32PtrAS1Ty),
301
- V2Int32PtrTy));
302
- EXPECT_FALSE (CastInst::castIsValid (Instruction::AddrSpaceCast,
303
- Constant::getNullValue (V2Int32PtrTy),
304
- V4Int32PtrAS1Ty));
285
+ EXPECT_FALSE (CastInst::castIsValid (
286
+ Instruction::AddrSpaceCast, Constant::getNullValue (V4PtrAS1Ty), V2PtrTy));
287
+ EXPECT_FALSE (CastInst::castIsValid (
288
+ Instruction::AddrSpaceCast, Constant::getNullValue (V2PtrTy), V4PtrAS1Ty));
305
289
306
290
// Address space cast of fixed/scalable vectors of pointers to scalable/fixed
307
291
// vector of pointers.
308
- EXPECT_FALSE (CastInst::castIsValid (
309
- Instruction::AddrSpaceCast, Constant::getNullValue (VScaleV4Int32PtrAS1Ty),
310
- V4Int32PtrTy));
311
292
EXPECT_FALSE (CastInst::castIsValid (Instruction::AddrSpaceCast,
312
- Constant::getNullValue (V4Int32PtrTy),
313
- VScaleV4Int32PtrAS1Ty));
293
+ Constant::getNullValue (VScaleV4PtrAS1Ty),
294
+ V4PtrTy));
295
+ EXPECT_FALSE (CastInst::castIsValid (Instruction::AddrSpaceCast,
296
+ Constant::getNullValue (V4PtrTy),
297
+ VScaleV4PtrAS1Ty));
314
298
// Address space cast of scalable vectors of pointers to scalable vector of
315
299
// pointers.
316
- EXPECT_FALSE (CastInst::castIsValid (
317
- Instruction::AddrSpaceCast, Constant::getNullValue (VScaleV4Int32PtrAS1Ty),
318
- VScaleV2Int32PtrTy));
319
300
EXPECT_FALSE (CastInst::castIsValid (Instruction::AddrSpaceCast,
320
- Constant::getNullValue (VScaleV2Int32PtrTy),
321
- VScaleV4Int32PtrAS1Ty));
301
+ Constant::getNullValue (VScaleV4PtrAS1Ty),
302
+ VScaleV2PtrTy));
303
+ EXPECT_FALSE (CastInst::castIsValid (Instruction::AddrSpaceCast,
304
+ Constant::getNullValue (VScaleV2PtrTy),
305
+ VScaleV4PtrAS1Ty));
322
306
EXPECT_TRUE (CastInst::castIsValid (Instruction::AddrSpaceCast,
323
- Constant::getNullValue (VScaleV4Int64PtrTy ),
324
- VScaleV4Int32PtrAS1Ty ));
307
+ Constant::getNullValue (VScaleV4PtrTy ),
308
+ VScaleV4PtrAS1Ty ));
325
309
// Same number of lanes, different address space.
326
- EXPECT_TRUE (CastInst::castIsValid (
327
- Instruction::AddrSpaceCast, Constant::getNullValue (VScaleV4Int32PtrAS1Ty ),
328
- VScaleV4Int32PtrTy ));
310
+ EXPECT_TRUE (CastInst::castIsValid (Instruction::AddrSpaceCast,
311
+ Constant::getNullValue (VScaleV4PtrAS1Ty ),
312
+ VScaleV4PtrTy ));
329
313
// Same number of lanes, same address space.
330
314
EXPECT_FALSE (CastInst::castIsValid (Instruction::AddrSpaceCast,
331
- Constant::getNullValue (VScaleV4Int64PtrTy ),
332
- VScaleV4Int32PtrTy ));
315
+ Constant::getNullValue (VScaleV4PtrTy ),
316
+ VScaleV4PtrTy ));
333
317
334
318
// Bit casting fixed/scalable vector to scalable/fixed vectors.
335
319
EXPECT_FALSE (CastInst::castIsValid (Instruction::BitCast,
@@ -377,10 +361,10 @@ TEST(InstructionsTest, CastInst) {
377
361
// pointers
378
362
// First form
379
363
BasicBlock *BB = BasicBlock::Create (C);
380
- Constant *NullV2I32Ptr = Constant::getNullValue (V2Int32PtrTy );
364
+ Constant *NullV2I32Ptr = Constant::getNullValue (V2PtrTy );
381
365
auto Inst1 = CastInst::CreatePointerCast (NullV2I32Ptr, V2Int32Ty, " foo" , BB);
382
366
383
- Constant *NullVScaleV2I32Ptr = Constant::getNullValue (VScaleV2Int32PtrTy );
367
+ Constant *NullVScaleV2I32Ptr = Constant::getNullValue (VScaleV2PtrTy );
384
368
auto Inst1VScale = CastInst::CreatePointerCast (
385
369
NullVScaleV2I32Ptr, VScaleV2Int32Ty, " foo.vscale" , BB);
386
370
@@ -400,14 +384,12 @@ TEST(InstructionsTest, CastCAPI) {
400
384
LLVMContext C;
401
385
402
386
Type *Int8Ty = Type::getInt8Ty (C);
403
- Type *Int32Ty = Type::getInt32Ty (C);
404
387
Type *Int64Ty = Type::getInt64Ty (C);
405
388
406
389
Type *FloatTy = Type::getFloatTy (C);
407
390
Type *DoubleTy = Type::getDoubleTy (C);
408
391
409
- Type *Int8PtrTy = PointerType::get (Int8Ty, 0 );
410
- Type *Int32PtrTy = PointerType::get (Int32Ty, 0 );
392
+ Type *PtrTy = PointerType::get (C, 0 );
411
393
412
394
const Constant *C8 = Constant::getNullValue (Int8Ty);
413
395
const Constant *C64 = Constant::getNullValue (Int64Ty);
@@ -433,12 +415,11 @@ TEST(InstructionsTest, CastCAPI) {
433
415
EXPECT_EQ (LLVMFPExt,
434
416
LLVMGetCastOpcode (wrap (CF32), true , wrap (DoubleTy), true ));
435
417
436
- const Constant *CPtr8 = Constant::getNullValue (Int8PtrTy );
418
+ const Constant *CPtr8 = Constant::getNullValue (PtrTy );
437
419
438
420
EXPECT_EQ (LLVMPtrToInt,
439
421
LLVMGetCastOpcode (wrap (CPtr8), true , wrap (Int8Ty), true ));
440
- EXPECT_EQ (LLVMIntToPtr,
441
- LLVMGetCastOpcode (wrap (C8), true , wrap (Int8PtrTy), true ));
422
+ EXPECT_EQ (LLVMIntToPtr, LLVMGetCastOpcode (wrap (C8), true , wrap (PtrTy), true ));
442
423
443
424
Type *V8x8Ty = FixedVectorType::get (Int8Ty, 8 );
444
425
Type *V8x64Ty = FixedVectorType::get (Int64Ty, 8 );
@@ -448,26 +429,22 @@ TEST(InstructionsTest, CastCAPI) {
448
429
EXPECT_EQ (LLVMTrunc, LLVMGetCastOpcode (wrap (CV64), true , wrap (V8x8Ty), true ));
449
430
EXPECT_EQ (LLVMSExt, LLVMGetCastOpcode (wrap (CV8), true , wrap (V8x64Ty), true ));
450
431
451
- Type *Int32PtrAS1Ty = PointerType::get (Int32Ty , 1 );
452
- Type *V2Int32PtrAS1Ty = FixedVectorType::get (Int32PtrAS1Ty , 2 );
453
- Type *V2Int32PtrTy = FixedVectorType::get (Int32PtrTy , 2 );
454
- const Constant *CV2ptr32 = Constant::getNullValue (V2Int32PtrTy );
432
+ Type *PtrAS1Ty = PointerType::get (C , 1 );
433
+ Type *V2PtrAS1Ty = FixedVectorType::get (PtrAS1Ty , 2 );
434
+ Type *V2PtrTy = FixedVectorType::get (PtrTy , 2 );
435
+ const Constant *CV2Ptr = Constant::getNullValue (V2PtrTy );
455
436
456
- EXPECT_EQ (LLVMAddrSpaceCast, LLVMGetCastOpcode ( wrap (CV2ptr32), true ,
457
- wrap (V2Int32PtrAS1Ty ), true ));
437
+ EXPECT_EQ (LLVMAddrSpaceCast,
438
+ LLVMGetCastOpcode ( wrap (CV2Ptr), true , wrap (V2PtrAS1Ty ), true ));
458
439
}
459
440
460
441
TEST (InstructionsTest, VectorGep) {
461
442
LLVMContext C;
462
443
463
444
// Type Definitions
464
- Type *I8Ty = IntegerType::get (C, 8 );
465
445
Type *I32Ty = IntegerType::get (C, 32 );
466
- PointerType *Ptri8Ty = PointerType::get (I8Ty, 0 );
467
- PointerType *Ptri32Ty = PointerType::get (I32Ty, 0 );
468
-
469
- VectorType *V2xi8PTy = FixedVectorType::get (Ptri8Ty, 2 );
470
- VectorType *V2xi32PTy = FixedVectorType::get (Ptri32Ty, 2 );
446
+ PointerType *PtrTy = PointerType::get (C, 0 );
447
+ VectorType *V2xPTy = FixedVectorType::get (PtrTy, 2 );
471
448
472
449
// Test different aspects of the vector-of-pointers type
473
450
// and GEPs which use this type.
@@ -478,8 +455,8 @@ TEST(InstructionsTest, VectorGep) {
478
455
Constant *C2xi32a = ConstantVector::get (ConstVa);
479
456
Constant *C2xi32b = ConstantVector::get (ConstVb);
480
457
481
- CastInst *PtrVecA = new IntToPtrInst (C2xi32a, V2xi32PTy );
482
- CastInst *PtrVecB = new IntToPtrInst (C2xi32b, V2xi32PTy );
458
+ CastInst *PtrVecA = new IntToPtrInst (C2xi32a, V2xPTy );
459
+ CastInst *PtrVecB = new IntToPtrInst (C2xi32b, V2xPTy );
483
460
484
461
ICmpInst *ICmp0 = new ICmpInst (ICmpInst::ICMP_SGT, PtrVecA, PtrVecB);
485
462
ICmpInst *ICmp1 = new ICmpInst (ICmpInst::ICMP_ULT, PtrVecA, PtrVecB);
@@ -495,10 +472,10 @@ TEST(InstructionsTest, VectorGep) {
495
472
GetElementPtrInst *Gep2 = GetElementPtrInst::Create (I32Ty, PtrVecB, C2xi32a);
496
473
GetElementPtrInst *Gep3 = GetElementPtrInst::Create (I32Ty, PtrVecB, C2xi32b);
497
474
498
- CastInst *BTC0 = new BitCastInst (Gep0, V2xi8PTy );
499
- CastInst *BTC1 = new BitCastInst (Gep1, V2xi8PTy );
500
- CastInst *BTC2 = new BitCastInst (Gep2, V2xi8PTy );
501
- CastInst *BTC3 = new BitCastInst (Gep3, V2xi8PTy );
475
+ CastInst *BTC0 = new BitCastInst (Gep0, V2xPTy );
476
+ CastInst *BTC1 = new BitCastInst (Gep1, V2xPTy );
477
+ CastInst *BTC2 = new BitCastInst (Gep2, V2xPTy );
478
+ CastInst *BTC3 = new BitCastInst (Gep3, V2xPTy );
502
479
503
480
Value *S0 = BTC0->stripPointerCasts ();
504
481
Value *S1 = BTC1->stripPointerCasts ();
0 commit comments