[PATCH] D144451: [X86] Optimize umax(X,1)
Kazu Hirata via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 25 23:07:23 PST 2023
kazu added a comment.
In D144451#4142080 <https://reviews.llvm.org/D144451#4142080>, @goldstein.w.n wrote:
> Slightly unrelated, is it possible to get the codegen to be:
>
> xorl %eax, %eax
> cmp $0x1, %edi
> adc %edi, %eax
>
> ?
>
> If so that would be preferable (except in register pressure corner case b.c `eax` and `edi` now have slight live-range overlap).
> On target like ICX it saves a full instruction b.c no move-elim.
I've never thought of that. Very interesting. The comparison of the two approaches is such a close call. I have a //slight// preference to the mov-cmp-adc route. If we assume that users typically do not care about the value of `x` past `umax(x,1)`, which I haven't surveyed in real-world applications, we shouldn't have to make a copy of the source operand with a `mov`, especially in large enough functions where the calling conventions (edi->eax) aren't much of a constraint. Friendliness under high register pressure along with the 6-byte encoding (without a `mov`) is a plus.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D144451/new/
https://reviews.llvm.org/D144451
More information about the llvm-commits
mailing list