https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88763

--- Comment #11 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
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": 1063000000.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.

Reply via email to