[llvm] [InstCombine] Pattern match minmax calls for unsigned saturation. (PR #99250)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 17 22:09:24 PDT 2024
================
@@ -1117,68 +1117,92 @@ static Instruction *moveAddAfterMinMax(IntrinsicInst *II,
return IsSigned ? BinaryOperator::CreateNSWAdd(NewMinMax, Add->getOperand(1))
: BinaryOperator::CreateNUWAdd(NewMinMax, Add->getOperand(1));
}
-/// Match a sadd_sat or ssub_sat which is using min/max to clamp the value.
-Instruction *InstCombinerImpl::matchSAddSubSat(IntrinsicInst &MinMax1) {
+/// Match a [s|u]add_sat or [s|u]sub_sat which is using min/max to clamp the
+/// value.
+Instruction *InstCombinerImpl::matchAddSubSat(IntrinsicInst &MinMax1) {
Type *Ty = MinMax1.getType();
- // We are looking for a tree of:
- // max(INT_MIN, min(INT_MAX, add(sext(A), sext(B))))
- // Where the min and max could be reversed
- Instruction *MinMax2;
+ // 1. We are looking for a tree of signed saturation:
+ // smax(SINT_MIN, smin(SINT_MAX, add|sub(sext(A), sext(B))))
+ // Where the smin and smax could be reversed.
+ // 2. A tree of unsigned saturation:
+ // smax(UINT_MIN, smin(UINT_MAX, sub(zext(A), zext(B))))
----------------
dtcxzyw wrote:
`UINT_MAX` is -1. It looks incorrect.
https://github.com/llvm/llvm-project/pull/99250
More information about the llvm-commits
mailing list