public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94414] New: only `--` gives constexpr
@ 2020-03-30 21:58 dmusiienko at gmail dot com
2020-03-31 7:43 ` [Bug c++/94414] " rguenth at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: dmusiienko at gmail dot com @ 2020-03-30 21:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94414
Bug ID: 94414
Summary: only `--` gives constexpr
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: dmusiienko at gmail dot com
Target Milestone: ---
x86-64 gcc (trunk)
-std=c++20 -O3
`++` - is not constexpr
`--` - is constexpr
==========================================
#include <ranges>
#include <array>
namespace rv = std::views;
int main()
{
constexpr std::array arr{5, 6, 7, 8};
auto contfilt = arr | rv::filter([](auto x){return x>5;})
| rv::transform([](auto x){return x*x;});
return *(++contfilt.begin());
}
===========================================
main:
movdqa xmm0, XMMWORD PTR .LC0[rip]
lea rax, [rsp-16]
movaps XMMWORD PTR [rsp-24], xmm0
jmp .L3
.L6:
add rax, 4
lea rdx, [rsp-8]
cmp rax, rdx
je .L2
.L3:
cmp DWORD PTR [rax], 5
jle .L6
.L2:
mov eax, DWORD PTR [rax]
imul eax, eax
ret
.LC0:
.long 5
.long 6
.long 7
.long 8
=========================================
Okay, but ...
========================================
#include <ranges>
#include <array>
namespace rv = std::views;
int main()
{
constexpr std::array arr{5, 6, 7, 8};
auto contfilt = arr | rv::filter([](auto x){return x>5;})
| rv::transform([](auto x){return x*x;});
return *(----contfilt.end());
}
========================================
main:
mov eax, 49
ret
========================================
Okay, but.....
========================================
#include <ranges>
#include <array>
namespace rv = std::views;
int main()
{
constexpr std::array arr{5, 6, 7, 8};
auto contfilt = arr | rv::filter([](auto x){return x>5;})
| rv::transform([](auto x){return x*x;});
return *(++(------contfilt.end()));
}
========================================
main:
mov eax, 49
ret
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/94414] only `--` gives constexpr
2020-03-30 21:58 [Bug c++/94414] New: only `--` gives constexpr dmusiienko at gmail dot com
@ 2020-03-31 7:43 ` rguenth at gcc dot gnu.org
2020-03-31 9:09 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-03-31 7:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94414
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
You are not actually constexpr evaluating the ++/--, instead you are seeing
missed optimizations for one case(?)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/94414] only `--` gives constexpr
2020-03-30 21:58 [Bug c++/94414] New: only `--` gives constexpr dmusiienko at gmail dot com
2020-03-31 7:43 ` [Bug c++/94414] " rguenth at gcc dot gnu.org
@ 2020-03-31 9:09 ` redi at gcc dot gnu.org
2020-03-31 15:02 ` ppalka at gcc dot gnu.org
2021-12-14 8:54 ` [Bug tree-optimization/94414] " pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2020-03-31 9:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94414
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Right, this has nothing to do with constexpr. The contfilt view is not a
constant expression, so nothing you do with it will be constant evaluated, so
whether it's constexpr is irrelevant.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/94414] only `--` gives constexpr
2020-03-30 21:58 [Bug c++/94414] New: only `--` gives constexpr dmusiienko at gmail dot com
2020-03-31 7:43 ` [Bug c++/94414] " rguenth at gcc dot gnu.org
2020-03-31 9:09 ` redi at gcc dot gnu.org
@ 2020-03-31 15:02 ` ppalka at gcc dot gnu.org
2021-12-14 8:54 ` [Bug tree-optimization/94414] " pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-03-31 15:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94414
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ppalka at gcc dot gnu.org
--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
It looks the memoization that's performed in filter_view::begin() is
interfering with optimization in the first testcase.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/94414] only `--` gives constexpr
2020-03-30 21:58 [Bug c++/94414] New: only `--` gives constexpr dmusiienko at gmail dot com
` (2 preceding siblings ...)
2020-03-31 15:02 ` ppalka at gcc dot gnu.org
@ 2021-12-14 8:54 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-14 8:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94414
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2021-12-14
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Severity|normal |enhancement
Component|c++ |tree-optimization
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
To me there looks like an unrolling not happening:
<bb 3> [local count: 1014686026]:
# __first_35 = PHI <__first_15(4), &MEM <const int[4]> [(void *)&arr +
8B](2)>
_14 = MEM[(const int &)__first_35];
if (_14 <= 5)
goto <bb 4>; [94.50%]
else
goto <bb 5>; [5.50%]
<bb 4> [local count: 958878296]:
__first_15 = __first_35 + 4;
if (&MEM <const struct array> [(void *)&arr + 16B] != __first_15)
goto <bb 3>; [94.50%]
else
goto <bb 5>; [5.50%]
But from what I can tell it is we unroll the one loop and then we can't unroll
this one until much later on. It is really interesting testcase.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-12-14 8:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-30 21:58 [Bug c++/94414] New: only `--` gives constexpr dmusiienko at gmail dot com
2020-03-31 7:43 ` [Bug c++/94414] " rguenth at gcc dot gnu.org
2020-03-31 9:09 ` redi at gcc dot gnu.org
2020-03-31 15:02 ` ppalka at gcc dot gnu.org
2021-12-14 8:54 ` [Bug tree-optimization/94414] " pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).