From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) by sourceware.org (Postfix) with ESMTPS id 797443858D37 for ; Thu, 30 Nov 2023 11:06:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 797443858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 797443858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701342388; cv=none; b=s3XxEK7P7z4CH/8BvcaTLbTGE6VJ74bvXLH/U7C8dEcN3V1MsAgq3AqDp1dsXoFdGCN2MVS6FnnayxObZ64jqIHy+6KhjZiDbSu4dBboE7TA3cXuJkoxKuKq+7GRcS3juqNt7KRZR8WFD5eZj7Gp9UE5PmhZwLH9KTBlBo89SQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701342388; c=relaxed/simple; bh=bbUGtM4kgHNaYY5kuViEiIAGVyBDmEZ2xevFBZ8NhD4=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=PBBZzeIoJ612XVTcVc4DofoKE0aHdEA83roLmOiRxmTOfHfyn66dmLQKSpOrWR/B3zLBdtykVsrtOEsYJq3WmTWcl7pQcTESGwnzSxTCFRbdzRkR00ZCC0DNmH3AVHYU3fNZBRvRZG/oXcD7CncELC+GKrujG6WyRCCtz8Av5/w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-5cece20f006so8814927b3.3 for ; Thu, 30 Nov 2023 03:06:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701342385; x=1701947185; darn=gcc.gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=IWh1zceYuZMsFsrje63g332ZEOzWInOoXIKmEdsqpSU=; b=X//un8MzUtXQ42iywjqgO1xyTedOK+riecee83gjZ/Hk67MLTXCo/Uq9blmirpujoV xI53d9q9G5QeZoYZaB7482ljex0pMrU0DV82BR7p/LaFc2rxBu1QMBPYPXTJNYzkx5KQ USqvILEMSYIq20ipkrqPyfZuYoPBmNCubJZV7vPj/Yb3N0rHZZusJTJm6cblUfrymdPV wEQNLkBoil1k6G3xiyxOBf9maM0N0qeb/7StDjGtueIophURoC74R30JIGiI3hMctUvE 3N5IOr/0hDgUiLN/vpiRw5WIAAUJHlhBZoISx6yz1rO3jcrhuLRdgPe1BdZfc83cM97b OhGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701342385; x=1701947185; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=IWh1zceYuZMsFsrje63g332ZEOzWInOoXIKmEdsqpSU=; b=ksdSZJXdwJv9EPn+TvGBP99MffeJJVmbDyr/hVO8jsfZOqVpzxZiB4Vh/y7I2cY/L9 W/55Z27ekVdFz71t1KGloUUvVy4rQ1vQNIZ6bTBqTFYM/RaG4CdYEsCGUUxMxfzclp2h Y5mZyU/Bmayf5im5ln6iZQgrW2i1cJ6vKJfRF+xdI9dnDbt5Ff7BOjVAjSGo0kHn80aw LmvOwfE9A0IbPDd+Hc+WY3WH6xe6QBSS0OSdwyedBzsLm+OPKEBivnT6AYFrOPRAVjME fju1d08d/26BT9P0279yl2aB/3rvi8GBWK+3Syn6qEUC2bsVdFFyG6YlOuVsZChDHchE zbtQ== X-Gm-Message-State: AOJu0YzmEvh42K1fnsxzur8thE0+L+ySpGkUVAWNGUMzPTSGkzjH3D+l aSevkT4RMUvWSmawo1sGQMF0wD5fpEcSKiRFUD7K584DKSw= X-Google-Smtp-Source: AGHT+IGr3RQism8CD2i5Ri6FfxrtxvJl3jzhPgs9q3O8pFGD3BczJrNgFdfuENhCmQ1OAuOVrgunjTxh6Yl2ixEKa6s= X-Received: by 2002:a81:5258:0:b0:5d3:4923:2fed with SMTP id g85-20020a815258000000b005d349232fedmr1238453ywb.36.1701342385330; Thu, 30 Nov 2023 03:06:25 -0800 (PST) MIME-Version: 1.0 From: Ties Klappe Date: Thu, 30 Nov 2023 12:05:49 +0100 Message-ID: Subject: Unjustified optimization due to restricted struct members? To: gcc@gcc.gnu.org Content-Type: multipart/alternative; boundary="00000000000084dea9060b5ca4a4" X-Spam-Status: No, score=0.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --00000000000084dea9060b5ca4a4 Content-Type: text/plain; charset="UTF-8" When reading section 6.7.3.1 of the C standard (quoted below) about the *restrict *type qualifier, the first section talks about *ordinary identifiers*. These are defined in section 6.2.3, and exclude members of structures. Let D be a declaration of an ordinary identifier that provides a means of > designating an object P as a restrict-qualified pointer to type T. I would assume that this means that in the code excerpt below the function *h* cannot be optimized by substituting the load of *b.p *for *10*, as the standard does not specify what it means for a struct member to be restrict qualified. However, the code is still optimized by gcc (but not Clang), as can be seen here: https://godbolt.org/z/hEnKKoaae struct bar { int* restrict p; int* restrict q; }; int h(struct bar b) { *b.p = 10; *b.q = 11; return *b.p; } Was this a deliberate choice, or does it simply follow from how restrict is supported in gcc (and could this be considered a bug w.r.t. the standard)? --00000000000084dea9060b5ca4a4--