@@ -220,29 +220,22 @@ TEST(InstructionsTest, CastInst) {
220220 Type *VScaleV4Int16Ty = ScalableVectorType::get (Int16Ty, 4 );
221221 Type *VScaleV1Int16Ty = ScalableVectorType::get (Int16Ty, 1 );
222222
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 );
225225
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 );
228229
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 );
241234
242235 const Constant* c8 = Constant::getNullValue (V8x8Ty);
243236 const Constant* c64 = Constant::getNullValue (V8x64Ty);
244237
245- const Constant *v2ptr32 = Constant::getNullValue (V2Int32PtrTy );
238+ const Constant *v2ptr32 = Constant::getNullValue (V2PtrTy );
246239
247240 EXPECT_EQ (CastInst::Trunc, CastInst::getCastOpcode (c64, true , V8x8Ty, true ));
248241 EXPECT_EQ (CastInst::SExt, CastInst::getCastOpcode (c8, true , V8x64Ty, true ));
@@ -251,23 +244,21 @@ TEST(InstructionsTest, CastInst) {
251244 EXPECT_FALSE (CastInst::isBitCastable (V8x8Ty, V8x64Ty));
252245
253246 // 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 ));
262254
263255 // 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));
269260
270- EXPECT_TRUE (CastInst::isBitCastable (Int32PtrTy, Int64PtrTy ));
261+ EXPECT_TRUE (CastInst::isBitCastable (PtrTy, PtrTy ));
271262 EXPECT_FALSE (CastInst::isBitCastable (DoubleTy, FloatTy));
272263 EXPECT_FALSE (CastInst::isBitCastable (FloatTy, DoubleTy));
273264 EXPECT_TRUE (CastInst::isBitCastable (FloatTy, FloatTy));
@@ -281,55 +272,48 @@ TEST(InstructionsTest, CastInst) {
281272 EXPECT_FALSE (CastInst::isBitCastable (Int32Ty, Int64Ty));
282273 EXPECT_FALSE (CastInst::isBitCastable (Int64Ty, Int32Ty));
283274
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));
288277 EXPECT_FALSE (CastInst::isBitCastable (V2Int32Ty, V2Int64Ty));
289278 EXPECT_FALSE (CastInst::isBitCastable (V2Int64Ty, V2Int32Ty));
290279
291-
292280 EXPECT_FALSE (CastInst::castIsValid (Instruction::BitCast,
293- Constant::getNullValue (V4Int32PtrTy),
294- V2Int32PtrTy));
281+ Constant::getNullValue (V4PtrTy), V2PtrTy));
295282 EXPECT_FALSE (CastInst::castIsValid (Instruction::BitCast,
296- Constant::getNullValue (V2Int32PtrTy),
297- V4Int32PtrTy));
283+ Constant::getNullValue (V2PtrTy), V4PtrTy));
298284
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));
305289
306290 // Address space cast of fixed/scalable vectors of pointers to scalable/fixed
307291 // vector of pointers.
308- EXPECT_FALSE (CastInst::castIsValid (
309- Instruction::AddrSpaceCast, Constant::getNullValue (VScaleV4Int32PtrAS1Ty),
310- V4Int32PtrTy));
311292 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));
314298 // Address space cast of scalable vectors of pointers to scalable vector of
315299 // pointers.
316- EXPECT_FALSE (CastInst::castIsValid (
317- Instruction::AddrSpaceCast, Constant::getNullValue (VScaleV4Int32PtrAS1Ty),
318- VScaleV2Int32PtrTy));
319300 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));
322306 EXPECT_TRUE (CastInst::castIsValid (Instruction::AddrSpaceCast,
323- Constant::getNullValue (VScaleV4Int64PtrTy ),
324- VScaleV4Int32PtrAS1Ty ));
307+ Constant::getNullValue (VScaleV4PtrTy ),
308+ VScaleV4PtrAS1Ty ));
325309 // 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 ));
329313 // Same number of lanes, same address space.
330314 EXPECT_FALSE (CastInst::castIsValid (Instruction::AddrSpaceCast,
331- Constant::getNullValue (VScaleV4Int64PtrTy ),
332- VScaleV4Int32PtrTy ));
315+ Constant::getNullValue (VScaleV4PtrTy ),
316+ VScaleV4PtrTy ));
333317
334318 // Bit casting fixed/scalable vector to scalable/fixed vectors.
335319 EXPECT_FALSE (CastInst::castIsValid (Instruction::BitCast,
@@ -377,10 +361,10 @@ TEST(InstructionsTest, CastInst) {
377361 // pointers
378362 // First form
379363 BasicBlock *BB = BasicBlock::Create (C);
380- Constant *NullV2I32Ptr = Constant::getNullValue (V2Int32PtrTy );
364+ Constant *NullV2I32Ptr = Constant::getNullValue (V2PtrTy );
381365 auto Inst1 = CastInst::CreatePointerCast (NullV2I32Ptr, V2Int32Ty, " foo" , BB);
382366
383- Constant *NullVScaleV2I32Ptr = Constant::getNullValue (VScaleV2Int32PtrTy );
367+ Constant *NullVScaleV2I32Ptr = Constant::getNullValue (VScaleV2PtrTy );
384368 auto Inst1VScale = CastInst::CreatePointerCast (
385369 NullVScaleV2I32Ptr, VScaleV2Int32Ty, " foo.vscale" , BB);
386370
@@ -400,14 +384,12 @@ TEST(InstructionsTest, CastCAPI) {
400384 LLVMContext C;
401385
402386 Type *Int8Ty = Type::getInt8Ty (C);
403- Type *Int32Ty = Type::getInt32Ty (C);
404387 Type *Int64Ty = Type::getInt64Ty (C);
405388
406389 Type *FloatTy = Type::getFloatTy (C);
407390 Type *DoubleTy = Type::getDoubleTy (C);
408391
409- Type *Int8PtrTy = PointerType::get (Int8Ty, 0 );
410- Type *Int32PtrTy = PointerType::get (Int32Ty, 0 );
392+ Type *PtrTy = PointerType::get (C, 0 );
411393
412394 const Constant *C8 = Constant::getNullValue (Int8Ty);
413395 const Constant *C64 = Constant::getNullValue (Int64Ty);
@@ -433,12 +415,11 @@ TEST(InstructionsTest, CastCAPI) {
433415 EXPECT_EQ (LLVMFPExt,
434416 LLVMGetCastOpcode (wrap (CF32), true , wrap (DoubleTy), true ));
435417
436- const Constant *CPtr8 = Constant::getNullValue (Int8PtrTy );
418+ const Constant *CPtr8 = Constant::getNullValue (PtrTy );
437419
438420 EXPECT_EQ (LLVMPtrToInt,
439421 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 ));
442423
443424 Type *V8x8Ty = FixedVectorType::get (Int8Ty, 8 );
444425 Type *V8x64Ty = FixedVectorType::get (Int64Ty, 8 );
@@ -448,26 +429,22 @@ TEST(InstructionsTest, CastCAPI) {
448429 EXPECT_EQ (LLVMTrunc, LLVMGetCastOpcode (wrap (CV64), true , wrap (V8x8Ty), true ));
449430 EXPECT_EQ (LLVMSExt, LLVMGetCastOpcode (wrap (CV8), true , wrap (V8x64Ty), true ));
450431
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 );
455436
456- EXPECT_EQ (LLVMAddrSpaceCast, LLVMGetCastOpcode ( wrap (CV2ptr32), true ,
457- wrap (V2Int32PtrAS1Ty ), true ));
437+ EXPECT_EQ (LLVMAddrSpaceCast,
438+ LLVMGetCastOpcode ( wrap (CV2Ptr), true , wrap (V2PtrAS1Ty ), true ));
458439}
459440
460441TEST (InstructionsTest, VectorGep) {
461442 LLVMContext C;
462443
463444 // Type Definitions
464- Type *I8Ty = IntegerType::get (C, 8 );
465445 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 );
471448
472449 // Test different aspects of the vector-of-pointers type
473450 // and GEPs which use this type.
@@ -478,8 +455,8 @@ TEST(InstructionsTest, VectorGep) {
478455 Constant *C2xi32a = ConstantVector::get (ConstVa);
479456 Constant *C2xi32b = ConstantVector::get (ConstVb);
480457
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 );
483460
484461 ICmpInst *ICmp0 = new ICmpInst (ICmpInst::ICMP_SGT, PtrVecA, PtrVecB);
485462 ICmpInst *ICmp1 = new ICmpInst (ICmpInst::ICMP_ULT, PtrVecA, PtrVecB);
@@ -495,10 +472,10 @@ TEST(InstructionsTest, VectorGep) {
495472 GetElementPtrInst *Gep2 = GetElementPtrInst::Create (I32Ty, PtrVecB, C2xi32a);
496473 GetElementPtrInst *Gep3 = GetElementPtrInst::Create (I32Ty, PtrVecB, C2xi32b);
497474
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 );
502479
503480 Value *S0 = BTC0->stripPointerCasts ();
504481 Value *S1 = BTC1->stripPointerCasts ();
0 commit comments