Skip to content

Commit 6d636d8

Browse files
committed
[IR][unittests] Deduplicate pointer tests
A lot of the old tests test the same thing twice because pointers are opaque. This removes the deduplication
1 parent 1a8637a commit 6d636d8

File tree

2 files changed

+71
-95
lines changed

2 files changed

+71
-95
lines changed

llvm/unittests/FuzzMutate/RandomIRBuilderTest.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,26 +323,24 @@ TEST(RandomIRBuilderTest, createStackMemory) {
323323
Type *DoubleTy = Type::getDoubleTy(Ctx);
324324
Constant *Double_0 =
325325
ConstantFP::get(Ctx, APFloat::getZero(DoubleTy->getFltSemantics()));
326-
std::array<Type *, 8> Types = {
326+
std::array<Type *, 7> Types = {
327327
Int32Ty,
328328
Int64Ty,
329329
DoubleTy,
330330
PointerType::get(Ctx, 0),
331-
PointerType::get(Ctx, 0),
332331
VectorType::get(Int32Ty, 4, false),
333332
StructType::create({Int32Ty, DoubleTy, Int64Ty}),
334333
ArrayType::get(Int64Ty, 4),
335334
};
336-
std::array<Value *, 8> Inits = {
335+
std::array<Value *, 7> Inits = {
337336
Int32_1,
338337
Int64_42,
339338
Double_0,
340339
UndefValue::get(Types[3]),
341-
UndefValue::get(Types[4]),
342340
ConstantVector::get({Int32_1, Int32_1, Int32_1, Int32_1}),
343-
ConstantStruct::get(cast<StructType>(Types[6]),
341+
ConstantStruct::get(cast<StructType>(Types[5]),
344342
{Int32_1, Double_0, Int64_42}),
345-
ConstantArray::get(cast<ArrayType>(Types[7]),
343+
ConstantArray::get(cast<ArrayType>(Types[6]),
346344
{Int64_42, Int64_42, Int64_42, Int64_42}),
347345
};
348346
ASSERT_EQ(Types.size(), Inits.size());

llvm/unittests/IR/InstructionsTest.cpp

Lines changed: 67 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -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(C, 0);
224-
Type *Int64PtrTy = PointerType::get(C, 0);
225-
226-
Type *Int32PtrAS1Ty = PointerType::get(C, 1);
227-
Type *Int64PtrAS1Ty = PointerType::get(C, 1);
223+
Type *PtrTy = PointerType::get(C, 0);
224+
Type *PtrAS1Ty = PointerType::get(C, 1);
228225

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);
226+
Type *V2PtrAS1Ty = FixedVectorType::get(PtrAS1Ty, 2);
227+
Type *V4PtrAS1Ty = FixedVectorType::get(PtrAS1Ty, 4);
228+
Type *VScaleV4PtrAS1Ty = ScalableVectorType::get(PtrAS1Ty, 4);
234229

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,22 @@ 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(V2PtrTy, V2PtrTy));
257+
EXPECT_FALSE(CastInst::isBitCastable(V2PtrAS1Ty, V2PtrAS1Ty));
258+
EXPECT_FALSE(CastInst::isBitCastable(V2PtrAS1Ty, V4PtrAS1Ty));
259+
EXPECT_FALSE(CastInst::isBitCastable(PtrTy, V2PtrTy));
260+
EXPECT_FALSE(CastInst::isBitCastable(V2PtrTy, PtrTy));
269261

270-
EXPECT_TRUE(CastInst::isBitCastable(Int32PtrTy, Int64PtrTy));
262+
EXPECT_TRUE(CastInst::isBitCastable(PtrTy, PtrTy));
271263
EXPECT_FALSE(CastInst::isBitCastable(DoubleTy, FloatTy));
272264
EXPECT_FALSE(CastInst::isBitCastable(FloatTy, DoubleTy));
273265
EXPECT_TRUE(CastInst::isBitCastable(FloatTy, FloatTy));
@@ -281,55 +273,48 @@ TEST(InstructionsTest, CastInst) {
281273
EXPECT_FALSE(CastInst::isBitCastable(Int32Ty, Int64Ty));
282274
EXPECT_FALSE(CastInst::isBitCastable(Int64Ty, Int32Ty));
283275

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));
276+
EXPECT_FALSE(CastInst::isBitCastable(V2PtrTy, Int64Ty));
277+
EXPECT_FALSE(CastInst::isBitCastable(Int64Ty, V2PtrTy));
288278
EXPECT_FALSE(CastInst::isBitCastable(V2Int32Ty, V2Int64Ty));
289279
EXPECT_FALSE(CastInst::isBitCastable(V2Int64Ty, V2Int32Ty));
290280

291-
292281
EXPECT_FALSE(CastInst::castIsValid(Instruction::BitCast,
293-
Constant::getNullValue(V4Int32PtrTy),
294-
V2Int32PtrTy));
282+
Constant::getNullValue(V4PtrTy), V2PtrTy));
295283
EXPECT_FALSE(CastInst::castIsValid(Instruction::BitCast,
296-
Constant::getNullValue(V2Int32PtrTy),
297-
V4Int32PtrTy));
284+
Constant::getNullValue(V2PtrTy), V4PtrTy));
298285

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));
286+
EXPECT_FALSE(CastInst::castIsValid(
287+
Instruction::AddrSpaceCast, Constant::getNullValue(V4PtrAS1Ty), V2PtrTy));
288+
EXPECT_FALSE(CastInst::castIsValid(
289+
Instruction::AddrSpaceCast, Constant::getNullValue(V2PtrTy), V4PtrAS1Ty));
305290

306291
// Address space cast of fixed/scalable vectors of pointers to scalable/fixed
307292
// vector of pointers.
308-
EXPECT_FALSE(CastInst::castIsValid(
309-
Instruction::AddrSpaceCast, Constant::getNullValue(VScaleV4Int32PtrAS1Ty),
310-
V4Int32PtrTy));
311293
EXPECT_FALSE(CastInst::castIsValid(Instruction::AddrSpaceCast,
312-
Constant::getNullValue(V4Int32PtrTy),
313-
VScaleV4Int32PtrAS1Ty));
294+
Constant::getNullValue(VScaleV4PtrAS1Ty),
295+
V4PtrTy));
296+
EXPECT_FALSE(CastInst::castIsValid(Instruction::AddrSpaceCast,
297+
Constant::getNullValue(V4PtrTy),
298+
VScaleV4PtrAS1Ty));
314299
// Address space cast of scalable vectors of pointers to scalable vector of
315300
// pointers.
316-
EXPECT_FALSE(CastInst::castIsValid(
317-
Instruction::AddrSpaceCast, Constant::getNullValue(VScaleV4Int32PtrAS1Ty),
318-
VScaleV2Int32PtrTy));
319301
EXPECT_FALSE(CastInst::castIsValid(Instruction::AddrSpaceCast,
320-
Constant::getNullValue(VScaleV2Int32PtrTy),
321-
VScaleV4Int32PtrAS1Ty));
302+
Constant::getNullValue(VScaleV4PtrAS1Ty),
303+
VScaleV2PtrTy));
304+
EXPECT_FALSE(CastInst::castIsValid(Instruction::AddrSpaceCast,
305+
Constant::getNullValue(VScaleV2PtrTy),
306+
VScaleV4PtrAS1Ty));
322307
EXPECT_TRUE(CastInst::castIsValid(Instruction::AddrSpaceCast,
323-
Constant::getNullValue(VScaleV4Int64PtrTy),
324-
VScaleV4Int32PtrAS1Ty));
308+
Constant::getNullValue(VScaleV4PtrTy),
309+
VScaleV4PtrAS1Ty));
325310
// Same number of lanes, different address space.
326-
EXPECT_TRUE(CastInst::castIsValid(
327-
Instruction::AddrSpaceCast, Constant::getNullValue(VScaleV4Int32PtrAS1Ty),
328-
VScaleV4Int32PtrTy));
311+
EXPECT_TRUE(CastInst::castIsValid(Instruction::AddrSpaceCast,
312+
Constant::getNullValue(VScaleV4PtrAS1Ty),
313+
VScaleV4PtrTy));
329314
// Same number of lanes, same address space.
330315
EXPECT_FALSE(CastInst::castIsValid(Instruction::AddrSpaceCast,
331-
Constant::getNullValue(VScaleV4Int64PtrTy),
332-
VScaleV4Int32PtrTy));
316+
Constant::getNullValue(VScaleV4PtrTy),
317+
VScaleV4PtrTy));
333318

334319
// Bit casting fixed/scalable vector to scalable/fixed vectors.
335320
EXPECT_FALSE(CastInst::castIsValid(Instruction::BitCast,
@@ -377,10 +362,10 @@ TEST(InstructionsTest, CastInst) {
377362
// pointers
378363
// First form
379364
BasicBlock *BB = BasicBlock::Create(C);
380-
Constant *NullV2I32Ptr = Constant::getNullValue(V2Int32PtrTy);
365+
Constant *NullV2I32Ptr = Constant::getNullValue(V2PtrTy);
381366
auto Inst1 = CastInst::CreatePointerCast(NullV2I32Ptr, V2Int32Ty, "foo", BB);
382367

383-
Constant *NullVScaleV2I32Ptr = Constant::getNullValue(VScaleV2Int32PtrTy);
368+
Constant *NullVScaleV2I32Ptr = Constant::getNullValue(VScaleV2PtrTy);
384369
auto Inst1VScale = CastInst::CreatePointerCast(
385370
NullVScaleV2I32Ptr, VScaleV2Int32Ty, "foo.vscale", BB);
386371

@@ -400,14 +385,12 @@ TEST(InstructionsTest, CastCAPI) {
400385
LLVMContext C;
401386

402387
Type *Int8Ty = Type::getInt8Ty(C);
403-
Type *Int32Ty = Type::getInt32Ty(C);
404388
Type *Int64Ty = Type::getInt64Ty(C);
405389

406390
Type *FloatTy = Type::getFloatTy(C);
407391
Type *DoubleTy = Type::getDoubleTy(C);
408392

409-
Type *Int8PtrTy = PointerType::get(C, 0);
410-
Type *Int32PtrTy = PointerType::get(C, 0);
393+
Type *PtrTy = PointerType::get(C, 0);
411394

412395
const Constant *C8 = Constant::getNullValue(Int8Ty);
413396
const Constant *C64 = Constant::getNullValue(Int64Ty);
@@ -433,12 +416,11 @@ TEST(InstructionsTest, CastCAPI) {
433416
EXPECT_EQ(LLVMFPExt,
434417
LLVMGetCastOpcode(wrap(CF32), true, wrap(DoubleTy), true));
435418

436-
const Constant *CPtr8 = Constant::getNullValue(Int8PtrTy);
419+
const Constant *CPtr8 = Constant::getNullValue(PtrTy);
437420

438421
EXPECT_EQ(LLVMPtrToInt,
439422
LLVMGetCastOpcode(wrap(CPtr8), true, wrap(Int8Ty), true));
440-
EXPECT_EQ(LLVMIntToPtr,
441-
LLVMGetCastOpcode(wrap(C8), true, wrap(Int8PtrTy), true));
423+
EXPECT_EQ(LLVMIntToPtr, LLVMGetCastOpcode(wrap(C8), true, wrap(PtrTy), true));
442424

443425
Type *V8x8Ty = FixedVectorType::get(Int8Ty, 8);
444426
Type *V8x64Ty = FixedVectorType::get(Int64Ty, 8);
@@ -448,26 +430,22 @@ TEST(InstructionsTest, CastCAPI) {
448430
EXPECT_EQ(LLVMTrunc, LLVMGetCastOpcode(wrap(CV64), true, wrap(V8x8Ty), true));
449431
EXPECT_EQ(LLVMSExt, LLVMGetCastOpcode(wrap(CV8), true, wrap(V8x64Ty), true));
450432

451-
Type *Int32PtrAS1Ty = PointerType::get(C, 1);
452-
Type *V2Int32PtrAS1Ty = FixedVectorType::get(Int32PtrAS1Ty, 2);
453-
Type *V2Int32PtrTy = FixedVectorType::get(Int32PtrTy, 2);
454-
const Constant *CV2ptr32 = Constant::getNullValue(V2Int32PtrTy);
433+
Type *PtrAS1Ty = PointerType::get(C, 1);
434+
Type *V2PtrAS1Ty = FixedVectorType::get(PtrAS1Ty, 2);
435+
Type *V2PtrTy = FixedVectorType::get(PtrTy, 2);
436+
const Constant *CV2Ptr = Constant::getNullValue(V2PtrTy);
455437

456-
EXPECT_EQ(LLVMAddrSpaceCast, LLVMGetCastOpcode(wrap(CV2ptr32), true,
457-
wrap(V2Int32PtrAS1Ty), true));
438+
EXPECT_EQ(LLVMAddrSpaceCast,
439+
LLVMGetCastOpcode(wrap(CV2Ptr), true, wrap(V2PtrAS1Ty), true));
458440
}
459441

460442
TEST(InstructionsTest, VectorGep) {
461443
LLVMContext C;
462444

463445
// Type Definitions
464-
Type *I8Ty = IntegerType::get(C, 8);
465446
Type *I32Ty = IntegerType::get(C, 32);
466-
PointerType *Ptri8Ty = PointerType::get(C, 0);
467-
PointerType *Ptri32Ty = PointerType::get(C, 0);
468-
469-
VectorType *V2xi8PTy = FixedVectorType::get(Ptri8Ty, 2);
470-
VectorType *V2xi32PTy = FixedVectorType::get(Ptri32Ty, 2);
447+
PointerType *PtrTy = PointerType::get(C, 0);
448+
VectorType *V2xPTy = FixedVectorType::get(PtrTy, 2);
471449

472450
// Test different aspects of the vector-of-pointers type
473451
// and GEPs which use this type.
@@ -478,8 +456,8 @@ TEST(InstructionsTest, VectorGep) {
478456
Constant *C2xi32a = ConstantVector::get(ConstVa);
479457
Constant *C2xi32b = ConstantVector::get(ConstVb);
480458

481-
CastInst *PtrVecA = new IntToPtrInst(C2xi32a, V2xi32PTy);
482-
CastInst *PtrVecB = new IntToPtrInst(C2xi32b, V2xi32PTy);
459+
CastInst *PtrVecA = new IntToPtrInst(C2xi32a, V2xPTy);
460+
CastInst *PtrVecB = new IntToPtrInst(C2xi32b, V2xPTy);
483461

484462
ICmpInst *ICmp0 = new ICmpInst(ICmpInst::ICMP_SGT, PtrVecA, PtrVecB);
485463
ICmpInst *ICmp1 = new ICmpInst(ICmpInst::ICMP_ULT, PtrVecA, PtrVecB);
@@ -495,10 +473,10 @@ TEST(InstructionsTest, VectorGep) {
495473
GetElementPtrInst *Gep2 = GetElementPtrInst::Create(I32Ty, PtrVecB, C2xi32a);
496474
GetElementPtrInst *Gep3 = GetElementPtrInst::Create(I32Ty, PtrVecB, C2xi32b);
497475

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);
476+
CastInst *BTC0 = new BitCastInst(Gep0, V2xPTy);
477+
CastInst *BTC1 = new BitCastInst(Gep1, V2xPTy);
478+
CastInst *BTC2 = new BitCastInst(Gep2, V2xPTy);
479+
CastInst *BTC3 = new BitCastInst(Gep3, V2xPTy);
502480

503481
Value *S0 = BTC0->stripPointerCasts();
504482
Value *S1 = BTC1->stripPointerCasts();

0 commit comments

Comments
 (0)