Skip to content

Commit 770dc47

Browse files
authored
[llvm][NFC] Refactor autoupdater's 'c' intrinsics (#73333)
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.
1 parent a4d5fd4 commit 770dc47

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -968,19 +968,20 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
968968
break;
969969
}
970970
case 'c': {
971-
if (Name.starts_with("ctlz.") && F->arg_size() == 1) {
972-
rename(F);
973-
NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::ctlz,
974-
F->arg_begin()->getType());
975-
return true;
976-
}
977-
if (Name.starts_with("cttz.") && F->arg_size() == 1) {
978-
rename(F);
979-
NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::cttz,
980-
F->arg_begin()->getType());
981-
return true;
971+
if (F->arg_size() == 1) {
972+
Intrinsic::ID ID = StringSwitch<Intrinsic::ID>(Name)
973+
.StartsWith("ctlz.", Intrinsic::ctlz)
974+
.StartsWith("cttz.", Intrinsic::cttz)
975+
.Default(Intrinsic::not_intrinsic);
976+
if (ID != Intrinsic::not_intrinsic) {
977+
rename(F);
978+
NewFn = Intrinsic::getDeclaration(F->getParent(), ID,
979+
F->arg_begin()->getType());
980+
return true;
981+
}
982982
}
983-
if (Name.equals("coro.end") && F->arg_size() == 2) {
983+
984+
if (F->arg_size() == 2 && Name.equals("coro.end")) {
984985
rename(F);
985986
NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::coro_end);
986987
return true;

0 commit comments

Comments
 (0)