https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88763
--- Comment #7 from Marius Messerschmidt <marius.messerschmidt at googlemail
dot com> ---
Thanks a lot for working on this!
A simple example would be the following:
-------------- CODE -------------------
int calc(int x, int y, int *flag)
{
if(flag > 5)
return x + y;
else
return x * y;
*flag += 2; // BAD LINE
}
int main(int argc, char **argv)
{
int flag = argc;
int array[250*250];
for(int i = 0; i < 250; i++)
{
for(int j = 0; j < 250
array[i*250 + j] = calc(i, j, &flag);
}
return array[42 + argc];
}
---------------------------------------
The line marked with "BAD LINE" is obviously preventing the unswitching as the
loop condition is no longer constant during the loop. If you uncomment the line
gcc reports ";; unswitched loop" which is great. But if you keep the line, you
get no output at all. The minimal output I would expect is:
";; not unswitching loop: REASON"
so in this case:
";; not unswitching loop: Condition is not invariant"
To further improve the output it would be great if there would be some more
information about the loop, but I do not know which information is available
during this stage. The most helpful additional information would be (also
applies for the successful message):
- File
- Function
- Line number of the loop head (or some other way to identify the loop, e.g.
loop number XY)
- Line number of the if-statement that should be unswitched out of the loop
- Line number of the issue that caused the loop unswitching to stop so in the
example above the commented line.
So I think the perfect log message would be something like this:
";; unswitching loop: testFile.c:82 (Condition: otherFile.c:502)"
";; not unswitching loop: testFile.c:91: Condition (otherFile.c:541) is not
invariant (modified at otherFile.c:32)"
But as I said above I do not know how many information about the original
source file is still available during this stage.