Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s9mDb-0055C4-W8 for pgsql-general@arkaria.postgresql.org; Wed, 22 May 2024 13:41:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1s9mDb-00HAZr-H7 for pgsql-general@arkaria.postgresql.org; Wed, 22 May 2024 13:41:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s9mDZ-00HAZi-VV for pgsql-general@lists.postgresql.org; Wed, 22 May 2024 13:41:23 +0000 Received: from mail-tycjpn01olkn2041.outbound.protection.outlook.com ([40.92.99.41] helo=JPN01-TYC-obe.outbound.protection.outlook.com) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s9mDW-001SRa-8J for pgsql-general@postgresql.org; Wed, 22 May 2024 13:41:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ky9gw4pBDhcDtlB28rxGik+ik3TfYsl4fMu/2s6qwCrn3uB7uy8/gGyABkpWBKVlNBCVsz2t9N/iZCPZ9FeniVu167Jg+UUVwul4rF8dvdnCN2htS8ZpAvFESocAkO9lhAZFerjAHc3yqSDi64aoVViklHMTWl0WEUSjHEPtzo6QdOFRXoLEazYWI8e84Zw0gNTjBHF+PoJ0kgWNaLS2aiDllNODlS0P3o09xy8ocFB9RQW3pdf+FUlLPEexkoRow8PZAoAao7wz0YgdSi/wJG6sKdjT+Qx/quq4KeqT/NOdUX+WC5pLsLFzxzWl4tXXUXTWe5mabrzco9IN4bKsxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=oA9DKvdaZqE4AuJXJ9ckMe2DAOOtvqUXEhK2mLYzSSE=; b=J0OvnbXapdm9KaF4gLLLUGLqsoQ1lBvh0Lgxgx4H9a8o7e1im6GZpVgHxsGB3SQDTaNRxXi29E7zfGY+/Ae/ynfc882H92kvyudDlBJ/T7clK6sAtkoO9/dRU4gLqo5L+xHAQSgxO+ysLwIreTJYYC/UsMR3BPZuXmAzjTURcoO5AiGFmf6Zv1xLja9KBClr9Co5u8IkvLlPY+yfUiTu/dtMRCDuN10c80VlBgt/bKp5tpmDOLgFFNFnpXxFL+AuRfYWgRlk9vHw3b83Jz0sKehu8UMbXTL7uiBBvgKa63TmEwQZlSSZPdQ93io4rnD26LV2/yLvrwJQ3IDEYc94UQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oA9DKvdaZqE4AuJXJ9ckMe2DAOOtvqUXEhK2mLYzSSE=; b=EJ65URBLOAWheuqkYDMmM2qaIf8BrIdWAdM9ccHfYKi2B18VXcJzLCp9AglWqJ4K9q+tiGIJIU1eRXtkuXaq/u10JM9EBpE1NHr1qWtQTq3oyg9CR1Io6M0I7gmf29tGS38UfTaUTttrBM2j9I9fRUWPI0tTn8qCZ0mZ86gzePHhFuV21ZW7VlTpoEUeFq15XfpndjDTHFEMduzAo1Xo36XwAhBD/w1yyX8eZNLX/CVUhasfDaH8E9iTabw6h9LDQxPlBvyy6L6JtAPbwRuQx+1CypQ0/Tenfq9Vjc04VGZtZKBx82cU+tzIQ1510T+UK+sdvCUJ4TGs43GQQcJjbw== Received: from OS0P286MB0163.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:a9::15) by TY3P286MB3031.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:318::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.21; Wed, 22 May 2024 13:41:13 +0000 Received: from OS0P286MB0163.JPNP286.PROD.OUTLOOK.COM ([fe80::be4b:2fd9:5414:c8bf]) by OS0P286MB0163.JPNP286.PROD.OUTLOOK.COM ([fe80::be4b:2fd9:5414:c8bf%3]) with mapi id 15.20.7611.016; Wed, 22 May 2024 13:41:13 +0000 Content-Type: multipart/alternative; boundary="------------uUWYYVbyzJ3yEeiYpaHWG0S0" Message-ID: Date: Wed, 22 May 2024 21:41:08 +0800 User-Agent: Mozilla Thunderbird Subject: Re: Missed compiler optimization issue in function select_rtable_names_for_explain To: Daniel Gustafsson References: <05C4ADF5-5E8C-49EC-8E0A-804BB946F1C7@yesql.se> <23848714-3662-428E-8E6D-5986D87491D6@yesql.se> Content-Language: en-US Cc: pgsql-general@postgresql.org From: XChy In-Reply-To: <23848714-3662-428E-8E6D-5986D87491D6@yesql.se> X-TMN: [u7ehCVjvfqSynQpvIrllsv+7wiXoYC2v] X-ClientProxiedBy: SI1PR02CA0051.apcprd02.prod.outlook.com (2603:1096:4:1f5::6) To OS0P286MB0163.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:a9::15) X-Microsoft-Original-Message-ID: <55a7159d-32f4-4b46-953a-bbcb57c8125a@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS0P286MB0163:EE_|TY3P286MB3031:EE_ X-MS-Office365-Filtering-Correlation-Id: 7cb1dab2-7921-453a-7c7e-08dc7a64d8b3 X-Microsoft-Antispam: BCL:0;ARA:14566002|461199019|3412199016|440099019; X-Microsoft-Antispam-Message-Info: IkNpgkYbMicxE2T4JjiQy57o+xneyMkrtdajE/m3ZyW+jNLjwPmGYeSBVXxNcUBqmDTHzQhYqZcz1HDybDCzfVtzGmUCPcJ3nIE2fxEUpMfKB79tjyf/BNz4bfOyI0c0g0+JBYBzQpMiVOi3YgC1PKqjqjnxsHaNnakCpSXb1hmLc8EO/WVKP0UW6pb5kGVunx6wgb17JZLDZ80+Y/HL2ZpRWvAIoZ7XA0ixDFQdLJvMU2p9ay4ySsKGOBcUL10QntczCPRde0EPn/TQUBCRDxxFVFUVmnXsRdktg7nIqu1XEurtbiaRMv4vPwb/3oaWjQSD7IIPDTaJqjc0QIZPxyZijfbmQ425UKz5k6d186udsXF6zNPERWRhx4oxn/ewbMTeecY8Q158lWi+nuzFhdOi3bxMsrahkzwawoEv+h+nsDLeJmJTCKYennrEaxuvSclLUw6T1FZfqG2CQ47OGdLPHBZ81+mSMub3wlpzrvizzx8m4ok9ktJ0L12JHKbmulAru6ItZ+tVRi3Td2Q+gIj+kLopkdncfWnoqsDbRlGhSqeOBJm8nzXn32eJ+21P X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?aHRSZmVQWjJiY0ZEdVA2aHljajM1azM0WVdtM1ZrMVB6dy8xbmlTR2dxTVVp?= =?utf-8?B?NXVvUk5qbXdaa05oOEJtQkZPRjNyVWRnMXNpWWJoZ29RTTU3NzlqSWQ5QUt4?= =?utf-8?B?SFRBMkU5SUJybEg4cUVwenUvQWtOKzBBNmt5ZmJEMWVjWXAvWGVsZVEwTHpx?= =?utf-8?B?am9oVW56YnZaaFVBMWxWdHVEb2RVSzNXaTdmSnRRbUZyVHhId2RQNU9mbTBQ?= =?utf-8?B?MncybmFNNGcxL01ydkppOTFjSmcra0g2MzJGOVEyTnFXdWUrQ1g1YUQxRkc3?= =?utf-8?B?RVJrUlRiODI2TU9iM3FzY0pBNll1anpWZ3FaWk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1ZFeS9mTFlnRldsV3NnekdNNmlMOGpudXliNVhZ?= =?utf-8?B?UVJGNVlMZWJNSm52U2JMd3VkZERBWm8xcGJ3ckZNQzNmZXV1b216RFgrL0ls?= =?utf-8?B?UnJ5dlhLc29TUUlsT1lSUld3NThVK3NGV1M0SzFwZTBwKzlXKzNxYmJqOW55?= =?utf-8?B?ZDcyV29qVXY0MTZBdVZmZDh1Z1NSb0xUbld1eDc5cVBLcU5WR1ZtTjBTang4?= =?utf-8?B?S2ZTZnZvWGRQblpncXg5a21LTEZETlRWSHJrNjdzQlpoQlR1M2picE05SmtN?= =?utf-8?B?c2J3aGY2Q25YLzNqelRsajlRSkpjQzR2K3dnSVJvNURtaUZSVWpMOEdBNDhu?= =?utf-8?B?c2cyVGRrejhSY1RpT1ZwWngwbzVoRGtzUkZqTit5bU95UDRtdnhyaHIzYjIz?= =?utf-8?Q?4k+Lp5qVNOQeGYhfUvfDVYh/IxNqwppyhxFn0o4e+Ai8=3D?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7cb1dab2-7921-453a-7c7e-08dc7a64d8b3 X-MS-Exchange-CrossTenant-AuthSource: OS0P286MB0163.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2024 13:41:13.3610 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY3P286MB3031 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --------------uUWYYVbyzJ3yEeiYpaHWG0S0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 在 2024/5/22 18:55, Daniel Gustafsson 写道: >> I mean that the stores with value "0" after the memset are dead: >> ``` >> dpns.subplans = NIL; >> dpns.ctes = NIL; >> dpns.appendrels = NULL; >> ``` >> since the memset has written zeroes to the object "dpns", and these members are known to be zero. > They are known to be zero, but that's not entirely equivalent though is it? > NIL is defined as ((List *) NULL) and NULL is typically defined as ((void *) > 0), so sizeof(0) would be the size of an int and sizeof(NULL) would be the size > of a void pointer. The type or size doesn't matter here. At IR or assembly level, they are all zeroes. My main point is that "dpns.xxx" are filled with zeroes by the memset firstly, and overwriting them with zeroes in the following stores is redundant. LLVM cannot remove the redundant overwrites due to the initialization order. If we adjust the order of the initialization of "dpns.xxx", the compiler can remove such stores. Does my explanation make sense to you? Best regards, Hongyu. --------------uUWYYVbyzJ3yEeiYpaHWG0S0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


在 2024/5/22 18:55, Daniel Gustafsson 写道:
I mean that the stores with value "0" after the memset are dead:
``` 
    dpns.subplans = NIL;
    dpns.ctes = NIL;
    dpns.appendrels = NULL;
```
since the memset has written zeroes to the object "dpns", and these members are known to be zero.
They are known to be zero, but that's not entirely equivalent though is it?
NIL is defined as ((List *) NULL) and NULL is typically defined as ((void *)
0), so sizeof(0) would be the size of an int and sizeof(NULL) would be the size
of a void pointer.

The type or size doesn't matter here. At IR or assembly level, they are all zeroes. 

My main point is that "dpns.xxx" are filled with zeroes by the memset firstly, and overwriting them with zeroes in the following stores is redundant. LLVM cannot remove the redundant overwrites due to the initialization order. If we adjust the order of the initialization of "dpns.xxx", the compiler can remove such stores.

Does my explanation make sense to you?

Best regards, Hongyu.

--------------uUWYYVbyzJ3yEeiYpaHWG0S0--