From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from MTA-14-4.privateemail.com (mta-14-4.privateemail.com [198.54.118.206]) by sourceware.org (Postfix) with ESMTPS id 3C0EF3858D32 for ; Tue, 9 Apr 2024 17:26:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C0EF3858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=twdb.moe Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=twdb.moe ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3C0EF3858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.54.118.206 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712683580; cv=none; b=UWuBwSJwsQYxEetQw/044/MkP1drkIdmh6hBhJzyZ6y1jLwvvBHJwJL6dQBDXnxhS40Nd45tZe7R/xnWy400T4rOPQNuRxjq6+qnEw5VtW8GPRVsm/6HQOBdsX8jrgYNrhXCqVXVihDJgDdJ6V7adR094hki2FgzxO3wHztV1S8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712683580; c=relaxed/simple; bh=KWds84kzrRuT3mPCc6W9vpNZmGxgE4PgELrCqC3dn1Q=; h=DKIM-Signature:Date:From:To:Message-ID:Subject:MIME-Version; b=mxO2U/iC9plWBVBskEw3BrgTBfrHYSXwjHQdaV0rjv/M32ClzA6DrmML96KxLiR3ur03Aq2kQVFnCqQOzDhQQt+3N0Pv57Y67bN5IpwiCmRx4me6rvcAilWF2xRdnVGEhxejwZY8e9sC98eo/w7oxlTakYJyEE3yNi00H/ZVm2M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mta-14.privateemail.com (localhost [127.0.0.1]) by mta-14.privateemail.com (Postfix) with ESMTP id 1D85B180004E for ; Tue, 9 Apr 2024 13:26:16 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=twdb.moe; s=default; t=1712683576; bh=KWds84kzrRuT3mPCc6W9vpNZmGxgE4PgELrCqC3dn1Q=; h=Date:From:To:Subject:From; b=Caj7IVP6pBlK8rzgSyZohyZGeDSwccheWN46Cep/FH1HiIkq4YjCJyOmUl4LrWUrn ELdEGPj34cw0HUw7URVYaPqUliM5HUHMQl9hhtLsLRK5kv2wYNLUP4au4dNQttqzKf O97p0bf2w+4KjSHvjcqe6n2xWWB0VkeaubzdRnHmc4Kr/bRYVoDeS4IVnAsQjS0VOj ilrWkAKjlasRxJO1hQ+jeRkNQ/TlVn4r1zVIneiiVaFJvsGMlCj+z0/gUe0m+EeKj0 6wcj8ghInV2A0nH4PdC//2ZHwJOmkkGgQhNaZlqVuCxZ7IoDRPGGQ9ZTcoNr9Oc5+6 5MOTTXHHw5i4Q== Received: from APP-06 (unknown [10.50.14.156]) by mta-14.privateemail.com (Postfix) with ESMTPA for ; Tue, 9 Apr 2024 13:26:16 -0400 (EDT) Date: Tue, 9 Apr 2024 14:26:16 -0300 (BRT) From: zamfofex To: "gcc-help@gcc.gnu.org" Message-ID: <32594954.210103.1712683576045@privateemail.com> Subject: simple optimisation question MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Priority: 3 Importance: Normal X-Mailer: Open-Xchange Mailer v7.10.6-Rev61 X-Originating-Client: open-xchange-appsuite X-Virus-Scanned: ClamAV using ClamSMTP X-Spam-Status: No, score=2.7 required=5.0 tests=BAYES_00,DKIM_INVALID,DKIM_SIGNED,KAM_DMARC_STATUS,LIKELY_SPAM_BODY,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: I was recently investigating what these two (relatively similar) functions = would compile to: - - - - - int read0(int (*x)[12], int i, int j) { return x[i][j]; } int read1(int *x, int i, int j) { return x[i * 12 + j]; } - - - - - I found (through Godbolt) the following behavior (all on x86-64): - On GCC: The two functions compile to different assembly code regardless o= f the flags tested. - On Clang: They compile to the same assembly code under =E2=80=98-m32 -Oz= =E2=80=99. - On Clang: They compile to different assembly code under other tested flag= s. The flags I tested were =E2=80=98-O3=E2=80=99 vs. =E2=80=98-Oz=E2=80=99 and= =E2=80=98-m32=E2=80=99 vs. none. (Four combinations per compiler.) In GCC, the assembly code, although different, under =E2=80=98-m32 -Oz=E2= =80=99 was of the same size (in bytes, after assembled) for both functions.= For =E2=80=98-Oz=E2=80=99 withough =E2=80=98-m32=E2=80=99, the first one w= as larger. Is this a missed size optimisation for x86-64? Even in the case where the a= ssembly code is larger, the time performance difference seems unobservable.= (Though I=E2=80=99d have imagined the the larger one would have been slowe= r in each case.) These are URLs for the tests I made: - =E2=80=98gcc -O3=E2=80=99: https://godbolt.org/z/8T77ehaEE - =E2=80=98gcc -Oz=E2=80=99: https://godbolt.org/z/1E1jMxY78 - =E2=80=98gcc -m32 -O3=E2=80=99: https://godbolt.org/z/P8G614xzv - =E2=80=98gcc -m32 -Oz=E2=80=99: https://godbolt.org/z/TTEGKqzn1 - =E2=80=98clang -O3=E2=80=99: https://godbolt.org/z/nEPbvfsb6 - =E2=80=98clang -Oz=E2=80=99: https://godbolt.org/z/hv1z3dEcf - =E2=80=98clang -m32 -O3=E2=80=99: https://godbolt.org/z/6snbhj68n - =E2=80=98clang -m32 -Oz=E2=80=99: https://godbolt.org/z/EEK87dn3d