From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 708113858295 for ; Thu, 30 Nov 2023 17:16:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 708113858295 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 708113858295 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=68.232.129.153 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701364620; cv=none; b=XqrbyKcspiZApaSbCBGcQgXEEFIOcgCc9rg632FzPuiDuLOV+iHnb8fCH12Z0+yXIsZGonqVYX6RboYhgebH81TIgcX+M4iRHwEsHaMEr+PUSbFxjQgMpXmTaDcobERBDnwBOpwli8BwVnj4RaikWBofWPEJFNvTjsiDi9dXGYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701364620; c=relaxed/simple; bh=ZL9fQryWTM4nf0HfpWYKIEhjF+BZcUflx8+w143ZJAU=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=NWSvqobFu9Y57hX07iz8gmFXR8Qd2cR1P2RrS2Ilf2ITLSo7RTSrjRrOu8eX+aVUABrKhUg6j/NS2NQHtOsaWYR1/BHL8ybQ86P+gDjRFVHycW1PnERKYrXRh9fFXN0EXSGBDm/srsuEIfZ9wjs/1mQulc/rEe0XVwO7a0IjoBQ= ARC-Authentication-Results: i=1; server2.sourceware.org X-CSE-ConnectionGUID: HLU1gEvbQ5y1PS/BJSysCw== X-CSE-MsgGUID: zJeFFE9sS4e1XHyKLy3G2A== X-IronPort-AV: E=Sophos;i="6.04,239,1695715200"; d="scan'208";a="27284205" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 30 Nov 2023 09:16:56 -0800 IronPort-SDR: 8cd8T6OS+4Qa18OA8Kyy3bUgT+xT0iZgPU8O3gvRVaXkCfSFOVlIm+a7UEU09aCg94CKRfw3DX 9jBylB8u9RLEvKgrID3IMcWabc9yvHx0p/8RaLb06g01+6hob61F4HM8oqtKWbsgRP2BBMPkSL CG0djLcx2kJos7BO8jkaF0wFgjWvLPpWw4e8Qc+QbdqI2rv3I6tO+GtBZXjXtz6Pl/nFn77O/x ezsOKpfuclfYmkdo/Cq/SaR2WAlu23FcGupJlxkOcahkVcZj/dKK0UZD8RDEeH18lagsvZb1RR zKA= Date: Thu, 30 Nov 2023 17:16:53 +0000 From: Joseph Myers To: Ties Klappe CC: Subject: Re: Unjustified optimization due to restricted struct members? In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-3103.0 required=5.0 tests=BAYES_00,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, 30 Nov 2023, Ties Klappe via Gcc wrote: > 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) { In this code, 'b' is the ordinary identifier; "struct bar b" is the declaration D. The declaration does not itself need to have pointer type. -- Joseph S. Myers joseph@codesourcery.com