[llvm] [InstCombine] Canonicalize `max(min(X, MinC), MaxC) -> min(max(X, MaxC), MinC)` (PR #136665)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 22 06:32:21 PDT 2025
================
@@ -1924,6 +1924,29 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
}
}
+ // smax(smin(X, MinC), MaxC) -> smin(smax(X, MaxC), MinC) if MinC s>= MaxC
+ // umax(umin(X, MinC), MaxC) -> umin(umax(X, MaxC), MinC) if MinC u>= MaxC
+ const APInt *MinC, *MaxC;
+ auto CreateTransposedMaxMin = [&](bool IsSigned) {
----------------
dtcxzyw wrote:
I cannot connect this transformation with the word `transposed`. But I don't have a better alternative in mind.
Actually, this transformation acts like the distributive law:
```
smax(smin(X, MinC), MaxC) ->
smin(smax(X, MaxC), smax(MinC, MaxC)) ->
smin(smax(X, MaxC), MinC)
```
https://github.com/llvm/llvm-project/pull/136665
More information about the llvm-commits
mailing list