This is an archive of the discontinued LLVM Phabricator instance.

[IR] Have Value::takeName() transfer intrinsic properties
Needs ReviewPublic

Authored by frasercrmck on Jun 30 2022, 7:27 AM.

Details

Reviewers
aeubanks
jlebar
Summary

Functions are considered intrinsics if their names begin with "llvm.",
even if they don't have a valid intrinsic ID. This is a cached property,
stored in GlobalValue's HasLLVMReservedName.

When calling Value::setName(), this property is recalculated. However,
this property is not recalculated when taking names from another Value.
While it's not documented as doing such, the semantics of "takeName"
suggest that A.takeName(B) is the same as A.setName(B.getName())
followed by B.setName("").

This patch updates Value::takeName to act in this fashion, to avoid any
unexpected behaviour: The new function is an intrinsic since it now starts with
"llvm." and the old function is no longer considered an intrinsic, since it no
longer begins with "llvm.".

Diff Detail

Event Timeline

frasercrmck created this revision.Jun 30 2022, 7:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2022, 7:27 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
frasercrmck requested review of this revision.Jun 30 2022, 7:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2022, 7:27 AM

what's the use case for having a function take the name of an intrinsic function?

what's the use case for having a function take the name of an intrinsic function?

It's a good question. I can't think of a reason you'd do this for intrinsics with intrinsic IDs, but if the meaning of intrinsic is indeed "starts with 'llvm.'", as is documented, then I think we should transfer that property over when naming functions in all cases. It's unintuitive to me to have a function beginning with "llvm." be an intrinsic if it's named through one method but not another.

As a more concrete example, downstream we have some passes which add parameters to functions, remove parameters from functions, change parameter types, etc., so we create new functions from old ones and this means we generally take the name. If, for whatever reason, we had a user using a "custom" intrinsic (if I may call them that - just a function starting with "llvm.") so they can make use of intrinsic semantics (e.g., they can use intrinsic-only function parameters like immarg or elementtype) then if we drop the fact that it's an intrinsic then at the very least the verifier would complain. That's how I originally caught this issue.

was worried about compile time issues, seems fine
https://llvm-compile-time-tracker.com/compare.php?from=a9119143a2d1f4d0d0bc1fe0d819e5351b4e0deb&to=3262dfdab15c7017935961c06b127ec9ac8dc7fd&stat=instructions

I'd sort of prefer going the opposite route of https://reviews.llvm.org/D129015 and banning setName/takeName on intrinsics, that seems less error-prone
it seems weird to create a new intrinsic declaration that has the same name as a previous intrinsic