Skip to content

[Utils] Use StringRef::starts_with (NFC) #138379

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

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented May 3, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) llvm/lib/Transforms/Utils/IRNormalizer.cpp (+3-3)
diff --git a/llvm/lib/Transforms/Utils/IRNormalizer.cpp b/llvm/lib/Transforms/Utils/IRNormalizer.cpp
index 75e775086493a..fd355ff9294cc 100644
--- a/llvm/lib/Transforms/Utils/IRNormalizer.cpp
+++ b/llvm/lib/Transforms/Utils/IRNormalizer.cpp
@@ -367,7 +367,7 @@ void IRNormalizer::foldInstructionName(Instruction *I) const {
   }
 
   // Don't fold if it is an output instruction or has no op prefix.
-  if (isOutput(I) || I->getName().substr(0, 2) != "op")
+  if (isOutput(I) || !I->getName().starts_with("op"))
     return;
 
   // Instruction operands.
@@ -375,8 +375,8 @@ void IRNormalizer::foldInstructionName(Instruction *I) const {
 
   for (auto &Op : I->operands()) {
     if (const auto *I = dyn_cast<Instruction>(Op)) {
-      bool HasNormalName = I->getName().substr(0, 2) == "op" ||
-                           I->getName().substr(0, 2) == "vl";
+      bool HasNormalName =
+          I->getName().starts_with("op") || I->getName().starts_with("vl");
 
       Operands.push_back(HasNormalName ? I->getName().substr(0, 7)
                                        : I->getName());

@kazutakahirata kazutakahirata merged commit fdea1b6 into llvm:main May 3, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_tidy_modernize-use-starts-ends-with_llvm branch May 3, 2025 14:05
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
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.

3 participants