[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
Loading
Please sign in to comment