This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/71608] Wrong constant folding


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

--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> ---
negate_expr_p, for MULT_EXPR, has:

      /* INT_MIN/n * n doesn't overflow while negating one operand it does
         if n is a power of two.  */
      if (INTEGRAL_TYPE_P (TREE_TYPE (t))
          && ! TYPE_OVERFLOW_WRAPS (TREE_TYPE (t))
          && ! ((TREE_CODE (TREE_OPERAND (t, 0)) == INTEGER_CST
                 && ! integer_pow2p (TREE_OPERAND (t, 0)))
                || (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST
                    && ! integer_pow2p (TREE_OPERAND (t, 1)))))
        break;

It handles INT_MIN/n * n where n is a power of 2 but not -(INT_MIN/n) * -n.

I am not convinced by the way fold_negate_expr handles this either.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]