[clang] [clang][CodeGen] `sret` args should always point to the `alloca` AS, so use that (PR #114062)
John McCall via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 10 01:25:16 PST 2024
https://github.com/rjmccall requested changes to this pull request.
I'm fine with how you're handling the address spaces for now.
I'd like to talk about the rule you're implementing, though. It looks like it's supposed to be:
- return values always use the alloca AS
- arguments always use the default AS
- whether something is indirect because it's non-POD or simply too big to fit in registers doesn't make a difference
That's a surprising rule; in fact, it's the exact opposite of the rule I would expect.
Indirect arguments are always true temporaries. The caller has total control over where to allocate and initialize the temporary, and it has very little reason to not always use the stack. So there's no reason for the ABI to not specify that the argument pointer is passed in the alloca AS.
Return values, in contrast, can be used to directly initialize all sorts of different memory, not just objects on the stack. So the ABI should probably be to pass as generic a pointer as the target supports. Moreover, while passing a restricted pointer in C is okay because we can always use pass a temporary and then relocate the object after the call, the same is not true for types that are non-trivial to copy in C++ — we are not generally allowed to introduce extra moves of such objects. So if you want to return values in the alloca AS in general, you do need to make an exception for non-trivial C++ objects.
https://github.com/llvm/llvm-project/pull/114062
More information about the cfe-commits
mailing list