[llvm] [DAGCombiner] Fold smax(X, -1) to or(X, ashr(X, BW-1)) for code size (PR #206242)

Aayush Shrivastava via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 27 11:34:31 PDT 2026


iamaayushrivastava wrote:

> This should apply to O2+ not just Oz: https://godbolt.org/z/YGrcvqq4e (for aarch64 and APX, this also reduce instructions)

Thank you for pointing that out! You're right, the fold is algebraically always correct, and the bitwise form is at least as good at any optimization level (strictly better on AArch64 where it goes from 2 instructions to 1 shifted ORR, and on APX). I've removed the `ForCodeSize` guard so the fold now applies unconditionally, and added an AArch64 test to document the instruction count reduction.

https://github.com/llvm/llvm-project/pull/206242


More information about the llvm-commits mailing list