https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122876

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
```
(for cmp (lt le gt ge)
     rcmp (gt ge lt le)
 (for op (plus minus)
      rop (minus plus)
  (simplify
   (cmp (op@3 @0 INTEGER_CST@1) INTEGER_CST@2)
   (if (!TREE_OVERFLOW (@1) && !TREE_OVERFLOW (@2)
        && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
    (with { tree res = int_const_binop (rop, @2, @1); }
     (if (TREE_OVERFLOW (res))
      {
        fold_overflow_warning (("assuming signed overflow does not occur "
                                "when simplifying conditional to constant"),
                               WARN_STRICT_OVERFLOW_CONDITIONAL);
        bool less = cmp == LE_EXPR || cmp == LT_EXPR;
        /* wi::ges_p (@2, 0) should be sufficient for a signed type.  */
        bool ovf_high = wi::lt_p (wi::to_wide (@1), 0,
                                  TYPE_SIGN (TREE_TYPE (@1)))
                        != (op == MINUS_EXPR);
        constant_boolean_node (less == ovf_high, type);
      }
      (if (single_use (@3))
       (with
        {
          fold_overflow_warning (("assuming signed overflow does not occur "
                                  "when changing X +- C1 cmp C2 to "
                                  "X cmp C2 -+ C1"),
                                 WARN_STRICT_OVERFLOW_COMPARISON);
        }
        (cmp @0 { res; })))))

```

Looks like this pattern is missing TYPE_OVERFLOW_SANITIZED check.

Reply via email to