16TEST(GetElemenPtrOperationTests, typeChecks)
21 auto i32Type = BitType::Create(32);
31 auto & i32Import = GraphImport::Create(graph, i32Type,
"");
32 auto & i32FixedVectorImport = GraphImport::Create(graph, i32FixedVectorType,
"");
33 auto & i32ScalableVectorImport = GraphImport::Create(graph, i32ScalableVectorType,
"");
35 auto & pointerImport = GraphImport::Create(graph, pointerType,
"");
36 auto & ptrFixedVectorImport = GraphImport::Create(graph, ptrFixedVectorType,
"");
37 auto & ptrScalableVectorImport = GraphImport::Create(graph, ptrScalableVectorType,
"");
42 EXPECT_TRUE(is<PointerType>(gepNode.output(0)->Type()));
48 EXPECT_TRUE(is<FixedVectorType>(resultType));
49 EXPECT_TRUE(isVectorOf<PointerType>(*resultType));
55 EXPECT_TRUE(is<ScalableVectorType>(resultType));
56 EXPECT_TRUE(isVectorOf<PointerType>(*resultType));
66 EXPECT_TRUE(is<PointerType>(gepNode.output(0)->Type()));
74 EXPECT_TRUE(is<FixedVectorType>(resultType));
75 EXPECT_TRUE(isVectorOf<PointerType>(*resultType));
83 EXPECT_TRUE(is<ScalableVectorType>(resultType));
84 EXPECT_TRUE(isVectorOf<PointerType>(*resultType));
88TEST(GetElementPtrOperationTests, TestOperationEquality)
103 { BitType::Create(32), BitType::Create(32) },
108 { BitType::Create(32), BitType::Create(32) },
112 EXPECT_NE(operation1, operation2);
115 auto copyOfStructType1 =
119 { BitType::Create(32), BitType::Create(32) },
125 EXPECT_NE(structType1, copyOfStructType1);
127 EXPECT_EQ(*operation1, *operation3);
130TEST(GetElementPtrTests, TryGetAsConstantTest)
136 const auto bits8Type = BitType::Create(32);
137 const auto bits16Type = BitType::Create(32);
138 const auto bits32Type = BitType::Create(32);
146 auto & baseAddress = GraphImport::Create(rvsdg, pointerType,
"base");
147 auto & i32 = GraphImport::Create(rvsdg, bits8Type,
"i32");
154 { zeroNode.output(0), oneNode.output(0) },
168 EXPECT_TRUE(gepConstant0.has_value());
169 EXPECT_EQ(gepConstant0.value().pointeeType, structType);
170 EXPECT_EQ(gepConstant0.value().indices, std::vector<uint64_t>({ 0, 1 }));
172 EXPECT_FALSE(gepConstant1.has_value());
173 EXPECT_FALSE(gepConstant2.has_value());
176TEST(GetElementPtrTests, TestGetElementPtrOperationConstant_OffestInBytes)
182 const auto bits8Type = BitType::Create(32);
183 const auto bits16Type = BitType::Create(32);
184 const auto bits32Type = BitType::Create(32);
200 EXPECT_EQ(constant0.getOffsetInBytes(), 0u);
201 EXPECT_EQ(constant1.getOffsetInBytes(), 8u);
202 EXPECT_EQ(constant2.getOffsetInBytes(), 20u);
203 EXPECT_EQ(constant3.getOffsetInBytes(), 8u);
204 EXPECT_EQ(constant4.getOffsetInBytes(), 20u);
205 EXPECT_EQ(constant5.getOffsetInBytes(), 32u);
208TEST(GetElementPtrTests, normalizeIdempotentReduction)
213 auto i32Type = BitType::Create(32);
219 auto & pointerImport = GraphImport::Create(graph, pointerType,
"");
228 { zero.output(0), zero.output(0) },
233 { zero.output(0),
one.output(0) },
236 auto & x1 = GraphExport::Create(*gepNode1.output(0),
"x1");
237 auto & x2 = GraphExport::Create(*gepNode2.output(0),
"x2");
238 auto & x3 = GraphExport::Create(*gepNode3.output(0),
"x3");
249 EXPECT_EQ(x1.origin(), &pointerImport);
253 EXPECT_EQ(x2.origin(), &pointerImport);
257 EXPECT_FALSE(successReductionGepNode3);
258 auto [gepNode, gepOperation] =
259 TryGetSimpleNodeAndOptionalOp<GetElementPtrOperation>(*x3.origin());
260 EXPECT_NE(gepOperation,
nullptr);