[clang] [llvm] IR: Store the default subtarget info in named metadata instead of the context. (PR #98673)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 15 18:14:31 PDT 2024


================
@@ -1240,11 +1240,22 @@ void IRLinker::linkNamedMDNodes() {
     if (IsPerformingImport && NMD.getName() == "llvm.stats")
       continue;
 
+    // Default subtarget info is only intended to be used before LTO and
+    // shouldn't be present after merging because the default subtargets may be
+    // different. Even if they were the same we wouldn't want to keep them to
+    // avoid introducing bugs that would only occur when merging modules with
+    // different subtarget info.
+    if (NMD.getName() == "llvm.subtarget.info")
----------------
pcc wrote:

Such cases should use a separate field, such as the e_flags field that I suggested in [the Discourse thread](https://discourse.llvm.org/t/functions-generated-by-function-createwithdefaultattr-should-respect-target-features/79838/11). That would more cleanly implement the semantics that the target actually wants. The metadata that I'm adding here is intended as a generic description of the singular default target CPU/features, and since that's not a concept that exists generically after LTO it gets removed from the IR at that point.

https://github.com/llvm/llvm-project/pull/98673


More information about the cfe-commits mailing list