[Bug tree-optimization/88763] Better Output for Loop Unswitching
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88763 Andrew Pinski changed: What|Removed |Added Keywords||diagnostic Severity|normal |enhancement
[Bug tree-optimization/88763] Better Output for Loop Unswitching
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88763 --- Comment #12 from Marius Messerschmidt --- I think this messages look really good! I believe that this contains everything required to actually work on improving automatic unswitching, thank you very much! Do you think that there is a chance that this will be included in GCC9?
[Bug tree-optimization/88763] Better Output for Loop Unswitching
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88763 --- Comment #11 from David Malcolm --- Thanks for the testcase. (In reply to David Malcolm from comment #10) > Created attachment 45406 [details] > Followup patch to try to dump why a condition can't be unswitched within a > loop This is a followup patch (on top of the one in comment #6), which tries to dump the desired information from comment #7. On the testcase from comment #9, it gives: $ ./xgcc -B. -c /tmp/t.c -O2 -funswitch-loops -fopt-info-loop-all /tmp/t.c:17:9: missed: within this loop... /tmp/t.c:5:7: missed: ...cannot unswitch condition: if (_16 > 5) /tmp/t.c:3:11: missed: ...as condition is not invariant within loop; modified here by: _16 = flag_37 + 2; /tmp/t.c:17:9: missed: within this loop... /tmp/t.c:17:9: missed: ...cannot unswitch condition: if (j_11 != 250) /tmp/t.c:17:34: missed: ...as condition is not invariant within loop; modified here by: j_11 = j_34 + 1; i.e. it's emitting 3 messages per unswitchable condition, highlighting each of: * the loop * the condition * the problematic statement The -fsave-optimization-record version of this dump also captures the function name (and the inlining chain, for inlined statements, such as that of the condition within the "calc" inlined within "main"): { "count": { "quality": "guessed_local", "value": 106300.0 }, "function": "main", "impl_location": { "file": "../../src/gcc/tree-ssa-loop-unswitch.c", "function": "dump_unswitchable_condition", "line": 198 }, "inlining_chain": [ { "fndecl": "calc" }, { "fndecl": "main", "site": { "column": 25, "file": "/tmp/t.c", "line": 19 } } ], "kind": "failure", "location": { "column": 7, "file": "/tmp/t.c", "line": 5 }, "message": [ "...cannot unswitch condition: ", { "location": { "column": 7, "file": "/tmp/t.c", "line": 5 }, "stmt": "if (_16 > 5)\n" } ], "pass": "0x3a33250" }, How does this look? FWIW, this is feeling like gcc 10 material.
[Bug tree-optimization/88763] Better Output for Loop Unswitching
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88763 --- Comment #10 from David Malcolm --- Created attachment 45406 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45406=edit Followup patch to try to dump why a condition can't be unswitched within a loop
[Bug tree-optimization/88763] Better Output for Loop Unswitching
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88763 --- Comment #9 from Marius Messerschmidt --- Created attachment 45397 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45397=edit Basic testcase As there where some more issues in the example I provided, I added it as an attachment. Now it should work just fine.
[Bug tree-optimization/88763] Better Output for Loop Unswitching
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88763 --- Comment #8 from Marius Messerschmidt --- Oh minor error from my side, the "BAD LINE" should of course be above the if/return block otherwise it would work just fine.
[Bug tree-optimization/88763] Better Output for Loop Unswitching
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88763 --- Comment #7 from Marius Messerschmidt --- 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, ); } 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.
[Bug tree-optimization/88763] Better Output for Loop Unswitching
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88763 --- Comment #6 from David Malcolm --- Candidate patch for porting to the dump_* API: https://gcc.gnu.org/ml/gcc-patches/2019-01/msg00512.html
[Bug tree-optimization/88763] Better Output for Loop Unswitching
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88763 --- Comment #5 from David Malcolm --- Marius: do you have a simple testcase which demonstrates an area where the log could be improved? [I'm testing a patch right now which ports things to the dump_* API, and thus should make the existing dump messages also appear in -fopt-info's output, but that may well not help for your use-case]
[Bug tree-optimization/88763] Better Output for Loop Unswitching
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88763 --- Comment #4 from David Malcolm --- (In reply to Marius Messerschmidt from comment #3) > Sorry but I do not fully understand what you mean. Do you suggest using > different command line arguments? I believe Richard is referring to the internal API used for dumping; right now it's presumably just writing to a FILE *, and this doesn't show up for -fopt-info*. > So far I tried: > > -fdump-tree-all > -fdump-tree-unswitch > > and > > -fopt-info-all-optall > > But none of them told me the all the things that I would wish to know, most > important the reason why a particular loop was skipped during unswitching > (e.g. because it is not invariant or so (right now it already reports a few > things with -fdump-tree-unswitch like too-many-instructions or > too-many-branches)) Am taking a look.
[Bug tree-optimization/88763] Better Output for Loop Unswitching
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88763 --- Comment #3 from Marius Messerschmidt --- Sorry but I do not fully understand what you mean. Do you suggest using different command line arguments? So far I tried: -fdump-tree-all -fdump-tree-unswitch and -fopt-info-all-optall But none of them told me the all the things that I would wish to know, most important the reason why a particular loop was skipped during unswitching (e.g. because it is not invariant or so (right now it already reports a few things with -fdump-tree-unswitch like too-many-instructions or too-many-branches))
[Bug tree-optimization/88763] Better Output for Loop Unswitching
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88763 --- Comment #2 from Marius Messerschmidt --- Sorry but I do not fully understand what you mean. Do you suggest using different command line arguments? So far I tried: -fdump-tree-all -fdump-tree-unswitch and -fopt-info-all-optall But none of them told me the all the things that I would wish to know, most important the reason why a particular loop was skipped during unswitching (e.g. because it is not invariant or so (right now it already reports a few things with -fdump-tree-unswitch like too-many-instructions or too-many-branches))
[Bug tree-optimization/88763] Better Output for Loop Unswitching
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88763 Richard Biener changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2019-01-09 CC||dmalcolm at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #1 from Richard Biener --- I guess the logging should be switched to dump_* so that -fopt-info- can report these.