[Bug middle-end/113705] [14 Regression] ICE in decompose, at wide-int.h:1049 on aarch64-linux-gnu since r14-8680-g2f14c0dbb78985

2024-02-02 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113705

Jakub Jelinek  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|ASSIGNED|RESOLVED

--- Comment #11 from Jakub Jelinek  ---
Fixed.

[Bug middle-end/113705] [14 Regression] ICE in decompose, at wide-int.h:1049 on aarch64-linux-gnu since r14-8680-g2f14c0dbb78985

2024-02-02 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113705

--- Comment #10 from GCC Commits  ---
The master branch has been updated by Jakub Jelinek :

https://gcc.gnu.org/g:a8f335ccb61bf6105192a4197ef2d84900614dc1

commit r14-8742-ga8f335ccb61bf6105192a4197ef2d84900614dc1
Author: Jakub Jelinek 
Date:   Fri Feb 2 11:25:13 2024 +0100

tree-ssa-math-opts: Fix is_widening_mult_rhs_p - unbreak bootstrap
[PR113705]

On Tue, Jan 30, 2024 at 07:33:10AM -, Roger Sayle wrote:
+ wide_int bits = wide_int::from (tree_nonzero_bits (rhs),
+ prec,
+ TYPE_SIGN (TREE_TYPE (rhs)));
...
> +   if (gimple_assign_rhs_code (stmt) == BIT_AND_EXPR
> +   && TREE_CODE (gimple_assign_rhs2 (stmt)) ==
INTEGER_CST
> +   && wi::to_wide (gimple_assign_rhs2 (stmt))
> +  == wi::mask (hprec, false, prec))

This change broke bootstrap on aarch64-linux.
The problem can be seen even on the reduced testcase.

The IL on the unreduced testcase before widening_mul has:
  # val_583 = PHI 
...
  pretmp_266 = MEM[(const struct wide_int_storage *)].len;
  _264 = pretmp_266 & 65535;
...
  _176 = (sizetype) val_583;
  _439 = (sizetype) _264;
  _284 = _439 * 8;
  _115 = _176 + _284;
where 583/266/264 have unsigned int type and 176/439/284/115 have sizetype.
widening_mul first turns that into:
  # val_583 = PHI 
...
  pretmp_266 = MEM[(const struct wide_int_storage *)].len;
  _264 = pretmp_266 & 65535;
...
  _176 = (sizetype) val_583;
  _439 = (sizetype) _264;
  _284 = _264 w* 8;
  _115 = _176 + _284;
and then is_widening_mult_rhs_p is called, with type sizetype (64-bit),
rhs _264, hprec 32 and prec 64.  Now tree_nonzero_bits (rhs) is
65535, so bits is 64-bit wide_int 65535, stmt is BIT_AND_EXPR,
but we ICE on the
wi::to_wide (gimple_assign_rhs2 (stmt)) == wi::mask (hprec, false, prec)
comparison because wi::to_wide on gimple_assign_rhs2 (stmt) - unsigned int
65535 gives 32-bit wide_int 65535, while wi::mask (hprec, false, prec)
gives 64-bit wide_int 0x and comparison between different precision
wide_ints is forbidden.

The following patch fixes it the same way how bits is computed earlier,
by calling wide_int::from on the wi::to_wide (gimple_assign_rhs2 (stmt)),
so we compare 64-bit 65535 with 64-bit 0x.

2024-02-02  Jakub Jelinek  

PR middle-end/113705
* tree-ssa-math-opts.cc (is_widening_mult_rhs_p): Use wide_int_from
around wi::to_wide in order to compare value in prec precision.

* g++.dg/opt/pr113705.C: New test.

[Bug middle-end/113705] [14 Regression] ICE in decompose, at wide-int.h:1049 on aarch64-linux-gnu since r14-8680-g2f14c0dbb78985

2024-02-02 Thread doko at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113705

Matthias Klose  changed:

   What|Removed |Added

 Target|aarch64-linux-gnu,  |aarch64-linux-gnu,
   |loongarch64-linux-gnu   |loongarch64-linux-gnu,
   ||mips64el-linux-gnu

--- Comment #9 from Matthias Klose  ---
also works on aarch64-linux-gnu and mips64el-linux-gnu

[Bug middle-end/113705] [14 Regression] ICE in decompose, at wide-int.h:1049 on aarch64-linux-gnu since r14-8680-g2f14c0dbb78985

2024-02-01 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113705

--- Comment #8 from Xi Ruoyao  ---
(In reply to Jakub Jelinek from comment #5)
> --- gcc/tree-ssa-math-opts.cc.jj  2024-02-01 09:14:16.623549514 +0100
> +++ gcc/tree-ssa-math-opts.cc 2024-02-01 17:48:59.151771177 +0100
> @@ -2572,7 +2572,8 @@ is_widening_mult_rhs_p (tree type, tree
> if (is_gimple_assign (stmt)
> && gimple_assign_rhs_code (stmt) == BIT_AND_EXPR
> && TREE_CODE (gimple_assign_rhs2 (stmt)) == INTEGER_CST
> -   && wi::to_wide (gimple_assign_rhs2 (stmt))
> +   && wide_int::from (wi::to_wide (gimple_assign_rhs2 (stmt)),
> +  prec, TYPE_SIGN (TREE_TYPE (rhs)))
>== wi::mask (hprec, false, prec))
>   *new_rhs_out = gimple_assign_rhs1 (stmt);
> else
> fixes the ICE.

Works for me on LoongArch.

[Bug middle-end/113705] [14 Regression] ICE in decompose, at wide-int.h:1049 on aarch64-linux-gnu since r14-8680-g2f14c0dbb78985

2024-02-01 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113705

Jakub Jelinek  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |jakub at gcc dot gnu.org
 Status|NEW |ASSIGNED

--- Comment #7 from Jakub Jelinek  ---
Created attachment 57284
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57284=edit
gcc14-pr113705.patch

Full untested patch.

[Bug middle-end/113705] [14 Regression] ICE in decompose, at wide-int.h:1049 on aarch64-linux-gnu since r14-8680-g2f14c0dbb78985

2024-02-01 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113705

Xi Ruoyao  changed:

   What|Removed |Added

 CC||xry111 at gcc dot gnu.org
 Target|aarch64-linux-gnu   |aarch64-linux-gnu,
   ||loongarch64-linux-gnu

--- Comment #6 from Xi Ruoyao  ---
Just hit this doing an experimental Linux From Scratch build with GCC 14 on
LoongArch.

[Bug middle-end/113705] [14 Regression] ICE in decompose, at wide-int.h:1049 on aarch64-linux-gnu since r14-8680-g2f14c0dbb78985

2024-02-01 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113705

--- Comment #5 from Jakub Jelinek  ---
--- gcc/tree-ssa-math-opts.cc.jj2024-02-01 09:14:16.623549514 +0100
+++ gcc/tree-ssa-math-opts.cc   2024-02-01 17:48:59.151771177 +0100
@@ -2572,7 +2572,8 @@ is_widening_mult_rhs_p (tree type, tree
  if (is_gimple_assign (stmt)
  && gimple_assign_rhs_code (stmt) == BIT_AND_EXPR
  && TREE_CODE (gimple_assign_rhs2 (stmt)) == INTEGER_CST
- && wi::to_wide (gimple_assign_rhs2 (stmt))
+ && wide_int::from (wi::to_wide (gimple_assign_rhs2 (stmt)),
+prec, TYPE_SIGN (TREE_TYPE (rhs)))
 == wi::mask (hprec, false, prec))
*new_rhs_out = gimple_assign_rhs1 (stmt);
  else
fixes the ICE.

[Bug middle-end/113705] [14 Regression] ICE in decompose, at wide-int.h:1049 on aarch64-linux-gnu since r14-8680-g2f14c0dbb78985

2024-02-01 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113705

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek  ---
Shouldn't that
wi::to_wide (gimple_assign_rhs2 (stmt))
in there be
wide_int::from (gimple_assign_rhs2 (stmt), prec, TYPE_SIGN (TREE_TYPE (rhs)))
instead?
Otherwise the ICE is obviously because wi::to_wide (gimple_assign_rhs2 (stmt))
is unsigned int 65535, while prec is 64-bit and comparing 32-bit vs. 64-bit
wide_int is not valid.

[Bug middle-end/113705] [14 Regression] ICE in decompose, at wide-int.h:1049 on aarch64-linux-gnu since r14-8680-g2f14c0dbb78985

2024-02-01 Thread acoplan at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113705

Alex Coplan  changed:

   What|Removed |Added

Summary|[14 Regression] ICE in  |[14 Regression] ICE in
   |decompose, at   |decompose, at
   |wide-int.h:1049 on  |wide-int.h:1049 on
   |aarch64-linux-gnu   |aarch64-linux-gnu since
   ||r14-8680-g2f14c0dbb78985

--- Comment #3 from Alex Coplan  ---
Started with r14-8680-g2f14c0dbb789852947cb58fdf7d3162413f053fa :

commit 2f14c0dbb789852947cb58fdf7d3162413f053fa
Author: Roger Sayle 
Date:   Thu Feb 1 06:10:42 2024

PR target/113560: Enhance is_widening_mult_rhs_p.

[Bug middle-end/113705] [14 Regression] ICE in decompose, at wide-int.h:1049 on aarch64-linux-gnu

2024-02-01 Thread mpolacek at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113705

Marek Polacek  changed:

   What|Removed |Added

   Priority|P3  |P1
 CC||mpolacek at gcc dot gnu.org

[Bug middle-end/113705] [14 Regression] ICE in decompose, at wide-int.h:1049 on aarch64-linux-gnu

2024-02-01 Thread acoplan at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113705

Alex Coplan  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
 CC||acoplan at gcc dot gnu.org
   Last reconfirmed||2024-02-01
 Ever confirmed|0   |1

--- Comment #2 from Alex Coplan  ---
Confirmed. Here is a reduced testcase that ICEs with -O2 on aarch64-linux-gnu:

void free();
template  struct generic_wide_int : storage { 
  long elt() const; 
};  
int elt_i;  
template  long generic_wide_int::elt() const {   
  return this->get_val()[elt_i];
}   
struct wide_int_storage {
  struct {
long val[0];
long valp;
  } u;
  unsigned len;
  int precision;
  wide_int_storage(const wide_int_storage &);
  ~wide_int_storage();
  const long *get_val() const;
  unsigned get_len() const;
};
wide_int_storage::wide_int_storage(const wide_int_storage &) {
  if (__builtin_expect(precision, 0))
u.valp = 0;
}
wide_int_storage::~wide_int_storage() {
  if (__builtin_expect(precision, 0))
free();
}
const long *wide_int_storage::get_val() const { return u.val; }
unsigned wide_int_storage::get_len() const { return len; }
struct irange {
  generic_wide_int upper_bound() const;
  generic_wide_int *m_base;
};
generic_wide_int irange::upper_bound() const {
  return m_base[1];
}
void set_irange() {
  irange r;
  for (unsigned i;;) {
generic_wide_int __trans_tmp_1 = r.upper_bound();
long *__trans_tmp_2;
unsigned short *len;
*len = __trans_tmp_1.get_len();
for (i = 0; i < *len; ++i)
  *__trans_tmp_2++ = __trans_tmp_1.elt();
  }
}

[Bug middle-end/113705] [14 Regression] ICE in decompose, at wide-int.h:1049 on aarch64-linux-gnu

2024-02-01 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113705

Richard Biener  changed:

   What|Removed |Added

 CC||sayle at gcc dot gnu.org
   Target Milestone|--- |14.0

[Bug middle-end/113705] [14 Regression] ICE in decompose, at wide-int.h:1049 on aarch64-linux-gnu

2024-02-01 Thread doko at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113705

--- Comment #1 from Matthias Klose  ---
Created attachment 57281
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57281=edit
preprocessed source