This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH v3 1/9] Allow COND_EXPR and VEC_COND_EXPR condtions to trap
- From: Ilya Leoshkevich <iii at linux dot ibm dot com>
- To: Richard Biener <richard dot guenther at gmail dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Richard Sandiford <richard dot sandiford at arm dot com>, Segher Boessenkool <segher at kernel dot crashing dot org>, "Joseph S. Myers" <joseph at codesourcery dot com>, Andreas Krebbel <krebbel at linux dot ibm dot com>, Robin Dapp <rdapp at linux dot ibm dot com>
- Date: Fri, 6 Sep 2019 17:45:49 +0200
- Subject: Re: [PATCH v3 1/9] Allow COND_EXPR and VEC_COND_EXPR condtions to trap
- References: <20190905111019.8951-1-iii@linux.ibm.com> <20190905111019.8951-2-iii@linux.ibm.com> <CAFiYyc2k_andqHebmS8KATMZ3AWP=ch+3WzZK6do5DGvM3ifxg@mail.gmail.com>
> Am 06.09.2019 um 13:07 schrieb Richard Biener <richard.guenther@gmail.com>:
>
> On Thu, Sep 5, 2019 at 1:10 PM Ilya Leoshkevich <iii@linux.ibm.com> wrote:
>>
>> Right now gimplifier does not allow VEC_COND_EXPR's condition to trap
>> and introduces a temporary if this could happen, for example, generating
>>
>> _5 = _4 > { 2.0e+0, 2.0e+0, 2.0e+0, 2.0e+0 };
>> _6 = VEC_COND_EXPR <_5, { -1, -1, -1, -1 }, { 0, 0, 0, 0 }>;
>>
>> from GENERIC
>>
>> VEC_COND_EXPR < (*b > { 2.0e+0, 2.0e+0, 2.0e+0, 2.0e+0 }) ,
>> { -1, -1, -1, -1 } ,
>> { 0, 0, 0, 0 } >
>>
>> This is not necessary and makes the resulting GIMPLE harder to analyze.
>> In particular, one of the next patches in series needs to get to
>> VEC_COND_EXPR's comparison code, which is not possible when a temporary
>> is introduced.
>>
>> This patch takes special care to avoid introducing trapping comparisons
>> in GIMPLE_COND. They are not allowed, because they would require 3
>> outgoing edges (then, else and EH), which is awkward to say the least.
>> Therefore, computations of such conditions should live in their own basic
>> blocks.
>
> Comments inline (thanks for the work btw)
>
>> #endif /* GCC_GIMPLE_EXPR_H */
>> diff --git a/gcc/gimple.c b/gcc/gimple.c
>> index 633ef512a19..fd14fbec15e 100644
>> --- a/gcc/gimple.c
>> +++ b/gcc/gimple.c
>> @@ -2144,6 +2144,8 @@ gimple_could_trap_p_1 (gimple *s, bool include_mem, bool include_stores)
>> op = gimple_assign_rhs_code (s);
>> if (get_gimple_rhs_class (op) == GIMPLE_BINARY_RHS)
>> div = gimple_assign_rhs2 (s);
>> + else if (op == COND_EXPR || op == VEC_COND_EXPR)
>> + op = TREE_CODE (gimple_assign_rhs1 (s));
>
> I think this is not correct since we can have
>
> int i = fp > 1. ? intval1 : intval2
>
> and thus FLOAT_TYPE_P (t) is wrong. You need to do
>
> t = TREE_TYPE (op);
>
> as well I think.
Doesn't this mean there is a problem with the existing logic too? If `s`
is
int i = fp > 1.;
then
t = gimple_expr_type (s);
would give us BOOLEAN_TYPE instead of REAL_TYPE.
Also, the new logic will probably be a bit more complicated, since I
will first have to do:
tree cond = gimple_assign_rhs1 (s);
then see if `cond` is not e.g. an SSA_NAME, but rather a tcc_comparison,
and only then
t = TREE_TYPE (TREE_OPERAND (cond, 0))
So I'd rather send a new version before merging this :-)