On 11/4/24 10:00, Andrew MacLeod wrote:
The invert() range operation is not supported on values of either VARYING or UNDEFINED.  Primarily this is because UNDEFINED has no type, which makes it impossible to perform invert() twice on a value, and produce that same value.  There were also times when it wasn't precisely clear what the client expects when UNDEFINED or VARYING is inverted.. so it is handled at the caller point.

When processing switches, whenever we find the ranges for a particular label, we invert that range, and intersect that inversion with the current "default:" ranges to determine the default case.   In this testcase, one label has all possible values, so the label was producing VARYING.  inverting that value was causing a trap.

This patch simple checks for VARYING and sets the default ranges to UNDEFINED in this case.

Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed.

Backports to GCC12 - 14 forthcoming.

Andrew


Commited virtuslly identical patch:

commit e1154e294b3d8f7267612afb2113b2572cb39e33 (HEAD -> gcc14, origin/releases/gcc-14)
Author: Andrew MacLeod <amacl...@redhat.com>
Date:   Sat Nov 2 10:26:24 2024 -0400

    Don't call invert on VARYING.

    When all cases go to one label and resul in a VARYING value, we can't
    invert that value to remove all values from the default case. Simply
    check for this case and set the default to UNDEFINED.

            PR tree-optimization/117398
            gcc/
            * gimple-range-edge.cc (gimple_outgoing_range::calc_switch_ranges):
            Check for VARYING and don't call invert () on it.

            gcc/testsuite/
            * gcc.dg/pr117398.c: New.


commit 84b713589646c63b38ec55352fb87c1e80b69b66 (HEAD -> gcc-13)
Author: Andrew MacLeod <amacl...@redhat.com>
Date:   Mon Nov 4 10:02:35 2024 -0500

    Don't call invert on VARYING.

    When all cases go to one label and resul in a VARYING value, we can't
    invert that value to remove all values from the default case. Simply
    check for this case and set the default to UNDEFINED.

            PR tree-optimization/117398
            gcc/
            * gimple-range-edge.cc (gimple_outgoing_range::calc_switch_ranges):
            Check for VARYING and don't call invert () on it.

            gcc/testsuite/
            * gcc.dg/pr117398.c: New.

commit 4b9d6952d4024c5b8a66146ad497d63ad76a4095 (HEAD -> gcc12)
Author: Andrew MacLeod <amacl...@redhat.com>
Date:   Mon Nov 4 10:02:35 2024 -0500

    Don't call invert on VARYING.

    When all cases go to one label and resul in a VARYING value, we can't
    invert that value to remove all values from the default case. Simply
    check for this case and set the default to UNDEFINED.

            PR tree-optimization/117398
            gcc/
            * gimple-range-edge.cc (gimple_outgoing_range::calc_switch_ranges):
            Check for VARYING and don't call invert () on it.

            gcc/testsuite/
            * gcc.dg/pr117398.c: New.


Reply via email to