lhmouse wrote:

> I'd like to understand the the performance claims a bit better. Do I 
> understand correctly that:
> 
> * nobody's saying that sret-ing is more efficient than direct returning in 
> xmm0
> * what is argued and demonstrated is that moving data between GPR and XMM 
> registers is slow, and sret-ing can _sometimes_ avoid that
> * so especially in the case where one or both sides of the caller-callee pair 
> need to do GPR<->XMM moves, sret-ing is _even more likely_ to perform better 
> (though, it seems not to be an absolute claim, there's always going to be 
> cases where that's worse)

It is very likely to be. There are some conditions for store-load forwarding:

1. The store instruction must cover the address range of the load instruction. 
A wider store followed by a narrower load is probably OK, but a narrower store 
followed by a wider load is definitely NG.
2. The store operation should not be split. As long as it's properly aligned, 
it is not an issue. I have also observed successful forwarding with `movdqu` 
pairs on i9-14900K; there's a 1-cycle penalty when the store-load pair 
straddles cachelines, but it (2 cycles) is clearly forwarded successfully.
3. The stored data must be in the store buffer. `MOVNT*` won't be optimizable.
4. The address should be synthesized from GPRs and optional displacements. If 
the address is RIP-relative, it usually takes at least 5~6 cycles even when 
forwarded successfully. An unforwarded store-load pair takes ~20 cycles 
regardless of the address type.

When these conditions are met, then store-load forwarding usually takes effect. 
All this is model-specific.

On modern Intel chips, there are two store ports for data stores, but there's 
only one for shuffling (for moving GPR into XMM), so it could become a 
bottleneck.


> And then in particular, is it true that:
> 
> * for internal functions (no ABI requirements), where GPR<->XMM moves are not 
> present, we would probably want to actively avoid sret-ing? (Not saying this 
> would need to be done in Clang, but somewhere.)
> 
> I'm asking because of #242246.

Of course. For a custom convention it can be returned in RDX:RAX.


https://github.com/llvm/llvm-project/pull/210358
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to