[llvm] [llvm][NFC] Refactor autoupdater's 'c' intrinsics (PR #73333)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 24 11:50:19 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Nathan Sidwell (urnathan)
<details>
<summary>Changes</summary>
With these three intrinsics it's probable faster to check the number of arguments first and then check the names. We can also handle ctlz and cttz in the same block.
---
Full diff: https://github.com/llvm/llvm-project/pull/73333.diff
1 Files Affected:
- (modified) llvm/lib/IR/AutoUpgrade.cpp (+13-12)
``````````diff
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 63c4b2c71299900..e6ff864a9140118 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -971,19 +971,20 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
break;
}
case 'c': {
- if (Name.starts_with("ctlz.") && F->arg_size() == 1) {
- rename(F);
- NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::ctlz,
- F->arg_begin()->getType());
- return true;
- }
- if (Name.starts_with("cttz.") && F->arg_size() == 1) {
- rename(F);
- NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::cttz,
- F->arg_begin()->getType());
- return true;
+ if (F->arg_size() == 1) {
+ Intrinsic::ID ID = StringSwitch<Intrinsic::ID>(Name)
+ .StartsWith("ctlz.", Intrinsic::ctlz)
+ .StartsWith("cttz.", Intrinsic::cttz)
+ .Default(Intrinsic::not_intrinsic);
+ if (ID != Intrinsic::not_intrinsic) {
+ rename(F);
+ NewFn = Intrinsic::getDeclaration(F->getParent(), ID,
+ F->arg_begin()->getType());
+ return true;
+ }
}
- if (Name.equals("coro.end") && F->arg_size() == 2) {
+
+ if (F->arg_size() == 2 && Name.equals("coro.end")) {
rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::coro_end);
return true;
``````````
</details>
https://github.com/llvm/llvm-project/pull/73333
More information about the llvm-commits
mailing list