[llvm] [LLVM][CanonicalizeFreezeInLoops] fix duplicate removal (PR #74714)
Wei Tao via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 7 05:25:23 PST 2023
https://github.com/Friedrich20 created https://github.com/llvm/llvm-project/pull/74714
This PR fixes #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.
>From 903262f32a67d7933ff7d240f6f3793b8a6609a3 Mon Sep 17 00:00:00 2001
From: Wei Tao <friedrich.taow at gmail.com>
Date: Thu, 7 Dec 2023 21:16:55 +0800
Subject: [PATCH] [LLVM][CanonicalizeFreezeInLoops] fix duplicate removal
---
llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp b/llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp
index fb4d828853772..af9dad143e2ed 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)) {
+ 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);
More information about the llvm-commits
mailing list