diff options
author | Owen Anderson <resistor@mac.com> | 2023-01-01 22:27:52 -0700 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2023-01-10 23:03:07 -0700 |
commit | 90c184662925b8f17bc9cf05cd60a9e98201fff6 (patch) | |
tree | 24d9af20b020d9d972c06e6c206d2b534f315b1b /llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp | |
parent | e9d571d3b6829f668e424d9dfce09f9ed7f297d9 (diff) | |
download | llvm-90c184662925b8f17bc9cf05cd60a9e98201fff6.zip llvm-90c184662925b8f17bc9cf05cd60a9e98201fff6.tar.gz llvm-90c184662925b8f17bc9cf05cd60a9e98201fff6.tar.bz2 |
Do not short circuit hoistIVInc when recomputation of poison flags is needed.
Fixes https://github.com/llvm/llvm-project/issues/59777
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D140836
Diffstat (limited to 'llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index 8653d13..80b0a20 100644 --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -1026,8 +1026,25 @@ void SCEVExpander::fixupInsertPoints(Instruction *I) { /// until we reach a value that dominates InsertPos. bool SCEVExpander::hoistIVInc(Instruction *IncV, Instruction *InsertPos, bool RecomputePoisonFlags) { - if (SE.DT.dominates(IncV, InsertPos)) - return true; + auto FixupPoisonFlags = [this](Instruction *I) { + // Drop flags that are potentially inferred from old context and infer flags + // in new context. + I->dropPoisonGeneratingFlags(); + if (auto *OBO = dyn_cast<OverflowingBinaryOperator>(I)) + if (auto Flags = SE.getStrengthenedNoWrapFlagsFromBinOp(OBO)) { + auto *BO = cast<BinaryOperator>(I); + BO->setHasNoUnsignedWrap( + ScalarEvolution::maskFlags(*Flags, SCEV::FlagNUW) == SCEV::FlagNUW); + BO->setHasNoSignedWrap( + ScalarEvolution::maskFlags(*Flags, SCEV::FlagNSW) == SCEV::FlagNSW); + } + }; + + if (SE.DT.dominates(IncV, InsertPos)) { + if (RecomputePoisonFlags) + FixupPoisonFlags(IncV); + return true; + } // InsertPos must itself dominate IncV so that IncV's new position satisfies // its existing users. @@ -1053,19 +1070,8 @@ bool SCEVExpander::hoistIVInc(Instruction *IncV, Instruction *InsertPos, for (Instruction *I : llvm::reverse(IVIncs)) { fixupInsertPoints(I); I->moveBefore(InsertPos); - if (!RecomputePoisonFlags) - continue; - // Drop flags that are potentially inferred from old context and infer flags - // in new context. - I->dropPoisonGeneratingFlags(); - if (auto *OBO = dyn_cast<OverflowingBinaryOperator>(I)) - if (auto Flags = SE.getStrengthenedNoWrapFlagsFromBinOp(OBO)) { - auto *BO = cast<BinaryOperator>(I); - BO->setHasNoUnsignedWrap( - ScalarEvolution::maskFlags(*Flags, SCEV::FlagNUW) == SCEV::FlagNUW); - BO->setHasNoSignedWrap( - ScalarEvolution::maskFlags(*Flags, SCEV::FlagNSW) == SCEV::FlagNSW); - } + if (RecomputePoisonFlags) + FixupPoisonFlags(I); } return true; } |