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

[NFC][VPlan] Simplify VPValue::removeUser #74708

Merged
merged 3 commits into from
Dec 11, 2023
Merged

Conversation

sunshaoce
Copy link
Contributor

I think we don't need to use lambda, and we can end the loop in advance like this.

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 7, 2023

@llvm/pr-subscribers-llvm-transforms

Author: Shao-Ce SUN (sunshaoce)

Changes

I think we don't need to use lambda, and we can end the loop in advance like this.


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

1 Files Affected:

  • (modified) llvm/lib/Transforms/Vectorize/VPlanValue.h (+5-9)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanValue.h b/llvm/lib/Transforms/Vectorize/VPlanValue.h
index ac2883b30dc8c..14634dc31878f 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanValue.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanValue.h
@@ -121,18 +121,14 @@ class VPValue {
 
   /// Remove a single \p User from the list of users.
   void removeUser(VPUser &User) {
-    bool Found = false;
     // The same user can be added multiple times, e.g. because the same VPValue
     // is used twice by the same VPUser. Remove a single one.
-    erase_if(Users, [&User, &Found](VPUser *Other) {
-      if (Found)
-        return false;
-      if (Other == &User) {
-        Found = true;
-        return true;
+    for (const auto &U : Users) {
+      if (U == &User) {
+        Users.erase(&U);
+        return;
       }
-      return false;
-    });
+    }
   }
 
   typedef SmallVectorImpl<VPUser *>::iterator user_iterator;

Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

Please see the inline comment before merging and also adjust the commit messages to be definitive, i.e. drop It think and adjust to say hat this is now using find + erase; there's no more explicit loop.

llvm/lib/Transforms/Vectorize/VPlanValue.h Outdated Show resolved Hide resolved
@sunshaoce sunshaoce merged commit d860710 into llvm:main Dec 11, 2023
4 checks passed
@sunshaoce sunshaoce deleted the removeUser branch December 11, 2023 02:55
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

4 participants