[llvm] [InstCombine] Pattern match minmax calls for unsigned saturation. (PR #99250)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 23 00:53:08 PDT 2024
================
@@ -1117,68 +1117,108 @@ 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, sub(zext(A), zext(B)))
+ // Or umin(UINT_MAX, add(zext(A), zext(B))).
----------------
goldsteinn wrote:
Can you update the comment as to which variant of `[s|u][add|sub]_sat` the different min/max patterns correspond to?
https://github.com/llvm/llvm-project/pull/99250
More information about the llvm-commits
mailing list