[Bug c++/92948] New: internal compiler error: in tsubst_copy, at cp/pt.c:15788

2019-12-15 Thread piotrsiupa at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92948

Bug ID: 92948
   Summary: internal compiler error: in tsubst_copy, at
cp/pt.c:15788
   Product: gcc
   Version: 9.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: piotrsiupa at gmail dot com
  Target Milestone: ---

Created attachment 47500
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47500&action=edit
Minimal and complete example

There is a bug in the experimental feature "non-type template parameters of
class type" in c++2a.

class Aaa
{
public:
constexpr Aaa(const int) {}
};
template
class Bbb_
{
public:
using ZZZ = unsigned;
};
template
using Bbb = Bbb_;
template::ZZZ>
int foo()
{
return 0;
}

The error is:

./crash-the-compiler.cpp: In substitution of 'template using Bbb =
Bbb_<((const Aaa)AAA)> [with Aaa AAA = ((Aaa*)(void)0)->Aaa::Aaa(XXX)]':
./crash-the-compiler.cpp:17:50:   required from here
./crash-the-compiler.cpp:15:18: internal compiler error: in tsubst_copy, at
cp/pt.c:15788
   15 | using Bbb = Bbb_;
  |  ^~~
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.

The bug seems to be pretty consistent on different versions of GCC.
I've found it in 9.2.0 but I can reproduce it in 9.1.0 and every 10.0.0 version
that I've found on https://godbolt.org/.
Even avr-g++ has the same exact problem.

[Bug tree-optimization/90693] Missing popcount simplifications

2024-01-01 Thread piotrsiupa at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90693

Piotr Siupa  changed:

   What|Removed |Added

 CC||piotrsiupa at gmail dot com

--- Comment #8 from Piotr Siupa  ---
I did a benchmark and (x & (x-1)) == 0 and it seems to be about 2x as fast as
the currently generated code (at least on my AMD64 processor).

Maybe it should be used if x is guaranteed to not be zero, e.g. if (x == 0)
std::unreachable().

[Bug tree-optimization/90693] Missing popcount simplifications

2024-01-07 Thread piotrsiupa at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90693

--- Comment #11 from Piotr Siupa  ---
Thanks! Now the generated assembly is one instruction shorter.

It works for:
bool foo(unsigned x)
{
[[assume(x != 0)]];
return std::has_single_bit(x);
}
and for:
bool foo(unsigned x)
{
if (x == 0)
std::unreachable();
else
return std::has_single_bit(x);
}

However, I've noticed that:
bool foo(unsigned x)
{
if (x == 0)
return true;
else
return std::has_single_bit(x);
}
still uses (X ^ (X - 1)) > (X - 1).