public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Kai Tietz <ktietz70@googlemail.com>
To: Jason Merrill <jason@redhat.com>
Cc: Kai Tietz <ktietz@redhat.com>,
	gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: Re: C++ delayed folding branch review
Date: Thu, 27 Aug 2015 10:54:00 -0000	[thread overview]
Message-ID: <CAEwic4ZoKOnXi2oMoJXFsr-e+duL0KtwJ22WBTN7DGcwX3A8qg@mail.gmail.com> (raw)
In-Reply-To: <55DE7C55.6030207@redhat.com>

2015-08-27 4:56 GMT+02:00 Jason Merrill <jason@redhat.com>:
> On 08/24/2015 03:15 AM, Kai Tietz wrote:
>>
>> 2015-08-03 17:39 GMT+02:00 Jason Merrill <jason@redhat.com>:
>>>
>>> On 08/03/2015 05:42 AM, Kai Tietz wrote:
>>>>
>>>> 2015-08-03 5:49 GMT+02:00 Jason Merrill <jason@redhat.com>:
>>>>>
>>>>> On 07/31/2015 05:54 PM, Kai Tietz wrote:
>>>>>>
>>>>>>
>>>>>> The "STRIP_NOPS-requirement in 'reduced_constant_expression_p'" I
>>>>>> could
>>>>>> remove, but for one case in constexpr.  Without folding we don't do
>>>>>> type-sinking/raising.
>>>>>
>>>>>
>>>>> Right.
>>>>>
>>>>>> So binary/unary operations might be containing cast, which were in the
>>>>>> past unexpected.
>>>>>
>>>>>
>>>>> Why aren't the casts folded away?
>>>>
>>>>
>>>> On such cast constructs, as for this vector-sample, we can't fold away
>>>
>>>
>>> Which testcase is this?
>>
>>
>> It is the g++.dg/ext/vector20.C testcase.  IIRC I mentioned this
>> testcase already earlier as reference, but I might be wrong here.
>
>
> I don't see any casts in that testcase.  So the compiler is introducing
> introducing conversions back and forth between const and non-const, then?  I
> suppose it doesn't so much matter where they come from, they should be
> folded away regardless.

The cast gets introduced in convert.c about line 836 in function
convert_to_integer_1 AFAIK.  There should be the alternative solution
for this issue by disallowing for PLUS/MINUS/... expressions the
sinking of the cast into the expression, if dofold is false, and type
has same width as inner_type, and is of vector-kind.

>>>> the cast chain.  The difference here to none-delayed-folding branch is
>>>> that the cast isn't moved out of the plus-expr.  What we see now is
>>>> (plus ((vec) (const vector ...) { .... }), ...).  Before we had (vec)
>>>> (plus (const vector ...) { ... }).
>>>
>>>
>>> How could a PLUS_EXPR be considered a reduced constant, regardless of
>>> where
>>> the cast is?
>>
>>
>> Of course it is just possible to sink out a cast from PLUS_EXPR, in
>> pretty few circumstance (eg. on constants if both types just differ in
>> const-attribute, if conversion is no view-convert).
>
>
> I don't understand how this is an answer to my question.

(vec) (const vector) { ... } expression can't be folded.  This cast to
none-const variant happens due the 'constexpr v = v +
<constant-value>' pattern in testcase.  v is still of type vec, even
if function itself is constexpr.

>>>>>> On verify_constant we check by reduced_constant_expression_p, if value
>>>>>> is
>>>>>> a constant.  We don't handle here, that NOP_EXPRs are something we
>>>>>> want to
>>>>>> look through here, as it doesn't change anything if this is a
>>>>>> constant, or
>>>>>> not.
>>>>>
>>>>>
>>>>> NOPs around constants should have been folded away by the time we get
>>>>> there.
>>>>
>>>>
>>>> Not in this cases, as the we actually have here a switch from const to
>>>> none-const.  So there is an attribute-change, which we can't ignore in
>>>> general.
>>>
>>>
>>> I wasn't suggesting we ignore it, we should be able to change the type of
>>> the vector_cst.
>>
>>
>> Well, the vector_cst we can change type, but this wouldn't help
>> AFAICS.  As there is still one cast surviving within PLUS_EXPR for the
>> other operand.
>
>
> Isn't the other operand also constant?  In constexpr evaluation, either
> we're dealing with a bunch of constants, in which case we should be folding
> things fully, including conversions between const and non-const, or we don't
> care.

No other operand isn't a constant-value.  See code-pattern in
testcase.  It is of type 'vec', which isn't constant (well, 'v' is,
but constexpr doesn't know about it).

The bogus error-message happens in:

#1  0x00668c20 in verify_constant (t=t@entry=0xffd3cbe8,
    allow_non_constant=<optimized out>,
    non_constant_p=non_constant_p@entry=0xe5fa6fa,
    overflow_p=overflow_p@entry=0xe5fa6fb)
    at ../../src/gcc/cp/constexpr.c:1480
#2  0x0066c710 in cxx_eval_binary_expression (overflow_p=0xe5fa6fb,
    non_constant_p=0xe5fa6fa, t=0xffd3cba0, ctx=0xe5fa6fc)
    at ../../src/gcc/cp/constexpr.c:1620
#3  cxx_eval_constant_expression (ctx=ctx@entry=0xe5fa6fc,
    t=t@entry=0xffd3cba0, lval=lval@entry=false,
    non_constant_p=non_constant_p@entry=0xe5fa6fa,
    overflow_p=overflow_p@entry=0xe5fa6fb, jump_target=jump_target@entry=0x0)
    at ../../src/gcc/cp/constexpr.c:3491

#2  0x0066c710 in cxx_eval_binary_expression (overflow_p=0xe5fa6fb,
    non_constant_p=0xe5fa6fa, t=0xffd3cba0, ctx=0xe5fa6fc)
    at ../../src/gcc/cp/constexpr.c:1620
1620        VERIFY_CONSTANT (lhs);

>> So the way to solve it would be to move such conversion out of the
>> expression.  For integer-scalars we do this, and for some
>> floating-points too.  So it might be something we don't handle for
>> operations with vector-type.
>
>
> We don't need to worry about that in constexpr evaluation, since we only
> care about constant operands.

Sure, but the variable 'v' is the problem, not a constant-value itself.

>>>> But I agree that for constexpr's we could special case cast
>>>> from const to none-const (as required in expressions like const vec v
>>>> = v + 1).
>>>
>>>
>>> Right.  But really this should happen in convert.c, it shouldn't be
>>> specific
>>> to C++.
>>
>>
>> Hmm, maybe.  But isn't one of our different goals to move such
>> implicit code-modification to match.pd instead?
>
> Folding const into a constant is hardly code modification.  But perhaps it
> should go into fold_unary_loc:VIEW_CONVERT_EXPR rather than into convert.c.

Hmm, it isn't related to a view-convert.  So moving it into
fold_unary_loc wouldn't solve here anything.  Issue is in constexpr
code, not in folding itself.

> Jason
>

Kai

  reply	other threads:[~2015-08-27 10:39 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-12  5:41 Jason Merrill
2015-06-12 16:17 ` Kai Tietz
2015-06-13  7:58   ` Jason Merrill
2015-07-27 19:01     ` Jason Merrill
2015-07-28  2:40       ` Kai Tietz
2015-07-28 20:35         ` Kai Tietz
2015-07-29 18:48           ` Jason Merrill
2015-07-29 23:03             ` Kai Tietz
2015-07-30 14:40               ` Kai Tietz
2015-07-30 18:41               ` Jason Merrill
2015-07-30 21:33                 ` Kai Tietz
2015-07-31  0:43                   ` Jason Merrill
2015-07-31  7:08                     ` Jeff Law
2015-07-31 23:00                     ` Kai Tietz
2015-08-03  3:49                       ` Jason Merrill
2015-08-03  9:42                         ` Kai Tietz
2015-08-03 15:39                           ` Jason Merrill
2015-08-24  7:20                             ` Kai Tietz
2015-08-27  2:57                               ` Jason Merrill
2015-08-27 10:54                                 ` Kai Tietz [this message]
2015-08-27 13:35                                   ` Jason Merrill
2015-08-27 13:44                                     ` Kai Tietz
2015-08-27 18:15                                       ` Kai Tietz
2015-08-28  3:03                                         ` Jason Merrill
2015-08-28  7:43                                           ` Kai Tietz
2015-08-28 11:18                                             ` Kai Tietz
2015-08-28  2:12                                       ` Jason Merrill
2015-07-31  4:00                 ` Jeff Law
2015-07-31 16:26                   ` Jason Merrill
2015-07-31 16:43                     ` Kai Tietz
2015-07-31 16:52                       ` Jakub Jelinek
2015-07-31 16:53                         ` Jason Merrill
2015-07-31 21:31                           ` Kai Tietz
  -- strict thread matches above, loose matches on Subject: below --
2015-04-24  4:23 Jason Merrill
2015-04-24 13:46 ` Kai Tietz
2015-04-24 18:25   ` Jason Merrill
2015-04-28 12:06     ` Kai Tietz
2015-04-28 13:57       ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEwic4ZoKOnXi2oMoJXFsr-e+duL0KtwJ22WBTN7DGcwX3A8qg@mail.gmail.com \
    --to=ktietz70@googlemail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=ktietz@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).