public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ipa/100801] New: Aggressive loop optimizations cause incorrect warning
@ 2021-05-27 14:03 jl_gccbugs at conductive dot de
2021-05-28 10:54 ` [Bug tree-optimization/100801] " rguenth at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: jl_gccbugs at conductive dot de @ 2021-05-27 14:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100801
Bug ID: 100801
Summary: Aggressive loop optimizations cause incorrect warning
Product: gcc
Version: 11.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ipa
Assignee: unassigned at gcc dot gnu.org
Reporter: jl_gccbugs at conductive dot de
CC: marxin at gcc dot gnu.org
Target Milestone: ---
The following warning is triggered
> $ gcc-11 -c constproploopopt.c -O2 -Wall -mavx -g
> constproploopopt.c: In function ‘test’:
> constproploopopt.c:22:18: warning: iteration 4611686018427387903 invokes undefined behavior [-Waggressive-loop-optimizations]
> 22 | dest[i] = src[i];
> | ^
> constproploopopt.c:21:12: note: within this loop
> 21 | for (; i < count; ++i) { // handle residual elements
> | ~~^~~~~~~
by this (minimal) code:
> #include <stdint.h>
> #include <stdio.h>
> #if defined(_MSC_VER)
> #include <intrin.h>
> #else
> #include <x86intrin.h>
> #endif
>
> void copy_32_unaligned(uint32_t* dest, const uint32_t* src, size_t count) {
> // invariant/nop
> __m128i shufmask = _mm_set_epi8(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
>
> size_t i;
> for (i = 0; i + 4 <= count; i += 4) {
> __m128i input = _mm_loadu_si128((const __m128i*)(&src[i]));
> __m128i output = input;
> // no warning without the shuffle:
> output = _mm_shuffle_epi8(input, shufmask);
> _mm_storeu_si128((__m128i*)(&dest[i]), output);
> }
> for (; i < count; ++i) { // handle residual elements
> dest[i] = src[i];
> }
> }
>
> void test(uint32_t* buf1, uint32_t* buf2) {
> copy_32_unaligned(buf2, buf1,
> // multiples of 4 and greater or equal then 12 trigger it:
> 12);
> }
>From objdump output I believe the generated code is correct though. The warning
seems to be incorrect in this context, especially since the "residual" loop
should be skipped for count=n*4 anyways.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/100801] Aggressive loop optimizations cause incorrect warning
2021-05-27 14:03 [Bug ipa/100801] New: Aggressive loop optimizations cause incorrect warning jl_gccbugs at conductive dot de
@ 2021-05-28 10:54 ` rguenth at gcc dot gnu.org
2021-05-28 12:45 ` jl_gccbugs at conductive dot de
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-05-28 10:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100801
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|ipa |tree-optimization
Keywords| |diagnostic,
| |missed-optimization
Status|UNCONFIRMED |ASSIGNED
Ever confirmed|0 |1
Last reconfirmed| |2021-05-28
Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed. We're warning on the obviously unreachable loop since:
<bb 4> [local count: 1073741824]:
_35 = 12;
if (_35 != 12)
goto <bb 7>; [75.00%]
else
goto <bb 6>; [25.00%]
$3 = <basic_block 0x7ffff434b680 (4)>
since we apply final value replacement to 'i' in sccp but do not propagate it
before the next number of iteration analysis in ivcanon:
NEXT_PASS (pass_tree_loop_init);
NEXT_PASS (pass_tree_unswitch);
NEXT_PASS (pass_scev_cprop); <<<< final value repl.
NEXT_PASS (pass_loop_split);
NEXT_PASS (pass_loop_versioning);
NEXT_PASS (pass_loop_jam);
/* All unswitching, final value replacement and splitting can expose
empty loops. Remove them now. */
NEXT_PASS (pass_cd_dce, false /* update_address_taken_p */);
NEXT_PASS (pass_iv_canon); <<<<< warning
NEXT_PASS (pass_loop_distribution);
NEXT_PASS (pass_linterchange);
NEXT_PASS (pass_copy_prop); <<<<<< propagation
IIRC final value replacement used to propagate and fold but I(?) removed this
at some point.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/100801] Aggressive loop optimizations cause incorrect warning
2021-05-27 14:03 [Bug ipa/100801] New: Aggressive loop optimizations cause incorrect warning jl_gccbugs at conductive dot de
2021-05-28 10:54 ` [Bug tree-optimization/100801] " rguenth at gcc dot gnu.org
@ 2021-05-28 12:45 ` jl_gccbugs at conductive dot de
2021-07-31 0:41 ` matthijsvanduin at gmail dot com
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: jl_gccbugs at conductive dot de @ 2021-05-28 12:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100801
--- Comment #2 from Joel Linn <jl_gccbugs at conductive dot de> ---
Great. In the meantime I will use
> if (count % 4 == 0) __builtin_unreachable();
at the start of the for loop to suppress the warning as suggested by Martin
Sebor https://gcc.gnu.org/pipermail/gcc-help/2021-May/140339.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/100801] Aggressive loop optimizations cause incorrect warning
2021-05-27 14:03 [Bug ipa/100801] New: Aggressive loop optimizations cause incorrect warning jl_gccbugs at conductive dot de
2021-05-28 10:54 ` [Bug tree-optimization/100801] " rguenth at gcc dot gnu.org
2021-05-28 12:45 ` jl_gccbugs at conductive dot de
@ 2021-07-31 0:41 ` matthijsvanduin at gmail dot com
2021-12-20 0:55 ` [Bug tree-optimization/100801] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: matthijsvanduin at gmail dot com @ 2021-07-31 0:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100801
Matthijs van Duin <matthijsvanduin at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |matthijsvanduin at gmail dot com
--- Comment #3 from Matthijs van Duin <matthijsvanduin at gmail dot com> ---
Simpler testcase:
/* compiler flags required to trigger warning: -O1 -ftree-vrp */
static void foo(int *x, long n)
{
long i = 0;
for (; i + 4 <= n; i += 4) {
}
for (; i < n; i++) {
x[i]++;
}
}
void bar(int *x)
{
foo(x, 128);
}
A workaround with no runtime overhead is adding the following check between the
loops:
if (__builtin_constant_p(n % 4 == 0) && n % 4 == 0)
return;
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/100801] [9/10/11/12 Regression] Aggressive loop optimizations cause incorrect warning
2021-05-27 14:03 [Bug ipa/100801] New: Aggressive loop optimizations cause incorrect warning jl_gccbugs at conductive dot de
` (2 preceding siblings ...)
2021-07-31 0:41 ` matthijsvanduin at gmail dot com
@ 2021-12-20 0:55 ` pinskia at gcc dot gnu.org
2022-01-05 14:29 ` rguenth at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-20 0:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100801
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Aggressive loop |[9/10/11/12 Regression]
|optimizations cause |Aggressive loop
|incorrect warning |optimizations cause
| |incorrect warning
Known to fail| |10.1.0, 9.1.0
Target Milestone|--- |9.5
Known to work| |8.5.0
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note the warning started in GCC 9 even. So it is a regression.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/100801] [9/10/11/12 Regression] Aggressive loop optimizations cause incorrect warning
2021-05-27 14:03 [Bug ipa/100801] New: Aggressive loop optimizations cause incorrect warning jl_gccbugs at conductive dot de
` (3 preceding siblings ...)
2021-12-20 0:55 ` [Bug tree-optimization/100801] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org
@ 2022-01-05 14:29 ` rguenth at gcc dot gnu.org
2022-05-27 9:45 ` [Bug tree-optimization/100801] [10/11/12/13 " rguenth at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-05 14:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100801
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/100801] [10/11/12/13 Regression] Aggressive loop optimizations cause incorrect warning
2021-05-27 14:03 [Bug ipa/100801] New: Aggressive loop optimizations cause incorrect warning jl_gccbugs at conductive dot de
` (4 preceding siblings ...)
2022-01-05 14:29 ` rguenth at gcc dot gnu.org
@ 2022-05-27 9:45 ` rguenth at gcc dot gnu.org
2022-06-28 10:45 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-27 9:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100801
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|9.5 |10.4
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9 branch is being closed
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/100801] [10/11/12/13 Regression] Aggressive loop optimizations cause incorrect warning
2021-05-27 14:03 [Bug ipa/100801] New: Aggressive loop optimizations cause incorrect warning jl_gccbugs at conductive dot de
` (5 preceding siblings ...)
2022-05-27 9:45 ` [Bug tree-optimization/100801] [10/11/12/13 " rguenth at gcc dot gnu.org
@ 2022-06-28 10:45 ` jakub at gcc dot gnu.org
2023-07-07 10:40 ` [Bug tree-optimization/100801] [11/12/13/14 " rguenth at gcc dot gnu.org
2024-03-11 3:42 ` [Bug tree-optimization/100801] [11/12 " law at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-28 10:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100801
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|10.4 |10.5
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/100801] [11/12/13/14 Regression] Aggressive loop optimizations cause incorrect warning
2021-05-27 14:03 [Bug ipa/100801] New: Aggressive loop optimizations cause incorrect warning jl_gccbugs at conductive dot de
` (6 preceding siblings ...)
2022-06-28 10:45 ` jakub at gcc dot gnu.org
@ 2023-07-07 10:40 ` rguenth at gcc dot gnu.org
2024-03-11 3:42 ` [Bug tree-optimization/100801] [11/12 " law at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100801
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|10.5 |11.5
--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 branch is being closed.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/100801] [11/12 Regression] Aggressive loop optimizations cause incorrect warning
2021-05-27 14:03 [Bug ipa/100801] New: Aggressive loop optimizations cause incorrect warning jl_gccbugs at conductive dot de
` (7 preceding siblings ...)
2023-07-07 10:40 ` [Bug tree-optimization/100801] [11/12/13/14 " rguenth at gcc dot gnu.org
@ 2024-03-11 3:42 ` law at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-11 3:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100801
Jeffrey A. Law <law at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |law at gcc dot gnu.org
Summary|[11/12/13/14 Regression] |[11/12 Regression]
|Aggressive loop |Aggressive loop
|optimizations cause |optimizations cause
|incorrect warning |incorrect warning
--- Comment #8 from Jeffrey A. Law <law at gcc dot gnu.org> ---
Works with gcc-13 and the trunk. Adjusting markers.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-03-11 3:42 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-27 14:03 [Bug ipa/100801] New: Aggressive loop optimizations cause incorrect warning jl_gccbugs at conductive dot de
2021-05-28 10:54 ` [Bug tree-optimization/100801] " rguenth at gcc dot gnu.org
2021-05-28 12:45 ` jl_gccbugs at conductive dot de
2021-07-31 0:41 ` matthijsvanduin at gmail dot com
2021-12-20 0:55 ` [Bug tree-optimization/100801] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org
2022-01-05 14:29 ` rguenth at gcc dot gnu.org
2022-05-27 9:45 ` [Bug tree-optimization/100801] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:45 ` jakub at gcc dot gnu.org
2023-07-07 10:40 ` [Bug tree-optimization/100801] [11/12/13/14 " rguenth at gcc dot gnu.org
2024-03-11 3:42 ` [Bug tree-optimization/100801] [11/12 " law 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).