[llvm] [LLVM][CanonicalizeFreezeInLoops] fix duplicate removal (PR #74716)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 7 05:36:41 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Wei Tao (Friedrich20)
<details>
<summary>Changes</summary>
This PR fixes [#<!-- -->74572](https://github.com/llvm/llvm-project/issues/74572) where the the freeze instruction could be found twice by the pass CanonicalizeFreezeInLoops, and then the compiling may crash in second removal since the instruction has already gone.
---
Full diff: https://github.com/llvm/llvm-project/pull/74716.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp (+10-3)
``````````diff
diff --git a/llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp b/llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp
index fb4d828853772..ff1eb17e0c248 100644
--- a/llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp
+++ b/llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp
@@ -151,11 +151,18 @@ bool CanonicalizeFreezeInLoopsImpl::run() {
}
}
+ bool Exist = false;
auto Visit = [&](User *U) {
if (auto *FI = dyn_cast<FreezeInst>(U)) {
- LLVM_DEBUG(dbgs() << "canonfr: found: " << *FI << "\n");
- Info.FI = FI;
- Candidates.push_back(Info);
+ for (const auto &Candidate : Candidates) {
+ auto *FI_cand = Candidate.FI;
+ Exist = (FI_cand == FI) ? true : Exist;
+ }
+ if (!Exist) {
+ LLVM_DEBUG(dbgs() << "canonfr: found: " << *FI << "\n");
+ Info.FI = FI;
+ Candidates.push_back(Info);
+ }
}
};
for_each(PHI.users(), Visit);
``````````
</details>
https://github.com/llvm/llvm-project/pull/74716
More information about the llvm-commits
mailing list