[llvm] ed76074 - [LICM] Remove custom isInstInList() implementation (PR59324)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 7 00:51:42 PST 2022
Author: Nikita Popov
Date: 2022-12-07T09:51:35+01:00
New Revision: ed7607417371929c2c3c390c66ea48e908c4d0fa
URL: https://github.com/llvm/llvm-project/commit/ed7607417371929c2c3c390c66ea48e908c4d0fa
DIFF: https://github.com/llvm/llvm-project/commit/ed7607417371929c2c3c390c66ea48e908c4d0fa.diff
LOG: [LICM] Remove custom isInstInList() implementation (PR59324)
We already collect all instructions that need to be promoted. The
custom isInstInList() implementation could provide incorrect
results if a new use of the original pointer was introduced as
part of promotion. This probably cannot happen with normal code,
because of the pointer capture, but it can happen with a null
pointer.
Fixes https://github.com/llvm/llvm-project/issues/59324.
Added:
llvm/test/Transforms/LICM/pr59324.ll
Modified:
llvm/lib/Transforms/Scalar/LICM.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index 4f8bdda413a6f..8a359f80573cf 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -1775,7 +1775,6 @@ static bool isSafeToExecuteUnconditionally(
namespace {
class LoopPromoter : public LoadAndStorePromoter {
Value *SomePtr; // Designated pointer to store to.
- const SmallSetVector<Value *, 8> &PointerMustAliases;
SmallVectorImpl<BasicBlock *> &LoopExitBlocks;
SmallVectorImpl<Instruction *> &LoopInsertPts;
SmallVectorImpl<MemoryAccess *> &MSSAInsertPts;
@@ -1809,30 +1808,19 @@ class LoopPromoter : public LoadAndStorePromoter {
public:
LoopPromoter(Value *SP, ArrayRef<const Instruction *> Insts, SSAUpdater &S,
- const SmallSetVector<Value *, 8> &PMA,
SmallVectorImpl<BasicBlock *> &LEB,
SmallVectorImpl<Instruction *> &LIP,
SmallVectorImpl<MemoryAccess *> &MSSAIP, PredIteratorCache &PIC,
MemorySSAUpdater &MSSAU, LoopInfo &li, DebugLoc dl,
Align Alignment, bool UnorderedAtomic, const AAMDNodes &AATags,
ICFLoopSafetyInfo &SafetyInfo, bool CanInsertStoresInExitBlocks)
- : LoadAndStorePromoter(Insts, S), SomePtr(SP), PointerMustAliases(PMA),
- LoopExitBlocks(LEB), LoopInsertPts(LIP), MSSAInsertPts(MSSAIP),
- PredCache(PIC), MSSAU(MSSAU), LI(li), DL(std::move(dl)),
- Alignment(Alignment), UnorderedAtomic(UnorderedAtomic), AATags(AATags),
+ : LoadAndStorePromoter(Insts, S), SomePtr(SP), LoopExitBlocks(LEB),
+ LoopInsertPts(LIP), MSSAInsertPts(MSSAIP), PredCache(PIC), MSSAU(MSSAU),
+ LI(li), DL(std::move(dl)), Alignment(Alignment),
+ UnorderedAtomic(UnorderedAtomic), AATags(AATags),
SafetyInfo(SafetyInfo),
CanInsertStoresInExitBlocks(CanInsertStoresInExitBlocks), Uses(Insts) {}
- bool isInstInList(Instruction *I,
- const SmallVectorImpl<Instruction *> &) const override {
- Value *Ptr;
- if (LoadInst *LI = dyn_cast<LoadInst>(I))
- Ptr = LI->getOperand(0);
- else
- Ptr = cast<StoreInst>(I)->getPointerOperand();
- return PointerMustAliases.count(Ptr);
- }
-
void insertStoresInLoopExitBlocks() {
// Insert stores after in the loop exit blocks. Each exit block gets a
// store of the live-out values that feed them. Since we've already told
@@ -2213,9 +2201,9 @@ bool llvm::promoteLoopAccessesToScalars(
// We use the SSAUpdater interface to insert phi nodes as required.
SmallVector<PHINode *, 16> NewPHIs;
SSAUpdater SSA(&NewPHIs);
- LoopPromoter Promoter(SomePtr, LoopUses, SSA, PointerMustAliases, ExitBlocks,
- InsertPts, MSSAInsertPts, PIC, MSSAU, *LI, DL,
- Alignment, SawUnorderedAtomic, AATags, *SafetyInfo,
+ LoopPromoter Promoter(SomePtr, LoopUses, SSA, ExitBlocks, InsertPts,
+ MSSAInsertPts, PIC, MSSAU, *LI, DL, Alignment,
+ SawUnorderedAtomic, AATags, *SafetyInfo,
StoreSafety == StoreSafe);
// Set up the preheader to have a definition of the value. It is the live-out
diff --git a/llvm/test/Transforms/LICM/pr59324.ll b/llvm/test/Transforms/LICM/pr59324.ll
new file mode 100644
index 0000000000000..b0ad60e650696
--- /dev/null
+++ b/llvm/test/Transforms/LICM/pr59324.ll
@@ -0,0 +1,21 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -passes=licm < %s | FileCheck %s
+
+define void @test(ptr %a) {
+; CHECK-LABEL: @test(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[LOOP:%.*]]
+; CHECK: loop:
+; CHECK-NEXT: [[V:%.*]] = load i32, ptr null, align 4
+; CHECK-NEXT: br label [[LOOP]]
+;
+entry:
+ br label %loop
+
+loop:
+ store ptr null, ptr null
+ %p = load ptr, ptr null
+ %v = load i32, ptr %p
+ store i32 %v, ptr %a
+ br label %loop
+}
More information about the llvm-commits
mailing list