Fixes PR49932
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
It's a bit more tricky than that:
- I'm not sure how we should handle the case where we are trying to merge 2 thread_local constants with different TLS models.
- In general we are better off *not* merging global constants with TLS constants since calculating a TLS address can be expensive.
Reading the bug description, it seems that if the TLS constant as an unnamed address we should be able to merge it into a non-TLS constant?
I'm not even sure what it would *mean* to have an unnamed TLS constant: I would expect an earlier pass to convert it to a normal constant rather than having to it in ConstantMerge.
Also, AFAIK neither clang nor rustc will ever generate unnamed TLS constants.
Can we just completely forbid merging thread_local constants (in isUnmergeableGlobal)? I don't really want to think about the implications of merging.
No declared objects in C are ever unnamed_addr, but it's completely reasonable to infer it from use patterns, so it's not like this is an invalid combination. But I agree that it's pointless to merge thread-local constants in constant-merging, because yeah, in any situation where it's permitted we should always be promoting the variable to a global instead (and then maybe that enables constant merging on the promoted TLS).