@@ -13,11 +13,13 @@ using namespace llvm;
1313namespace {
1414
1515struct AddrMode : public TargetLowering ::AddrMode {
16- constexpr AddrMode (GlobalValue *GV, int64_t Offs, bool HasBase, int64_t S) {
16+ constexpr AddrMode (GlobalValue *GV, int64_t Offs, bool HasBase, int64_t S,
17+ int64_t SOffs = 0 ) {
1718 BaseGV = GV;
1819 BaseOffs = Offs;
1920 HasBaseReg = HasBase;
2021 Scale = S;
22+ ScalableOffset = SOffs;
2123 }
2224};
2325struct TestCase {
@@ -153,6 +155,45 @@ const std::initializer_list<TestCase> Tests = {
153155 {{nullptr , 4096 + 1 , true , 0 }, 8 , false },
154156
155157};
158+
159+ struct SVETestCase {
160+ AddrMode AM;
161+ unsigned TypeBits;
162+ unsigned NumElts;
163+ bool Result;
164+ };
165+
166+ const std::initializer_list<SVETestCase> SVETests = {
167+ // {BaseGV, BaseOffs, HasBaseReg, Scale, SOffs}, EltBits, Count, Result
168+ // Test immediate range -- [-8,7] vector's worth.
169+ // <vscale x 16 x i8>, increment by one vector
170+ {{nullptr , 0 , true , 0 , 16 }, 8 , 16 , true },
171+ // <vscale x 4 x i32>, increment by eight vectors
172+ {{nullptr , 0 , true , 0 , 128 }, 32 , 4 , false },
173+ // <vscale x 8 x i16>, increment by seven vectors
174+ {{nullptr , 0 , true , 0 , 112 }, 16 , 8 , true },
175+ // <vscale x 2 x i64>, decrement by eight vectors
176+ {{nullptr , 0 , true , 0 , -128 }, 64 , 2 , true },
177+ // <vscale x 16 x i8>, decrement by nine vectors
178+ {{nullptr , 0 , true , 0 , -144 }, 8 , 16 , false },
179+
180+ // Half the size of a vector register, but allowable with extending
181+ // loads and truncating stores
182+ // <vscale x 8 x i8>, increment by three vectors
183+ {{nullptr , 0 , true , 0 , 24 }, 8 , 8 , true },
184+
185+ // Test invalid types or offsets
186+ // <vscale x 5 x i32>, increment by one vector (base size > 16B)
187+ {{nullptr , 0 , true , 0 , 20 }, 32 , 5 , false },
188+ // <vscale x 8 x i16>, increment by half a vector
189+ {{nullptr , 0 , true , 0 , 8 }, 16 , 8 , false },
190+ // <vscale x 3 x i8>, increment by 3 vectors (non-power-of-two)
191+ {{nullptr , 0 , true , 0 , 9 }, 8 , 3 , false },
192+
193+ // Scalable and fixed offsets
194+ // <vscale x 16 x i8>, increment by 32 then decrement by vscale x 16
195+ {{nullptr , 32 , true , 0 , -16 }, 8 , 16 , false },
196+ };
156197} // namespace
157198
158199TEST (AddressingModes, AddressingModes) {
@@ -179,4 +220,11 @@ TEST(AddressingModes, AddressingModes) {
179220 Type *Typ = Type::getIntNTy (Ctx, Test.TypeBits );
180221 ASSERT_EQ (TLI->isLegalAddressingMode (DL, Test.AM , Typ, 0 ), Test.Result );
181222 }
223+
224+ for (const auto &SVETest : SVETests) {
225+ Type *Ty = VectorType::get (Type::getIntNTy (Ctx, SVETest.TypeBits ),
226+ ElementCount::getScalable (SVETest.NumElts ));
227+ ASSERT_EQ (TLI->isLegalAddressingMode (DL, SVETest.AM , Ty, 0 ),
228+ SVETest.Result );
229+ }
182230}
0 commit comments