This is the mail archive of the
mailing list for the GCC project.
Re: Question about fold C_MAYBE_CONST_EXPR expressions
- From: "Bin.Cheng" <amker dot cheng at gmail dot com>
- To: Prathamesh Kulkarni <prathamesh dot kulkarni at linaro dot org>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Mon, 25 Jul 2016 08:29:19 +0100
- Subject: Re: Question about fold C_MAYBE_CONST_EXPR expressions
- Authentication-results: sourceware.org; auth=none
- References: <CAHFci28_maioG0kc+0LAtovhMPKkPVhz6z7KZqo7OxscTDvrYg@mail.gmail.com> <CAAgBjMmM1YyVxFrwRdkw6AX=SFwaORH4NaQEuv2uVKug_qwBow@mail.gmail.com>
On Sun, Jul 24, 2016 at 11:04 PM, Prathamesh Kulkarni
> On 24 July 2016 at 21:26, Bin.Cheng <firstname.lastname@example.org> wrote:
>> I ran into a problem that C frontend (in function
>> build_conditional_expr) creates expression like (C_MAYBE_CONST_EXPR
>> (NULL, x + const)). The inner expression (and its operands) have
>> unsigned int type. After that, the expression needs to be casted to
>> result type which is unsigned short. In this case,
>> convert_to_integer/convert_to_integer_1 doesn't fold into
>> C_MAYBE_CONST_EXPR and just returns (unsigned
>> short)(C_MAYBE_CONST_EXPR (NULL, x + const)), as a result, (unsigned
>> short)(x + const) won't be simplified as (unsigned short)x + const.
>> My questions are, 1) Is it possible to fold type conversion into
>> C_MAYBE_CONST_EXPR's inner expression in convert_to_integer_1? 2) If
>> not, looks like there are couple of places the mentioned fold can be
>> done, for example, after stripping C_MAYBE_CONST_EXPR and before (or
>> during) gimplify. So which place is preferred?
> Sorry, I have a very silly question:
> I don't understand how the following transform
> (unsigned short) (x + const) to (unsigned short)x + const would be legal
> since the operands to PLUS_EXPR in latter case would have different types
> (unsigned short, unsigned) ?
> I suppose in GIMPLE (and GENERIC too?)
> we require rhs1 and rhs2 to have same types ?
I skipped type information for the const operand, of course the const
will be converted to unsigned short which is the type for computation.