[all-commits] [llvm/llvm-project] a21a7d: [X86] Optimize umax(X, 1) (NFC)
kazutakahirata via All-commits
all-commits at lists.llvm.org
Mon Mar 6 10:19:21 PST 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: a21a7ddf5ad1f34874cddb4d10cbd40b8ce1bef8
https://github.com/llvm/llvm-project/commit/a21a7ddf5ad1f34874cddb4d10cbd40b8ce1bef8
Author: Kazu Hirata <kazu at google.com>
Date: 2023-03-06 (Mon, 06 Mar 2023)
Changed paths:
M llvm/lib/Target/X86/X86ISelLowering.cpp
M llvm/test/CodeGen/X86/umax.ll
Log Message:
-----------
[X86] Optimize umax(X,1) (NFC)
Without this patch:
%cond = call i32 @llvm.umax.i32(i32 %X, i32 1)
is compiled as:
83 ff 02 cmp $0x2,%edi
b8 01 00 00 00 mov $0x1,%eax
0f 43 c7 cmovae %edi,%eax
With this patch, the compiler generates:
89 f8 mov %edi,%eax
83 ff 01 cmp $0x1,%edi
83 d0 00 adc $0x0,%eax
saving 3 bytes. We should be able to save 5 bytes in larger functions
where the mov is unnecessary.
This patch converts the specific cmov pattern to cmp $1 followed by
adc $0.
This patch partially fixes:
https://github.com/llvm/llvm-project/issues/60374
The LLVM IR optimizer is yet to canonicalize max expressions to
actual @llvm.umax.
Differential Revision: https://reviews.llvm.org/D144451
More information about the All-commits
mailing list