Skip to content

Commit a695be7

Browse files
committed
[llvm][NFC] Refactor AutoUpgrade case 'w'
Check for 'wasm.' prefix before proceeding, and a bit of common handling for some of the intrinsics therein. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D158370
1 parent 87a1421 commit a695be7

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,36 +1188,34 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
11881188
}
11891189

11901190
case 'w':
1191-
if (Name.startswith("wasm.fma.")) {
1192-
rename(F);
1193-
NewFn = Intrinsic::getDeclaration(
1194-
F->getParent(), Intrinsic::wasm_relaxed_madd, F->getReturnType());
1195-
return true;
1196-
}
1197-
if (Name.startswith("wasm.fms.")) {
1198-
rename(F);
1199-
NewFn = Intrinsic::getDeclaration(
1200-
F->getParent(), Intrinsic::wasm_relaxed_nmadd, F->getReturnType());
1201-
return true;
1202-
}
1203-
if (Name.startswith("wasm.laneselect.")) {
1204-
rename(F);
1205-
NewFn = Intrinsic::getDeclaration(
1206-
F->getParent(), Intrinsic::wasm_relaxed_laneselect,
1207-
F->getReturnType());
1208-
return true;
1209-
}
1210-
if (Name == "wasm.dot.i8x16.i7x16.signed") {
1211-
rename(F);
1212-
NewFn = Intrinsic::getDeclaration(
1213-
F->getParent(), Intrinsic::wasm_relaxed_dot_i8x16_i7x16_signed);
1214-
return true;
1215-
}
1216-
if (Name == "wasm.dot.i8x16.i7x16.add.signed") {
1217-
rename(F);
1218-
NewFn = Intrinsic::getDeclaration(
1219-
F->getParent(), Intrinsic::wasm_relaxed_dot_i8x16_i7x16_add_signed);
1220-
return true;
1191+
if (Name.consume_front("wasm.")) {
1192+
Intrinsic::ID ID =
1193+
StringSwitch<Intrinsic::ID>(Name)
1194+
.StartsWith("fma.", Intrinsic::wasm_relaxed_madd)
1195+
.StartsWith("fms.", Intrinsic::wasm_relaxed_nmadd)
1196+
.StartsWith("laneselect.", Intrinsic::wasm_relaxed_laneselect)
1197+
.Default(Intrinsic::not_intrinsic);
1198+
if (ID != Intrinsic::not_intrinsic) {
1199+
rename(F);
1200+
NewFn =
1201+
Intrinsic::getDeclaration(F->getParent(), ID, F->getReturnType());
1202+
return true;
1203+
}
1204+
1205+
if (Name.consume_front("dot.i8x16.i7x16.")) {
1206+
ID = StringSwitch<Intrinsic::ID>(Name)
1207+
.Case("signed", Intrinsic::wasm_relaxed_dot_i8x16_i7x16_signed)
1208+
.Case("add.signed",
1209+
Intrinsic::wasm_relaxed_dot_i8x16_i7x16_add_signed)
1210+
.Default(Intrinsic::not_intrinsic);
1211+
if (ID != Intrinsic::not_intrinsic) {
1212+
rename(F);
1213+
NewFn = Intrinsic::getDeclaration(F->getParent(), ID);
1214+
return true;
1215+
}
1216+
break; // No other 'wasm.dot.i8x16.i7x16.*'.
1217+
}
1218+
break; // No other 'wasm.*'.
12211219
}
12221220
break;
12231221

0 commit comments

Comments
 (0)