[llvm] [llvm] Adjust Autoupdater's llvm prefix detection (PR #74142)

via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 2 08:57:51 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Nathan Sidwell (urnathan)

<details>
<summary>Changes</summary>

Use consume_front to swallow the 'llvm.' prefix, and 'empty' to check there's at least one character left.  It does not seem worth while checking for at least 2 characters left -- any well formed IR will have several characters remaining anyway.

probably the simplest of my autoupdater changes.

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


1 Files Affected:

- (modified) llvm/lib/IR/AutoUpgrade.cpp (+3-3) 


``````````diff
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 9d546d3a5e9b1..7a40f24661caf 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -704,11 +704,11 @@ static Intrinsic::ID ShouldUpgradeNVPTXBF16Intrinsic(StringRef Name) {
 static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
   assert(F && "Illegal to upgrade a non-existent Function.");
 
-  // Quickly eliminate it, if it's not a candidate.
   StringRef Name = F->getName();
-  if (Name.size() <= 7 || !Name.starts_with("llvm."))
+
+  // Quickly eliminate it, if it's not a candidate.
+  if (!Name.consume_front("llvm.") || Name.empty())
     return false;
-  Name = Name.substr(5); // Strip off "llvm."
 
   switch (Name[0]) {
   default: break;

``````````

</details>


https://github.com/llvm/llvm-project/pull/74142


More information about the llvm-commits mailing list