[Bug rtl-optimization/85605] Potentially missing optimization under x64 and ARM: seemingly unnecessary branch in codegen
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85605 --- Comment #1 from sergey.ignatchenko at ithare dot com --- Command line switches (see also Godbolt link above): -O3 -fomit-frame-pointer
[Bug rtl-optimization/85605] New: Potentially missing optimization under x64 and ARM: seemingly unnecessary branch in codegen
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85605 Bug ID: 85605 Summary: Potentially missing optimization under x64 and ARM: seemingly unnecessary branch in codegen Product: gcc Version: 7.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: sergey.ignatchenko at ithare dot com Target Milestone: --- Code: == #include #include template inline bool cmp(T a, T2 b) { return a<0 ? true : T2(a) < b; } template inline bool cmp2(T a, T2 b) { return (a<0) | (T2(a) < b); } bool f(int a, int b) { return cmp(int64_t(a), unsigned(b)); } bool f2(int a, int b) { return cmp2(int64_t(a), unsigned(b)); } Functions cmp and cmp2 seem to be equivalent (at least under "as if" rule, as side effects of reading and casting are non-observable). However, under GCC/x64, cmp() generates code with branch, while seemingly-equivalent cmp2() - manages to do without branching: === f(int, int): testl %edi, %edi movl $1, %eax js .L1 cmpl %edi, %esi seta %al .L1: rep ret f2(int, int): movl %edi, %edx shrl $31, %edx cmpl %edi, %esi seta %al orl %edx, %eax ret === And f2() is expected to be significantly faster than f1() in most usage scenarios (*NB: if you feel it is necessary to create a case to illustrate detriment of branching - please LMK, but hopefully it is quite obvious*). Per Godbolt, similar behavior is observed under both GCC/x64, and GCC/ARM; however, Clang manages to do without branching both for f1() and f2(). *Godbolt link*: https://godbolt.org/g/ktovvP
[Bug c++/84463] Supposedly-incompliant "error: '* key0' is not a constant expression"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84463 --- Comment #1 from sergey.ignatchenko at ithare dot com --- oops, forgot to mention command line: g++ -std=c++1z -lstdc++ -Werror ../chachatest.cpp where chachatest.cpp is provided in "CODE" section above
[Bug c++/84463] New: Supposedly-incompliant "error: '* key0' is not a constant expression"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84463 Bug ID: 84463 Summary: Supposedly-incompliant "error: '* key0' is not a constant expression" Product: gcc Version: 7.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sergey.ignatchenko at ithare dot com Target Milestone: --- == COMPILER == root@ubuntu-gcc7:~/ithare/kscope/test/nix# g++ --version g++ (Ubuntu 7.2.0-8ubuntu3) 7.2.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. == CODE #include #include struct chacha_tv { const char *desc; const uint8_t key[32]; const uint8_t iv[8]; const size_t len; const unsigned char out[512]; }; static constexpr chacha_tv chacha_test_vectors[] = { { "TC1: All zero key and IV", { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, 64, { 0x76, 0xb8, 0xe0, 0xad, 0xa0, 0xf1, 0x3d, 0x90, 0x40, 0x5d, 0x6a, 0xe5, 0x53, 0x86, 0xbd, 0x28, 0xbd, 0xd2, 0x19, 0xb8, 0xa0, 0x8d, 0xed, 0x1a, 0xa8, 0x36, 0xef, 0xcc, 0x8b, 0x77, 0x0d, 0xc7, 0xda, 0x41, 0x59, 0x7c, 0x51, 0x57, 0x48, 0x8d, 0x77, 0x24, 0xe0, 0x3f, 0xb8, 0xd8, 0x4a, 0x37, 0x6a, 0x43, 0xb8, 0xf4, 0x15, 0x18, 0xa1, 0x1c, 0xc3, 0x87, 0xb6, 0x69, 0xb2, 0xee, 0x65, 0x86, }, }, }; constexpr int KSCOPE_CT_Chacha_set_key_iv2(const uint8_t* key0, int keybits /*128 or 256*/, const uint8_t iv0[8], const uint8_t counter0[8]) { uint8_t c = key0[0]; return 0; } constexpr static const chacha_tv* tv = _test_vectors[0]; constexpr static const int k = tv->key[0]; constexpr static uint8_t kk[3] = {0,1,2}; constexpr static int x0 = KSCOPE_CT_Chacha_set_key_iv2(chacha_test_vectors[0].key,256,tv->iv,nullptr);//OK constexpr static int x1 = KSCOPE_CT_Chacha_set_key_iv2(kk,256,tv->iv,nullptr);//OK constexpr static int x2 = KSCOPE_CT_Chacha_set_key_iv2(tv->key,256,tv->iv,nullptr); == PROBLEM When trying to compile the code above with GCC 7.2, the following error is generated: ../chachatest.cpp:50:55: in constexpr expansion of 'KSCOPE_CT_Chacha_set_key_i v2(((const uint8_t*)(((const uint8_t (*)[32])tv) + 8)), 256, ((const uint8_t*)(( (const uint8_t (*)[8])tv) + 40)), 0)' ../chachatest.cpp:41:27: error: '* key0' is not a constant expression uint8_t c = key0[0]; Expected behaviour is to acknowledge that key0 is an 'address constant expression' in a sense of 5.19 (at least my humble reading of the standard says that it is), and to allow the code to be compiled. Notes: - note that both x0 and x1 compile ok - both Clang and MSVC seem to agree it is an 'address constant expression' and don't complain.
[Bug c++/84401] New: Misleading error message when running out of RAM
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84401 Bug ID: 84401 Summary: Misleading error message when running out of RAM Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sergey.ignatchenko at ithare dot com Target Milestone: --- Whenever GCC consumes too much RAM (="the box doesn't have enough RAM to compile whatever-is-necessary-to-compile"), GCC is likely to be sent SIGKILL; it leads to an error message along the following lines: g++: internal compiler error: Killed (program cc1plus) Please submit a full bug report, with preprocessed source if appropriate. See for instructions. This message is (a) not really helpful for the developer, and (b) causes quite a few non-bugs to be submitted (such as https://gcc.gnu.org/bugzilla/show_bug.cgi?id=34882, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36665, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61860 , https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30615 , https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71671 , https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80434 , https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30615, etc. ). While there is no _guarantee_ that SIGKILL is caused by lack of RAM, this seems to be the most likely case by far, so simply adjusting the message (just for SIGKILL) to the following, would improve quality-of-life both for devs-using-GCC (who will know what they should do right away), and for GCC devs (who won't need to deal with non-bug reports): g++: internal compiler error: Killed (program cc1plus) This error is often caused by lack of RAM on your computer, PLEASE CHECK THAT YOU DIDN'T RAN OUT OF RAM FIRST. If it is not the case, please submit a full bug report, with preprocessed source if appropriate. See for instructions.
[Bug c++/47488] sorry, unimplemented: string literal in function template signature
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47488 sergey.ignatchenko at ithare dot com changed: What|Removed |Added CC||sergey.ignatchenko at ithare dot c ||om --- Comment #12 from sergey.ignatchenko at ithare dot com --- FWIW, the same test case still fails under GCC 7.2.0. Moreover, I ran into something-very-similar when playing with constexpr-function-of-string-literal-as-a-template-parameter; IMO, with advent of C++17 and constexpr functions this bug started to be significantly more important - please consider raising priority. Oh, and it does compile under Clang (at least Apple Clang 9.0.0).