diff options
| author | Florian Hahn <flo@fhahn.com> | 2024-05-04 20:53:53 +0100 |
|---|---|---|
| committer | Florian Hahn <flo@fhahn.com> | 2024-05-04 20:53:54 +0100 |
| commit | b54a78d69be1952884462cb897abb9cf60a33978 (patch) | |
| tree | 87c53e7e21500fd47d58c6d95cf83b5b10613c6c /llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp | |
| parent | 677dddebae77a93e080a98617aa2714be4a46fd0 (diff) | |
[LV,LAA] Don't vectorize loops with load and store to invar address.
Code checking stores to invariant addresses and reductions made an
incorrect assumption that the case of both a load & store to the same
invariant address does not need to be handled.
In some cases when vectorizing with runtime checks, there may be
dependences with a load and store to the same address, storing a
reduction value.
Update LAA to separately track if there was a store-store and a
load-store dependence with an invariant addresses.
Bail out early if there as a load-store dependence with invariant
address. If there was a store-store one, still apply the logic checking
if they all store a reduction.
Diffstat (limited to 'llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp index d33743e74cbe..9de49d1bcfea 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp @@ -1067,6 +1067,15 @@ bool LoopVectorizationLegality::canVectorizeMemory() { if (!LAI->canVectorizeMemory()) return false; + if (LAI->hasLoadStoreDependenceInvolvingLoopInvariantAddress()) { + reportVectorizationFailure("We don't allow storing to uniform addresses", + "write to a loop invariant address could not " + "be vectorized", + "CantVectorizeStoreToLoopInvariantAddress", ORE, + TheLoop); + return false; + } + // We can vectorize stores to invariant address when final reduction value is // guaranteed to be stored at the end of the loop. Also, if decision to // vectorize loop is made, runtime checks are added so as to make sure that @@ -1102,13 +1111,12 @@ bool LoopVectorizationLegality::canVectorizeMemory() { } } - if (LAI->hasDependenceInvolvingLoopInvariantAddress()) { + if (LAI->hasStoreStoreDependenceInvolvingLoopInvariantAddress()) { // For each invariant address, check its last stored value is the result // of one of our reductions. // - // We do not check if dependence with loads exists because they are - // currently rejected earlier in LoopAccessInfo::analyzeLoop. In case this - // behaviour changes we have to modify this code. + // We do not check if dependence with loads exists because that is already + // checked via hasLoadStoreDependenceInvolvingLoopInvariantAddress. ScalarEvolution *SE = PSE.getSE(); SmallVector<StoreInst *, 4> UnhandledStores; for (StoreInst *SI : LAI->getStoresToInvariantAddresses()) { |
