[llvm] [InstCombine] Canonicalize more saturated add variants (PR #100008)

Rose Silicon via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 28 12:39:06 PDT 2024


================
@@ -996,6 +989,30 @@ static Value *canonicalizeSaturatedAdd(ICmpInst *Cmp, Value *TVal, Value *FVal,
   if (!match(TVal, m_AllOnes()))
     return nullptr;
 
+  if ((Pred == ICmpInst::ICMP_UGE || Pred == ICmpInst::ICMP_UGT) &&
+      match(FVal, m_Add(m_Specific(Cmp0), m_APInt(C))) &&
+      match(Cmp1, m_SpecificIntAllowPoison(~*C))) {
----------------
RSilicon wrote:

> uadd_sat_poison is a scalar poison value. m_SpecifincIntAllowPoison won't match that.
> 
> m_SpecificIntAllowPoison allows matching a vector where some elements are poison and some are the specific constant like `<i32 31, i32 poison, i32 31, i32 31>`. For scalars it only matches the specific constant.

I added a splat-poison vector test to show this!

https://github.com/llvm/llvm-project/pull/100008


More information about the llvm-commits mailing list