llvm.org GIT mirror llvm / 870be0c
[MIRParser] Accept overloaded intrinsic names w/o type suffixes Function::lookupIntrinsicID is somewhat forgiving as it comes to overloaded intrinsics' names: it returns an ID as soon as the name provided has a prefix that matches a registered intrinsic's name w/o actually checking that the rest of the name encodes all the concrete arg types, let alone that those types are compatible with the intrinsic's definition. That's probably fine and comes in handy in MIR serialization: we don't care about IR types at MIR level and every intrinsic should be selectable based on its ID and low-level types (LLTs) of its operands, including the overloaded ones, so there is no point in serializing mangled IR types as part of the intrinsic's name. However, lookupIntrinsicID is somewhat inconsistent in its forgiveness: if the name provided is actually an exact match, it will refuse to return the ID if the intrinsic is overloaded. There is probably no real reason for that and it renders MIRParser incapable to deserialize MIR MIRPrinter serialized. This commit fixes it. Reviewers: rnk, aditya_nandakumar, qcolombet, thegameg, dsanders, marcello.maggioni Reviewed By: bogner Subscribers: javed.absar, llvm-commits Differential Revision: https://reviews.llvm.org/D43267 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326387 91177308-0d34-0410-b5e6-96231b3b80d8 Roman Tereshin 2 years ago
2 changed file(s) with 29 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
522522 Intrinsic::ID ID = static_cast(Idx + Adjust);
524524 // If the intrinsic is not overloaded, require an exact match. If it is
525 // overloaded, require a prefix match.
526 bool IsPrefixMatch = Name.size() > strlen(NameTable[Idx]);
527 return IsPrefixMatch == isOverloaded(ID) ? ID : Intrinsic::not_intrinsic;
525 // overloaded, require either exact or prefix match.
526 const auto MatchSize = strlen(NameTable[Idx]);
527 assert(Name.size() >= MatchSize && "Expected either exact or prefix match");
528 bool IsExactMatch = Name.size() == MatchSize;
529 return IsExactMatch || isOverloaded(ID) ? ID : Intrinsic::not_intrinsic;
528530 }
530532 void Function::recalculateIntrinsicID() {
0 # RUN: llc -mtriple aarch64-- -run-pass irtranslator -simplify-mir %s -o %t \
1 # RUN: -verify-machineinstrs; llc -mtriple aarch64-- -run-pass legalizer \
2 # RUN: -simplify-mir %t -x mir -o - -verify-machineinstrs | FileCheck %s
4 # Test that MIRParser is able to deserialize back MIR MIRPrinter serialized,
5 # specifically overloaded intrinsic names in this case which aren't required
6 # to encode all the concrete arg types in the name at MIR level.
8 --- |
9 define i32 @int_aarch64_sdiv(i32 %a, i32 %b) nounwind readnone ssp {
10 ; CHECK-LABEL: name: int_aarch64_sdiv
11 ; CHECK: liveins: $w0, $w1
12 ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
13 ; CHECK: [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
14 ; CHECK: [[INT:%[0-9]+]]:_(s32) = G_INTRINSIC intrinsic(@llvm.aarch64.sdiv), [[COPY]](s32), [[COPY1]](s32)
15 ; CHECK: $w0 = COPY [[INT]](s32)
16 ; CHECK: RET_ReallyLR implicit $w0
17 entry:
18 %sdiv = call i32 @llvm.aarch64.sdiv.i32(i32 %a, i32 %b)
19 ret i32 %sdiv
20 }
22 declare i32 @llvm.aarch64.sdiv.i32(i32, i32) nounwind readnone
23 ...