From: Ties Klappe <tg.klappe@gmail.com>
To: Joseph Myers <josmyers@redhat.com>
Cc: gcc@gcc.gnu.org
Subject: Re: Nested restrict pointers: missed optimization & client with UB?
Date: Tue, 13 Feb 2024 16:25:37 +0100 [thread overview]
Message-ID: <CAHSOcvDGfck9UAh4rXfqLnvgf4XR_ywr_DdkZws6uA=giB5DUA@mail.gmail.com> (raw)
In-Reply-To: <4b5ab0fa-7f70-4617-379-a80c94b1dc6@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1532 bytes --]
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?
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
>
>
next prev parent reply other threads:[~2024-02-13 15:26 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 [this message]
2024-02-13 15:33 ` Joseph Myers
2024-02-13 16:06 ` Richard Biener
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='CAHSOcvDGfck9UAh4rXfqLnvgf4XR_ywr_DdkZws6uA=giB5DUA@mail.gmail.com' \
--to=tg.klappe@gmail.com \
--cc=gcc@gcc.gnu.org \
--cc=josmyers@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).