[llvm] [InstCombine] Allow min/max in constant BOp min/max folding (PR #142878)
Alex MacLean via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 8 18:39:01 PDT 2025
AlexMaclean 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?
In addition, I've observed some cases where multiple binops with constants get folded into a comparison preventing this optimization from occuring. Would it be alright to iteratively fold binops with constants until we reach the other value in the select or is this sort of thing too complex / potentially expensive for InstCombine?
https://github.com/llvm/llvm-project/pull/142878
More information about the llvm-commits
mailing list