[llvm] [DAGCombiner] Fold smax(X, -1) to or(X, ashr(X, BW-1)) for code size (PR #206242)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 27 14:16:51 PDT 2026
================
@@ -0,0 +1,75 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc < %s -mtriple=x86_64-linux -O2 | FileCheck %s
+;
+; Verify smax(X, -1) and smin(X, 0) fold to bitwise shift forms.
+; smax(X, -1) = or(X, ashr(X, BW-1)) -- saves a byte vs compare+cmov on x86-64
+; smin(X, 0) = and(X, ashr(X, BW-1)) -- saves a byte vs compare+cmov on x86-64
+; Both also reduce instruction count on AArch64/APX. GCC PR 125921, LLVM #206153.
----------------
RKSimon wrote:
If you've dropped codesize probably best to move these tests inside combine-smax.ll
https://github.com/llvm/llvm-project/pull/206242
More information about the llvm-commits
mailing list