[llvm] [InstCombine] Allow min/max in constant BOp min/max folding (PR #142878)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 9 01:07:30 PDT 2025


nikic wrote:

> @nikic / @dtcxzyw I'm considering trying to improve this function further and I'm interested in your thoughts.
> 
> The wrap flags may be preserved on the BinOp if wrapping doesn't occur when computing C2 BOp C1 (https://alive2.llvm.org/ce/z/n_3aNJ). Unfortunately, there doesn't seem like there exists a simply way to know whether wrapping occurred when constant folding the binop. The best I can think of would be to first constant-fold a sext/zext of C1 and C2 and see if evaluating BOp on a larger type is equivalent to evaluating on the original type and then extending. Does this seem like an okay approach? or do you know of a better way?

There is a willNotOverflow() helper in InstCombine you could use. Do the flags matter in practice for further optimization?

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


More information about the llvm-commits mailing list