public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Ties Klappe <tg.klappe@gmail.com>
Cc: Joseph Myers <josmyers@redhat.com>, gcc@gcc.gnu.org
Subject: Re: Nested restrict pointers: missed optimization & client with UB?
Date: Tue, 13 Feb 2024 17:06:34 +0100	[thread overview]
Message-ID: <FE6628CA-8FAD-40AC-A0F6-49374E2A78BB@gmail.com> (raw)
In-Reply-To: <CAHSOcvDGfck9UAh4rXfqLnvgf4XR_ywr_DdkZws6uA=giB5DUA@mail.gmail.com>



> Am 13.02.2024 um 16:27 schrieb Ties Klappe via Gcc <gcc@gcc.gnu.org>:
> 
> Thank you both for your quick replies.
> 
> @Joseph, thank you for linking me to the other issue. If I understand
> correctly what the point is, would you then agree that the program main
> when calling foo2 has *defined* behavior?
> What surprises me is that *p and *q might be the same restricted pointer:
> the *xp* object itself is not declared as *int** *restrict* but as *int**.
> 
> By passing *xp* as argument to foo1, is the type of the object *xp* then
> implicitly converted to (or merely interpreted as) *int* restrict *(because
> of the argument type)*, i.e.* xp corresponds to the object *P *the standard
> refers to?
> 
> int main() {
>    int x = 0;
>    int* xp = &x;
> 
>    int res = foo2(&xp, &xp);
> 
>    return 0;
> }
> 
> ---
> 
> @Richard, thank you for the alternative implementation. Is foo3 meant to be
> optimized by GCC currently (I didn't manage to get GCC13.2 to do it)? Or is
> it a hypothetical example that would allow GCC to optimize it?

It’s a situation to show handling your two examples the same would be difficult.

> int foo3(int *restrict * p, int *restrict * q)
> {
>    int a;
>    *p = &a;
>    **q = 11;
>    **p = 12;
>    return **q;
> }
> 
> Kind regards,
> Ties
> 
> 
> Op di 13 feb 2024 om 15:29 schreef Joseph Myers <josmyers@redhat.com>:
> 
>>> On Tue, 13 Feb 2024, Ties Klappe via Gcc wrote:
>>> 
>>> int foo2(int *restrict *p, int *restrict *q)
>>> {
>>>    **p = 10;
>>>    **q = 11;
>>>    return **p;
>>> }
>> 
>> In this case, *p and *q might be the same restricted pointer object.  See
>> the more detailed explanation at
>> <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14192#c8>.
>> 
>> --
>> Joseph S. Myers
>> josmyers@redhat.com
>> 
>> 

      parent reply	other threads:[~2024-02-13 16:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-13 13:00 Ties Klappe
2024-02-13 14:15 ` Richard Biener
2024-02-13 14:29 ` Joseph Myers
2024-02-13 15:25   ` Ties Klappe
2024-02-13 15:33     ` Joseph Myers
2024-02-13 16:06     ` Richard Biener [this message]

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=FE6628CA-8FAD-40AC-A0F6-49374E2A78BB@gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc@gcc.gnu.org \
    --cc=josmyers@redhat.com \
    --cc=tg.klappe@gmail.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).