On 5/22/21 5:19 PM, Joel Linn via Gcc-help wrote:
Hello,
we are in the process of making our project GCC compatible.
With LTO enabled, linking takes remarkably long and these warnings show:
../src/xenia/base/memory.h: In function ‘copy_and_swap.constprop’:
../src/xenia/base/memory.cc:105: warning: iteration
4611686018427387903 invokes undefined behavior
[-Waggressive-loop-optimizations]
105 | dest[i] = byte_swap(src[i]);
|
../src/xenia/base/memory.cc:104: note: within this loop
104 | for (; i < count; ++i) { // handle residual elements
|
../src/xenia/base/memory.cc:124: warning: iteration
4611686018427387903 invokes undefined behavior
[-Waggressive-loop-optimizations]
124 | dest[i] = byte_swap(src[i]);
|
../src/xenia/base/memory.cc:123: note: within this loop
123 | for (; i < count; ++i) { // handle residual elements
|
It's the first time we see an issue with these functions. They include
vector intrinsics.
How can I debug this issue? How to get the stack trace of the call GCC
is trying to optimize?
Most likely the loop is being unrolled beyond its upper limit. It
can happen even though the unrolled code is in reality unreachable.
If you know the hard limit hardcoding it in the form of an assertion
(e.g., if (count > HARD_UPPER_LIMIT) __builtin_unreachable ()) should
avoid the warning.
GCC should print the inlining stack in the warning but it doesn't
do it (it's a usability bug in the code that issues the warning).
If you can rebuild GCC the following untested patch should do it.
If you can reduce the warning to a test case showing it's a false
positive I would suggest to submit a bug for it. If you can't
I'd still suggest to open a bug for the missing inlining stack.
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index b5add827018..fcc6e39e3f6 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -3389,7 +3389,7 @@ do_warn_aggressive_loop_optimizations (class loop
*loop,
? UNSIGNED : SIGNED);
auto_diagnostic_group d;
if (warning_at (gimple_location (stmt),
OPT_Waggressive_loop_optimizations,
- "iteration %s invokes undefined behavior", buf))
+ "%Giteration %s invokes undefined behavior", stmt, buf))
inform (gimple_location (estmt), "within this loop");
loop->warned_aggressive_loop_optimizations = true;
}
Martin