Integer min/max operations are associative:
max (max X, C0), C1 --> max X, (max C0, C1) --> max X, NewC
https://alive2.llvm.org/ce/z/wW5HVM
This would avoid a regression when we canonicalize to min/max intrinsics (see D98152 ).
Differential D119754
[InstCombine] reassociate min/max intrinsics with constant operands spatel on Feb 14 2022, 11:46 AM. Authored by
Details Integer min/max operations are associative: https://alive2.llvm.org/ce/z/wW5HVM This would avoid a regression when we canonicalize to min/max intrinsics (see D98152 ).
Diff Detail
Unit Tests Event TimelineComment Actions You mean to enable more general reassociation to cascade? If the reassociate pass handled intrinsics, it would go the other direction (pull the constant higher up in the instruction sequence). I suspect it wouldn't be a small patch to generalize that pass to handle intrinsics instead of just true binop instructions. I didn't think instcombine inverted that, but it does do that for 'or' instructions at least: Comment Actions That was the idea, yes.
Comment Actions LGTM I think additional reassociation is not really a requirement here, and probably InstCombine is not the right place to reassociate large chains. Comment Actions I think it's good to make that an incremental improvement. It's not a lot of work to implement a variation of the suggested generalization -- I already drafted it. :) |
clang-format: please reformat the code