Skip to content

Commit c0ee8e2

Browse files
[SandboxVec][SeedCollector] Reject non-simple memory ops for memory seeds (#116891)
Load/Store isSimple is a necessary condition for VectorSeeds, but not sufficient, so reverse the condition and return value, and continue the check. Add relevant tests.
1 parent 77ee94e commit c0ee8e2

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

llvm/lib/Transforms/Vectorize/SandboxVectorizer/SeedCollector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ LLVM_DUMP_METHOD void SeedContainer::dump() const { print(dbgs()); }
140140
#endif // NDEBUG
141141

142142
template <typename LoadOrStoreT> static bool isValidMemSeed(LoadOrStoreT *LSI) {
143-
if (LSI->isSimple())
144-
return true;
143+
if (!LSI->isSimple())
144+
return false;
145145
auto *Ty = Utils::getExpectedType(LSI);
146146
// Omit types that are architecturally unvectorizable
147147
if (Ty->isX86_FP80Ty() || Ty->isPPC_FP128Ty())

llvm/unittests/Transforms/Vectorize/SandboxVectorizer/SeedCollectorTest.cpp

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,16 @@ define void @foo(ptr noalias %ptr, float %val) {
394394

395395
TEST_F(SeedBundleTest, VectorStores) {
396396
parseIR(C, R"IR(
397-
define void @foo(ptr noalias %ptr, <2 x float> %val) {
397+
define void @foo(ptr noalias %ptr, <2 x float> %val0, i64 %val1) {
398398
bb:
399399
%ptr0 = getelementptr float, ptr %ptr, i32 0
400400
%ptr1 = getelementptr float, ptr %ptr, i32 1
401-
store <2 x float> %val, ptr %ptr1
402-
store <2 x float> %val, ptr %ptr0
401+
%ptr2 = getelementptr i64, ptr %ptr, i32 2
402+
store <2 x float> %val0, ptr %ptr1
403+
store <2 x float> %val0, ptr %ptr0
404+
store atomic i64 %val1, ptr %ptr2 unordered, align 8
405+
store volatile i64 %val1, ptr %ptr2
406+
403407
ret void
404408
}
405409
)IR");
@@ -418,14 +422,16 @@ define void @foo(ptr noalias %ptr, <2 x float> %val) {
418422
sandboxir::SeedCollector SC(&*BB, SE);
419423

420424
// Find the stores
421-
auto It = std::next(BB->begin(), 2);
425+
auto It = std::next(BB->begin(), 3);
422426
// StX with X as the order by offset in memory
423427
auto *St1 = &*It++;
424428
auto *St0 = &*It++;
425429

426430
auto StoreSeedsRange = SC.getStoreSeeds();
427431
EXPECT_EQ(range_size(StoreSeedsRange), 1u);
428432
auto &SB = *StoreSeedsRange.begin();
433+
// isValidMemSeed check: The atomic and volatile stores should not
434+
// be included in the bundle, but the vector stores should be.
429435
ExpectThatElementsAre(SB, {St0, St1});
430436
}
431437

@@ -466,5 +472,50 @@ define void @foo(ptr noalias %ptr, float %v, <2 x float> %val) {
466472
auto StoreSeedsRange = SC.getStoreSeeds();
467473
EXPECT_EQ(range_size(StoreSeedsRange), 1u);
468474
auto &SB = *StoreSeedsRange.begin();
475+
// isValidMemSeedCheck here: all of the three stores should be included.
469476
ExpectThatElementsAre(SB, {St0, St1, St3});
470477
}
478+
479+
TEST_F(SeedBundleTest, VectorLoads) {
480+
parseIR(C, R"IR(
481+
define void @foo(ptr noalias %ptr, <2 x float> %val0) {
482+
bb:
483+
%ptr0 = getelementptr float, ptr %ptr, i32 0
484+
%ptr1 = getelementptr float, ptr %ptr, i32 1
485+
%r0 = load <2 x float>, ptr %ptr0
486+
%r1 = load <2 x float>, ptr %ptr1
487+
%r2 = load atomic i64, ptr %ptr0 unordered, align 8
488+
%r3 = load volatile i64, ptr %ptr1
489+
%r4 = load void()*, ptr %ptr1
490+
491+
ret void
492+
}
493+
)IR");
494+
Function &LLVMF = *M->getFunction("foo");
495+
DominatorTree DT(LLVMF);
496+
TargetLibraryInfoImpl TLII;
497+
TargetLibraryInfo TLI(TLII);
498+
DataLayout DL(M->getDataLayout());
499+
LoopInfo LI(DT);
500+
AssumptionCache AC(LLVMF);
501+
ScalarEvolution SE(LLVMF, TLI, AC, DT, LI);
502+
503+
sandboxir::Context Ctx(C);
504+
auto &F = *Ctx.createFunction(&LLVMF);
505+
auto BB = F.begin();
506+
sandboxir::SeedCollector SC(&*BB, SE);
507+
508+
// Find the loads
509+
auto It = std::next(BB->begin(), 2);
510+
// StX with X as the order by offset in memory
511+
auto *Ld0 = cast<sandboxir::LoadInst>(&*It++);
512+
auto *Ld1 = cast<sandboxir::LoadInst>(&*It++);
513+
514+
auto LoadSeedsRange = SC.getLoadSeeds();
515+
EXPECT_EQ(range_size(LoadSeedsRange), 2u);
516+
auto &SB = *LoadSeedsRange.begin();
517+
// isValidMemSeed check: The atomic and volatile loads should not
518+
// be included in the bundle, the vector stores should be, but the
519+
// void-typed load should not.
520+
ExpectThatElementsAre(SB, {Ld0, Ld1});
521+
}

0 commit comments

Comments
 (0)