[llvm] [AsmWriter] Fix MIR printing of single constant LLVM IR metadata (PR #165029)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 27 09:22:47 PDT 2025


saxlungs wrote:

> This seems like too low level of a change. Why are these cases not just uniformly handled in the first place?

@arsenm 

It seems to me that "MDNode" was originally specifically meant to be just used for metadata in the LLVM IR that's in the format "!x", where x is some number. This makes sense for slot purposes, because those metadata also later have the definition of what each index is referring to (you can see an example in the test I updated). However, MachineInstruction objects don't just house generic Metadata objects, for some reason their "Contents" field enum only allows MDNode objects specifically. So any metadata that isn't an MDNode that wants to be kept in the MIR just gets wrapped in an MDNode before getting put into a MachineInstruction during translation (you can see this around line ~2845 in llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp). To truly solve the issue, I think we'd have to allow any Metadata family object to be in the MachineInstruction, but I don't know why that limitation was made in the first place and I can imagine that that might be a very involved change if they had good reasons. Since this is just meant to fix some small headaches when updating tests I thought the minimal effective solution could be good, but let me know if you think a much deeper dive would be appropriate

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


More information about the llvm-commits mailing list