[Bug rtl-optimization/43226] simplify_binary_operation_1 MINUS x const_int issue

2023-06-05 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43226

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |DUPLICATE
   Target Milestone|--- |7.0
   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=78546

--- Comment #2 from Andrew Pinski  ---
The code does this now:
  /* Don't let a relocatable value get a negative coeff.  */
  if (poly_int_rtx_p (op1) && GET_MODE (op0) != VOIDmode)
return simplify_gen_binary (PLUS, mode,
op0,
neg_poly_int_rtx (mode, op1));


Which does:
/* Negate I, which satisfies poly_int_rtx_p.  MODE is the mode of I.  */

static rtx
neg_poly_int_rtx (machine_mode mode, const_rtx i)
{
  return immed_wide_int_const (-wi::to_poly_wide (i, mode), mode);
}


Poly_int's operator- does:
template
inline POLY_POLY_RESULT (N, Ca, Ca)
operator - (const poly_int_pod )
{
  typedef POLY_CAST (Ca, Ca) NCa;
  typedef POLY_POLY_COEFF (Ca, Ca) C;
  poly_int r;
  for (unsigned int i = 0; i < N; i++)
POLY_SET_COEFF (C, r, i, -NCa (a.coeffs[i]));
  return r;
}

  typedef poly_int > >
rtx_to_poly_wide_ref;

operator- on generic_wide_int calls wi::neg which does:
/* Return -x.  */
template 
inline WI_UNARY_RESULT (T)
wi::neg (const T )
{
  return sub (0, x);
}


wi::sub only uses `unsigned HOST_WIDE_INT`


r10-3327-g681fc0fa40cc moved it over to poly_int.



But r7-4950-gd057004733e8 (PR 78546) fixed this bug really for the same reason
why it was reported here but for HWI==64 and int128_t.

I am going to mark this as a dup of bug 78546 because the bug is the same.

*** This bug has been marked as a duplicate of bug 78546 ***

[Bug rtl-optimization/43226] simplify_binary_operation_1 MINUS x const_int issue

2021-08-07 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43226

--- Comment #1 from Andrew Pinski  ---
This changed over to wide_int (well poly_wide_int but for most targets it is
just wide_int). I have not looked to see if that fixes the issue here though.