Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LLVM][CanonicalizeFreezeInLoops] fix duplicate removal #74714

Closed
wants to merge 1 commit into from
Closed

[LLVM][CanonicalizeFreezeInLoops] fix duplicate removal #74714

wants to merge 1 commit into from

Conversation

Friedrich20
Copy link
Contributor

@Friedrich20 Friedrich20 commented Dec 7, 2023

No description provided.

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 7, 2023

@llvm/pr-subscribers-llvm-transforms

Author: Wei Tao (Friedrich20)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/74714.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp (+7)
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);

Copy link

github-actions bot commented Dec 7, 2023

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 6a1badfed2dcd438d94a35cc4ab3b38c7cc06208 903262f32a67d7933ff7d240f6f3793b8a6609a3 -- llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp
View the diff from clang-format here.
diff --git a/llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp b/llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp
index af9dad143e..ff1eb17e0c 100644
--- a/llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp
+++ b/llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp
@@ -159,9 +159,9 @@ bool CanonicalizeFreezeInLoopsImpl::run() {
           Exist = (FI_cand == FI) ? true : Exist;
         }
         if (!Exist) {
-        LLVM_DEBUG(dbgs() << "canonfr: found: " << *FI << "\n");
-        Info.FI = FI;
-        Candidates.push_back(Info);
+          LLVM_DEBUG(dbgs() << "canonfr: found: " << *FI << "\n");
+          Info.FI = FI;
+          Candidates.push_back(Info);
         }
       }
     };

@Friedrich20 Friedrich20 closed this Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants