Skip to content

Commit 037f203

Browse files
committed
[llvm][NFC] Adjust address-space access auto upgrade detection
The address-space intrinsics need detecting, and all have very similar processing. Refactor to do just that. Differential Revision: https://reviews.llvm.org/D157763 Reviewed By: jroelofs
1 parent b966978 commit 037f203

File tree

1 file changed

+27
-44
lines changed

1 file changed

+27
-44
lines changed

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,51 +1053,34 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
10531053
break;
10541054
}
10551055
case 'm': {
1056-
if (Name.startswith("masked.load.")) {
1057-
Type *Tys[] = { F->getReturnType(), F->arg_begin()->getType() };
1058-
if (F->getName() !=
1059-
Intrinsic::getName(Intrinsic::masked_load, Tys, F->getParent())) {
1060-
rename(F);
1061-
NewFn = Intrinsic::getDeclaration(F->getParent(),
1062-
Intrinsic::masked_load,
1063-
Tys);
1064-
return true;
1065-
}
1066-
}
1067-
if (Name.startswith("masked.store.")) {
1068-
auto Args = F->getFunctionType()->params();
1069-
Type *Tys[] = { Args[0], Args[1] };
1070-
if (F->getName() !=
1071-
Intrinsic::getName(Intrinsic::masked_store, Tys, F->getParent())) {
1072-
rename(F);
1073-
NewFn = Intrinsic::getDeclaration(F->getParent(),
1074-
Intrinsic::masked_store,
1075-
Tys);
1076-
return true;
1077-
}
1078-
}
1079-
// Renaming gather/scatter intrinsics with no address space overloading
1080-
// to the new overload which includes an address space
1081-
if (Name.startswith("masked.gather.")) {
1082-
Type *Tys[] = {F->getReturnType(), F->arg_begin()->getType()};
1083-
if (F->getName() !=
1084-
Intrinsic::getName(Intrinsic::masked_gather, Tys, F->getParent())) {
1085-
rename(F);
1086-
NewFn = Intrinsic::getDeclaration(F->getParent(),
1087-
Intrinsic::masked_gather, Tys);
1088-
return true;
1089-
}
1090-
}
1091-
if (Name.startswith("masked.scatter.")) {
1092-
auto Args = F->getFunctionType()->params();
1093-
Type *Tys[] = {Args[0], Args[1]};
1094-
if (F->getName() !=
1095-
Intrinsic::getName(Intrinsic::masked_scatter, Tys, F->getParent())) {
1096-
rename(F);
1097-
NewFn = Intrinsic::getDeclaration(F->getParent(),
1098-
Intrinsic::masked_scatter, Tys);
1099-
return true;
1056+
StringRef MaskPfx = "masked.";
1057+
if (Name.startswith(MaskPfx)) {
1058+
// Renaming masked intrinsics with no address space overloading
1059+
// to the new overload, which includes an address space.
1060+
Intrinsic::ID ID =
1061+
StringSwitch<Intrinsic::ID>(Name.substr(MaskPfx.size()))
1062+
.StartsWith("load.", Intrinsic::masked_load)
1063+
.StartsWith("store.", Intrinsic::masked_store)
1064+
.StartsWith("gather.", Intrinsic::masked_gather)
1065+
.StartsWith("scatter.", Intrinsic::masked_scatter)
1066+
.Default(Intrinsic::not_intrinsic);
1067+
if (ID != Intrinsic::not_intrinsic) {
1068+
const auto *FT = F->getFunctionType();
1069+
SmallVector<Type *, 2> Tys;
1070+
if (ID == Intrinsic::masked_load || ID == Intrinsic::masked_gather)
1071+
// Loading operations overload on the return type.
1072+
Tys.push_back(FT->getReturnType());
1073+
Tys.push_back(FT->getParamType(0));
1074+
if (ID == Intrinsic::masked_store || ID == Intrinsic::masked_scatter)
1075+
// Store operations overload on the stored type.
1076+
Tys.push_back(FT->getParamType(1));
1077+
if (F->getName() != Intrinsic::getName(ID, Tys, F->getParent())) {
1078+
rename(F);
1079+
NewFn = Intrinsic::getDeclaration(F->getParent(), ID, Tys);
1080+
return true;
1081+
}
11001082
}
1083+
break; // No other 'masked.*'
11011084
}
11021085
// Updating the memory intrinsics (memcpy/memmove/memset) that have an
11031086
// alignment parameter to embedding the alignment as an attribute of

0 commit comments

Comments
 (0)