diff options
author | Momchil Velikov <momchil.velikov@arm.com> | 2023-03-30 13:31:45 +0100 |
---|---|---|
committer | Momchil Velikov <momchil.velikov@arm.com> | 2023-03-30 14:18:14 +0100 |
commit | 2453da0a4e606c8dc75ed9cae0534b0c87ba77b9 (patch) | |
tree | 71f5b9999783abab22667665a408aa9bf957a8b1 /llvm/lib/CodeGen/CodeGenPrepare.cpp | |
parent | 18fe66396906178872dd933a39e38779a5a3c722 (diff) | |
download | llvm-2453da0a4e606c8dc75ed9cae0534b0c87ba77b9.zip llvm-2453da0a4e606c8dc75ed9cae0534b0c87ba77b9.tar.gz llvm-2453da0a4e606c8dc75ed9cae0534b0c87ba77b9.tar.bz2 |
[CodeGenPrepare] Fix counting uses when folding addresses into memory instructions
The counter of the number of instructions seen in `FindAllMemoryUses`
is reset after returning from a recursive invocation of
`FindAllMemoryUses` to the value it had before the call. In effect,
depending on the shape of the uses graph, the function may scan up to
`2^N-1` instructions where `N` is the scan limit
(`MaxMemoryUsesToScan`). This does not look intuitive or intended.
This patch changes the counting to just count the scanned
instructions, independent of the shape of the references.
Reviewed By: mkazantsev
Differential Revision: https://reviews.llvm.org/D143893
Change-Id: I99f5de55e84843cf2fbea287d6ae4312fa196240
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r-- | llvm/lib/CodeGen/CodeGenPrepare.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index ddbba80..db3aa72 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -4972,7 +4972,7 @@ static bool FindAllMemoryUses( Instruction *I, SmallVectorImpl<std::pair<Value *, Type *>> &MemoryUses, SmallPtrSetImpl<Instruction *> &ConsideredInsts, const TargetLowering &TLI, const TargetRegisterInfo &TRI, bool OptSize, ProfileSummaryInfo *PSI, - BlockFrequencyInfo *BFI, int SeenInsts = 0) { + BlockFrequencyInfo *BFI, int &SeenInsts) { // If we already considered this instruction, we're done. if (!ConsideredInsts.insert(I).second) return false; @@ -5043,6 +5043,17 @@ static bool FindAllMemoryUses( return false; } +static bool FindAllMemoryUses( + Instruction *I, SmallVectorImpl<std::pair<Value *, Type *>> &MemoryUses, + const TargetLowering &TLI, const TargetRegisterInfo &TRI, bool OptSize, + ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI) { + int SeenInsts = 0; + SmallPtrSet<Instruction *, 16> ConsideredInsts; + return FindAllMemoryUses(I, MemoryUses, ConsideredInsts, TLI, TRI, OptSize, + PSI, BFI, SeenInsts); +} + + /// Return true if Val is already known to be live at the use site that we're /// folding it into. If so, there is no cost to include it in the addressing /// mode. KnownLive1 and KnownLive2 are two values that we know are live at the @@ -5125,9 +5136,7 @@ bool AddressingModeMatcher::isProfitableToFoldIntoAddressingMode( // for another (at worst.) In this context, folding an addressing mode into // the use is just a particularly nice way of sinking it. SmallVector<std::pair<Value *, Type *>, 16> MemoryUses; - SmallPtrSet<Instruction *, 16> ConsideredInsts; - if (FindAllMemoryUses(I, MemoryUses, ConsideredInsts, TLI, TRI, OptSize, PSI, - BFI)) + if (FindAllMemoryUses(I, MemoryUses, TLI, TRI, OptSize, PSI, BFI)) return false; // Has a non-memory, non-foldable use! // Now that we know that all uses of this instruction are part of a chain of |