[Bug tree-optimization/112941] during GIMPLE pass: bitintlower ICE: in handle_operand_addr, at gimple-lower-bitint.cc:2126 (gimple-lower-bitint.cc:2134) at -O with _BitInt()

2024-01-20 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112941

Andrew Pinski  changed:

   What|Removed |Added

   Target Milestone|--- |14.0

[Bug tree-optimization/112941] during GIMPLE pass: bitintlower ICE: in handle_operand_addr, at gimple-lower-bitint.cc:2126 (gimple-lower-bitint.cc:2134) at -O with _BitInt()

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

Jakub Jelinek  changed:

   What|Removed |Added

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

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

[Bug tree-optimization/112941] during GIMPLE pass: bitintlower ICE: in handle_operand_addr, at gimple-lower-bitint.cc:2126 (gimple-lower-bitint.cc:2134) at -O with _BitInt()

2023-12-22 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112941

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

https://gcc.gnu.org/g:0a6aa1927597d821a85bc3d1fd7682256c25b548

commit r14-6805-g0a6aa1927597d821a85bc3d1fd7682256c25b548
Author: Jakub Jelinek 
Date:   Fri Dec 22 12:28:54 2023 +0100

symtab-thunks: Use aggregate_value_p even on is_gimple_reg_type returns
[PR112941]

Large/huge _BitInt types are returned in memory and the bitint lowering
pass right now relies on that.
The gimplification etc. use aggregate_value_p to see if it should be
returned in memory or not and use
   = _123;
  return ;
rather than
  return _123;
But expand_thunk used e.g. by IPA-ICF was performing an optimization,
assuming is_gimple_reg_type is always passed in registers and not calling
aggregate_value_p in that case.  The following patch changes it to match
what the gimplification etc. are doing.

2023-12-22  Jakub Jelinek  

PR tree-optimization/112941
* symtab-thunks.cc (expand_thunk): Check aggregate_value_p
regardless
of whether is_gimple_reg_type (restype) or not.

* gcc.dg/bitint-60.c: New test.

[Bug tree-optimization/112941] during GIMPLE pass: bitintlower ICE: in handle_operand_addr, at gimple-lower-bitint.cc:2126 (gimple-lower-bitint.cc:2134) at -O with _BitInt()

2023-12-21 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112941

--- Comment #11 from Jakub Jelinek  ---
Created attachment 56920
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56920=edit
gcc14-pr112941-thunk.patch

Untested patch for the #c6 ICE.

[Bug tree-optimization/112941] during GIMPLE pass: bitintlower ICE: in handle_operand_addr, at gimple-lower-bitint.cc:2126 (gimple-lower-bitint.cc:2134) at -O with _BitInt()

2023-12-21 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112941

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

https://gcc.gnu.org/g:3d1bdbf64c2ed5be70fbff687b2927e328297b81

commit r14-6777-g3d1bdbf64c2ed5be70fbff687b2927e328297b81
Author: Jakub Jelinek 
Date:   Thu Dec 21 11:13:42 2023 +0100

lower-bitint: Avoid nested casts in muldiv/float operands [PR112941]

Multiplication/division/modulo/float operands are handled by libgcc calls
and so need to be passed as array of limbs with precision argument,
using handle_operand_addr.  That code can't deal with more than one cast,
so the following patch avoids merging those cases.
.MUL_OVERFLOW calls use the same code, but we don't actually try to merge
the operands in that case already.

2023-12-21  Jakub Jelinek  

PR tree-optimization/112941
* gimple-lower-bitint.cc (gimple_lower_bitint): Disallow merging
a cast with multiplication, division or conversion to floating
point
if rhs1 of the cast is result of another single use cast in the
same
bb.

* gcc.dg/bitint-56.c: New test.
* gcc.dg/bitint-57.c: New test.

[Bug tree-optimization/112941] during GIMPLE pass: bitintlower ICE: in handle_operand_addr, at gimple-lower-bitint.cc:2126 (gimple-lower-bitint.cc:2134) at -O with _BitInt()

2023-12-20 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112941

--- Comment #9 from Jakub Jelinek  ---
*** Bug 113015 has been marked as a duplicate of this bug. ***

[Bug tree-optimization/112941] during GIMPLE pass: bitintlower ICE: in handle_operand_addr, at gimple-lower-bitint.cc:2126 (gimple-lower-bitint.cc:2134) at -O with _BitInt()

2023-12-20 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112941

Jakub Jelinek  changed:

   What|Removed |Added

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

--- Comment #8 from Jakub Jelinek  ---
Created attachment 56910
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56910=edit
gcc14-pr112941-mul.patch

Patch to punt merging of nested casts in mul/div/mod/float operands.

[Bug tree-optimization/112941] during GIMPLE pass: bitintlower ICE: in handle_operand_addr, at gimple-lower-bitint.cc:2126 (gimple-lower-bitint.cc:2134) at -O with _BitInt()

2023-12-20 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112941

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

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

commit r14-6742-gbe9e8de628471399ee5abb1e6ba7738139256b67
Author: Jakub Jelinek 
Date:   Wed Dec 20 11:32:52 2023 +0100

lower-bitint: Fix up handling of nested casts in mergeable stmt handling
[PR112941]

The following patch fixes 2 issues in handling of casts for mergeable
stmts.
The first hunk fixes the case when we have two nested casts (typically
after optimization that is zero-extension of a sign-extension because
everything else should have been folded into a single cast).  If
the lowering of the outer cast needs to make the code conditional
(e.g.
  for (...)
{
  if (idx <= 32)
{
  if (idx < 32)
{ ... handle_operand (idx); ... }
  else
{ ... handle_operand (32); ... }
}
  ...
}
) and the lowering of the inner one as well, right now it creates invalid
SSA form, because even for the inner cast we need a PHI on the loop
and the PHI argument from the latch edge is a SSA_NAME initialized in
the conditionally executed bb.  The hunk fixes that by detecting such
a case and adding further PHI nodes at the end of the ifs such that
the right value propagates to the next loop iteration.  We can use
0 arguments for the other edges because the inner operand handling
is only done for the first set of iterations and then the other ifs take
over.

The rest fixes a case of again invalid SSA form, when for a sign extension
we need to use the 0 or -1 value initialized by earlier iteration in
a constant idx case, the code was using the value of the loop PHI argument
from latch edge rather than result; that is correct for cases expanded
in straight line code after the loop, but not inside of the loop for the
cases of handle_cast conditionals, there we should use PHI result.  This
is done in the second hunk and supported by the remaining hunks, where
it clears m_bb to tell the code we aren't in the loop anymore.

Note, this patch doesn't deal with similar problems during multiplication,
division, floating casts etc. where we just emit a library call.  I'll
need to make sure in that case we don't merge more than one cast per
operand.

2023-12-20  Jakub Jelinek  

PR tree-optimization/112941
* gimple-lower-bitint.cc (bitint_large_huge::handle_cast): If
save_cast_conditional, instead of adding assignment of t4 to
m_data[save_data_cnt + 1] before m_gsi, add phi nodes such that
t4 propagates to m_bb loop.  For constant idx, use
m_data[save_data_cnt] rather than m_data[save_data_cnt + 1] if
inside
of the m_bb loop.
(bitint_large_huge::lower_mergeable_stmt): Clear m_bb when no
longer
expanding inside of that loop.
(bitint_large_huge::lower_comparison_stmt): Likewise.
(bitint_large_huge::lower_addsub_overflow): Likewise.
(bitint_large_huge::lower_mul_overflow): Likewise.
(bitint_large_huge::lower_bit_query): Likewise.

* gcc.dg/bitint-55.c: New test.

[Bug tree-optimization/112941] during GIMPLE pass: bitintlower ICE: in handle_operand_addr, at gimple-lower-bitint.cc:2126 (gimple-lower-bitint.cc:2134) at -O with _BitInt()

2023-12-15 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112941

--- Comment #6 from Jakub Jelinek  ---
And another testcase which ICEs:
unsigned _BitInt(495) f1 (signed _BitInt(381) x) { unsigned _BitInt(539) y = x;
return y; }
unsigned _BitInt(495) f2 (unsigned _BitInt(381) x) { unsigned _BitInt(539) y =
x; return y; }
unsigned _BitInt(495) f3 (signed _BitInt(381) x) { _BitInt(539) y = x; return
y; }
unsigned _BitInt(495) f4 (unsigned _BitInt(381) x) { _BitInt(539) y = x; return
y; }
_BitInt(495) f5 (signed _BitInt(381) x) { unsigned _BitInt(539) y = x; return
y; }
_BitInt(495) f6 (unsigned _BitInt(381) x) { unsigned _BitInt(539) y = x; return
y; }
_BitInt(495) f7 (signed _BitInt(381) x) { _BitInt(539) y = x; return y; }
_BitInt(495) f8 (unsigned _BitInt(381) x) { _BitInt(539) y = x; return y; }
unsigned _BitInt(495) f9 (signed _BitInt(381) x) { return (unsigned
_BitInt(539)) x; }
unsigned _BitInt(495) f10 (unsigned _BitInt(381) x) { return (unsigned
_BitInt(539)) x; }
unsigned _BitInt(495) f11 (signed _BitInt(381) x) { return (_BitInt(539)) x; }
unsigned _BitInt(495) f12 (unsigned _BitInt(381) x) { return (_BitInt(539)) x;
}
_BitInt(495) f13 (signed _BitInt(381) x) { return (unsigned _BitInt(539)) x; }
_BitInt(495) f14 (unsigned _BitInt(381) x) { return (unsigned _BitInt(539)) x;
}
_BitInt(495) f15 (signed _BitInt(381) x) { return (_BitInt(539)) x; }
_BitInt(495) f16 (unsigned _BitInt(381) x) { return (_BitInt(539)) x; }

[Bug tree-optimization/112941] during GIMPLE pass: bitintlower ICE: in handle_operand_addr, at gimple-lower-bitint.cc:2126 (gimple-lower-bitint.cc:2134) at -O with _BitInt()

2023-12-15 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112941

--- Comment #5 from Jakub Jelinek  ---
Testcase covering various cases where 2 consecutive casts can't be optimized
away.
This ICEs in multiple ways as well:
void
f1 (_BitInt(4096) *p, int r, _BitInt(115) s, _BitInt(128) t, _BitInt(231) u)
{
  p[0] += (unsigned _BitInt(2048)) r;
  p[1] += (unsigned _BitInt(2048)) s;
  p[2] += (unsigned _BitInt(2048)) t;
  p[3] += (unsigned _BitInt(2048)) u;
}

void
f2 (_BitInt(4096) *p, int r, _BitInt(115) s, _BitInt(128) t, _BitInt(231) u)
{
  p[0] *= (unsigned _BitInt(2048)) r;
  p[1] *= (unsigned _BitInt(2048)) s;
  p[2] *= (unsigned _BitInt(2048)) t;
  p[3] *= (unsigned _BitInt(2048)) u;
}

void
f3 (_BitInt(4096) *p, int r, _BitInt(115) s, _BitInt(128) t, _BitInt(231) u)
{
  p[0] += (unsigned _BitInt(2110)) r;
  p[1] += (unsigned _BitInt(2110)) s;
  p[2] += (unsigned _BitInt(2110)) t;
  p[3] += (unsigned _BitInt(2110)) u;
}

void
f4 (_BitInt(4096) *p, int r, _BitInt(115) s, _BitInt(128) t, _BitInt(231) u)
{
  p[0] *= (unsigned _BitInt(2110)) r;
  p[1] *= (unsigned _BitInt(2110)) s;
  p[2] *= (unsigned _BitInt(2110)) t;
  p[3] *= (unsigned _BitInt(2110)) u;
}

void
f5 (unsigned _BitInt(4096) *p, int r, _BitInt(115) s, _BitInt(128) t,
_BitInt(231) u)
{
  p[0] += (unsigned _BitInt(2048)) r;
  p[1] += (unsigned _BitInt(2048)) s;
  p[2] += (unsigned _BitInt(2048)) t;
  p[3] += (unsigned _BitInt(2048)) u;
}

void
f6 (unsigned _BitInt(4096) *p, int r, _BitInt(115) s, _BitInt(128) t,
_BitInt(231) u)
{
  p[0] *= (unsigned _BitInt(2048)) r;
  p[1] *= (unsigned _BitInt(2048)) s;
  p[2] *= (unsigned _BitInt(2048)) t;
  p[3] *= (unsigned _BitInt(2048)) u;
}

void
f7 (unsigned _BitInt(4096) *p, int r, _BitInt(115) s, _BitInt(128) t,
_BitInt(231) u)
{
  p[0] += (unsigned _BitInt(2110)) r;
  p[1] += (unsigned _BitInt(2110)) s;
  p[2] += (unsigned _BitInt(2110)) t;
  p[3] += (unsigned _BitInt(2110)) u;
}

void
f8 (unsigned _BitInt(4096) *p, int r, _BitInt(115) s, _BitInt(128) t,
_BitInt(231) u)
{
  p[0] *= (unsigned _BitInt(2110)) r;
  p[1] *= (unsigned _BitInt(2110)) s;
  p[2] *= (unsigned _BitInt(2110)) t;
  p[3] *= (unsigned _BitInt(2110)) u;
}

#if __SIZEOF_INT128__
void
f9 (_BitInt(4096) *p, __int128 r)
{
  p[0] += (unsigned _BitInt(2048)) r;
}

void
f10 (_BitInt(4096) *p, __int128 r)
{
  p[0] *= (unsigned _BitInt(2048)) r;
}

void
f11 (_BitInt(4096) *p, __int128 r)
{
  p[0] += (unsigned _BitInt(2110)) r;
}

void
f12 (_BitInt(4096) *p, __int128 r)
{
  p[0] *= (unsigned _BitInt(2110)) r;
}

void
f13 (unsigned _BitInt(4096) *p, __int128 r)
{
  p[0] += (unsigned _BitInt(2048)) r;
}

void
f14 (unsigned _BitInt(4096) *p, __int128 r)
{
  p[0] *= (unsigned _BitInt(2048)) r;
}

void
f15 (unsigned _BitInt(4096) *p, __int128 r)
{
  p[0] += (unsigned _BitInt(2110)) r;
}

void
f16 (unsigned _BitInt(4096) *p, __int128 r)
{
  p[0] *= (unsigned _BitInt(2110)) r;
}
#endif

[Bug tree-optimization/112941] during GIMPLE pass: bitintlower ICE: in handle_operand_addr, at gimple-lower-bitint.cc:2126 (gimple-lower-bitint.cc:2134) at -O with _BitInt()

2023-12-15 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112941

--- Comment #4 from Jakub Jelinek  ---
And after the PR113024 changes, one needs -O1 -fno-tree-forwprop on:
unsigned _BitInt(2049)
foo (unsigned _BitInt(6384) x, _BitInt(8) y)
{
  unsigned _BitInt(6384) z = y;
  return x * z;
}

_BitInt(2049)
bar (unsigned _BitInt(6384) x, _BitInt(1023) y)
{
  unsigned _BitInt(6384) z = y;
  return x * z;
}
to reproduce it.

[Bug tree-optimization/112941] during GIMPLE pass: bitintlower ICE: in handle_operand_addr, at gimple-lower-bitint.cc:2126 (gimple-lower-bitint.cc:2134) at -O with _BitInt()

2023-12-14 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112941

--- Comment #3 from Jakub Jelinek  ---
Simplified:
unsigned _BitInt(2049)
foo (unsigned _BitInt(6384) x, _BitInt(8) y)
{
  return x * y;
}

_BitInt(2049)
bar (unsigned _BitInt(6384) x, _BitInt(1023) y)
{
  return x * y;
}

[Bug tree-optimization/112941] during GIMPLE pass: bitintlower ICE: in handle_operand_addr, at gimple-lower-bitint.cc:2126 (gimple-lower-bitint.cc:2134) at -O with _BitInt()

2023-12-13 Thread zsojka at seznam dot cz via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112941

--- Comment #2 from Zdenek Sojka  ---
(In reply to Andrew Pinski from comment #1)
> Confirmed.
> 
> Slightly more reduced:
> ```
> _BitInt (2049) b2049;
> unsigned _BitInt (6384) b16384;
> 
> void
> foo (signed char t)
> {
>   b2049 = b16384 * t;
> }
> 
> ```

Thank you for the further reduction.
In the original testcase, foo() and bar() trigger different ICE ( :2126 and
:2134 )

[Bug tree-optimization/112941] during GIMPLE pass: bitintlower ICE: in handle_operand_addr, at gimple-lower-bitint.cc:2126 (gimple-lower-bitint.cc:2134) at -O with _BitInt()

2023-12-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112941

Andrew Pinski  changed:

   What|Removed |Added

 Ever confirmed|0   |1
   Last reconfirmed||2023-12-09
 Status|UNCONFIRMED |NEW

--- Comment #1 from Andrew Pinski  ---
Confirmed.

Slightly more reduced:
```
_BitInt (2049) b2049;
unsigned _BitInt (6384) b16384;

void
foo (signed char t)
{
  b2049 = b16384 * t;
}

```