7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " llvm/Transforms/Vectorize/SandboxVectorizer/SeedCollector.h"
10
+ #include " llvm/Analysis/AliasAnalysis.h"
11
+ #include " llvm/Analysis/AssumptionCache.h"
12
+ #include " llvm/Analysis/BasicAliasAnalysis.h"
13
+ #include " llvm/Analysis/LoopInfo.h"
14
+ #include " llvm/Analysis/TargetLibraryInfo.h"
10
15
#include " llvm/AsmParser/Parser.h"
16
+ #include " llvm/IR/Dominators.h"
11
17
#include " llvm/SandboxIR/Function.h"
12
18
#include " llvm/SandboxIR/Instruction.h"
13
19
#include " llvm/Support/SourceMgr.h"
@@ -26,6 +32,12 @@ struct SeedBundleTest : public testing::Test {
26
32
if (!M)
27
33
Err.print (" LegalityTest" , errs ());
28
34
}
35
+ BasicBlock *getBasicBlockByName (Function &F, StringRef Name) {
36
+ for (BasicBlock &BB : F)
37
+ if (BB.getName () == Name)
38
+ return &BB;
39
+ llvm_unreachable (" Expected to find basic block!" );
40
+ }
29
41
};
30
42
31
43
TEST_F (SeedBundleTest, SeedBundle) {
@@ -123,3 +135,64 @@ define void @foo(float %v0, i32 %i0, i16 %i1, i8 %i2) {
123
135
/* ForcePowerOf2 */ true );
124
136
EXPECT_EQ (Slice4.size (), 0u );
125
137
}
138
+
139
+ TEST_F (SeedBundleTest, MemSeedBundle) {
140
+ parseIR (C, R"IR(
141
+ define void @foo(ptr %ptrA, float %val, ptr %ptr) {
142
+ bb:
143
+ %gep0 = getelementptr float, ptr %ptr, i32 0
144
+ %gep1 = getelementptr float, ptr %ptr, i32 1
145
+ %gep2 = getelementptr float, ptr %ptr, i32 3
146
+ %gep3 = getelementptr float, ptr %ptr, i32 4
147
+ store float %val, ptr %gep0
148
+ store float %val, ptr %gep1
149
+ store float %val, ptr %gep2
150
+ store float %val, ptr %gep3
151
+
152
+ load float, ptr %gep0
153
+ load float, ptr %gep1
154
+ load float, ptr %gep2
155
+ load float, ptr %gep3
156
+
157
+ ret void
158
+ }
159
+ )IR" );
160
+ Function &LLVMF = *M->getFunction (" foo" );
161
+
162
+ DominatorTree DT (LLVMF);
163
+ TargetLibraryInfoImpl TLII;
164
+ TargetLibraryInfo TLI (TLII);
165
+ DataLayout DL (M->getDataLayout ());
166
+ LoopInfo LI (DT);
167
+ AssumptionCache AC (LLVMF);
168
+ ScalarEvolution SE (LLVMF, TLI, AC, DT, LI);
169
+
170
+ sandboxir::Context Ctx (C);
171
+ auto &F = *Ctx.createFunction (&LLVMF);
172
+ auto *BB = &*F.begin ();
173
+ auto It = std::next (BB->begin (), 4 );
174
+ auto *S0 = cast<sandboxir::StoreInst>(&*It++);
175
+ auto *S1 = cast<sandboxir::StoreInst>(&*It++);
176
+ auto *S2 = cast<sandboxir::StoreInst>(&*It++);
177
+ auto *S3 = cast<sandboxir::StoreInst>(&*It++);
178
+
179
+ // Single instruction constructor; test insert out of memory order
180
+ sandboxir::StoreSeedBundle SB (S3);
181
+ SB.insert (S1, SE);
182
+ SB.insert (S2, SE);
183
+ SB.insert (S0, SE);
184
+ EXPECT_THAT (SB, testing::ElementsAre (S0, S1, S2, S3));
185
+
186
+ // Instruction list constructor; test list out of order
187
+ auto *L0 = cast<sandboxir::LoadInst>(&*It++);
188
+ auto *L1 = cast<sandboxir::LoadInst>(&*It++);
189
+ auto *L2 = cast<sandboxir::LoadInst>(&*It++);
190
+ auto *L3 = cast<sandboxir::LoadInst>(&*It++);
191
+ SmallVector<sandboxir::Instruction *> Loads;
192
+ Loads.push_back (L1);
193
+ Loads.push_back (L3);
194
+ Loads.push_back (L2);
195
+ Loads.push_back (L0);
196
+ sandboxir::LoadSeedBundle LB (std::move (Loads), SE);
197
+ EXPECT_THAT (LB, testing::ElementsAre (L0, L1, L2, L3));
198
+ }
0 commit comments