From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 2C645388DD64 for ; Thu, 8 Dec 2022 15:59:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2C645388DD64 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B87jGA7007098; Thu, 8 Dec 2022 15:59:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : references : date : in-reply-to : message-id : content-type : content-transfer-encoding : mime-version; s=corp-2022-7-12; bh=S1Hp/ECZbZNKLUCH1uqut7sv8quY3PF5gHbHs8Bxrug=; b=VyC9xQatv8ZWRvu3GPFtwT4TcYWZs99+oRxj7w7VIHu841nNpquzg3s9QeZleIg//IKr utneXHHwluxzC3yCzWtqYzP/IKTHTkT2rAzi0gzdvyeG+pJidSmIkJ5Zxj06TC/uCpmu crz7tshvGfOH1pJt+tYYC19r9awyYGd+MeaRsECQsrntu6s7b4LscOpqIvLnPmmcwm5Q LvY/Pb9zvaOK6e78tZbhkQZZfl4cBiIJqdj6m6kXNNKYw7ViMfrLEDreuP4WuvE7oLUE E7mTFTSJg8M+q3TPqcQampTBxZL+b6awPewBU28HXqxl8muGWz7F6Qik8G6a8iPjQhxP ZA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3mauf8k25h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Dec 2022 15:59:23 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2B8FU90k029405; Thu, 8 Dec 2022 15:59:22 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2104.outbound.protection.outlook.com [104.47.70.104]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3maa6b39gv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 08 Dec 2022 15:59:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nDkbbhBc+eq39gJ4x3nS/URXsOls34sfZ2X/2TVWskOAgPl67yxYVDRVyTLTpyPIkLrk50Z5ZntlPbmEgNhJBqkcpLh7zOR/hJeEm/GVP50Aq1xVHnpxVEztECtWYHG4x2j704XZHMFVzt1kk3WK4ApHzQdQcGJI2f4ZgwobhKb4nxOlTEBe9xCFdTHwojhdbm+WP4knjKgKnZCo90+w9vqDbTedLyF/OrQhATzrHaDKDx045+0JlyG+of/bOJtioDPq4xbZfGIznUFA8coBtuak1yP7IioJaPUKswKiHpm9359ON6or3y+Y+t1d5uuMGur2L6CPuSUFTxKF8WgqQQ== 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=S1Hp/ECZbZNKLUCH1uqut7sv8quY3PF5gHbHs8Bxrug=; b=Kx+zJKpgW0V1qzaBU0TZpl/OoCcaSIheSdhXmJIxQ+nyORF3Ux/gTgdRrpxFPGHLaaj8VLEpjrVM+kD/nfJfWN0QL1UMT8Hr1a/N/6cCy3z2XdTcIMIAbCeAmgDZ0n7LkqcqoGpAxseJmhbOxxPIi8PT2rMBMydgUyCgc1+dPSsWeQ2LPi5dugy1lQSsifp2gxn0sjqM+ydtm3IhiJLh7TCzMT1c4V/1mN3GYc+fPoizR1Bo7h4fiZDYbrPb4ghMNZ0Q9Smyew9qUvR8qe0GGR1LU0KLckrs4YqmEiwJuHxcsry/Dy6/+9LStNhTWVMHHPPS35RpQak53QjTiTwtLw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S1Hp/ECZbZNKLUCH1uqut7sv8quY3PF5gHbHs8Bxrug=; b=vllB7QqNsxwJ/HVlzGFHi0Ay4IZFANQMnHrBxTPy8b1AbaihqOP0DDAOm+6Vgepm0L33r0sNOa0QKBtvvzDWTpp16t/BlueClTDeRusEzzgF0WrDnWg4RvfCnm3p0jQryDzwCzaSyD1NGL6FER8vm1oourPlZ2jhqpTe8OZrHXE= Received: from BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) by BL3PR10MB6236.namprd10.prod.outlook.com (2603:10b6:208:38f::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 15:59:20 +0000 Received: from BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::ebe9:b7c9:82ae:d256]) by BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::ebe9:b7c9:82ae:d256%7]) with mapi id 15.20.5880.014; Thu, 8 Dec 2022 15:59:19 +0000 From: "Jose E. Marchesi" To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] expr.cc: avoid unexpected side effects in expand_expr_divmod optimization References: <20221208105944.660323-1-jose.marchesi@oracle.com> <50269CD5-A3C0-4F12-8D0D-A81DA761BCD6@gmail.com> Date: Thu, 08 Dec 2022 17:03:03 +0100 In-Reply-To: <50269CD5-A3C0-4F12-8D0D-A81DA761BCD6@gmail.com> (Richard Biener's message of "Thu, 8 Dec 2022 14:42:29 +0100") Message-ID: <87bkodyjbc.fsf@oracle.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO4P123CA0258.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:194::11) To BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB2888:EE_|BL3PR10MB6236:EE_ X-MS-Office365-Filtering-Correlation-Id: 1f630ea6-39bf-4194-4a75-08dad9352a56 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Thie/TjVEIpb0P3tpJxbpkoRuM7ycgICsvv6UVrDMXEeIYC6FqGHYOfvRJgptPVaruCzStBpVIvpEpBVqaRN+u/rfq+mXV5RPLEJZo7Y2XfTBZEe29amUYGof7nPAIpsjTGSYPTz8O2qcyYdiXA75Aa3EecqxQqS6SaHFc41oplRwryFkKf9Y4ud+fFubHdTMBoVJGvQ+RFR3ZtIhBEolqdWk8vFYndigUlZSIWvQW/6Db21u7hGMocvprx72u4mEZrxrbyvezVnPdbv7ofeDFlVo4jt+ucxgYmnaS3cKRjBK9rAJqrEToTdrj/YUcM6CzjrsbzN0NUXIYcU4Wajkjbsifk/CdY2YLnAlA3uYKLMGhOqKWw4NAEBq6aUWfM5dXrmJ+9qoUf/VgEj47qSjXFUb0PeDG8pmwGfK4q16/9rzwWDr6eM0/c9+JL6EZ9QgXa7nksIIgbJfzBId3rBBn//qmhKpmNxhIqEqimpYQJfzPTOnmL8HM2Jwtpa0TXbFUP7uwDReffXAJRmAwdSUx0PdfWJdPihA8aWiTi31lox5WyFL0HhrksQiC9vejt/H8rYWI9+cu/ICDkfqmyjgbHLujgk1u3yQOHqxQPuqfVVmU+zicaT3lIpC5MZ1dFnLLcFYJIeg2R7OlRhIqn8aQRSDZPaaB94k0zXr9b+3mYWCgkiva1f3cpopIt4nWX9KlsQ2ersMiFhOfUa4PJqDAoCuqkMC/wRit2PJKiLIuw7XvZioc9Fft4UM8GYqsr0d4lFWRWWmng76y1p3PGYBA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB2888.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(376002)(39860400002)(366004)(136003)(346002)(396003)(451199015)(66946007)(66476007)(66556008)(8676002)(84970400001)(6666004)(4326008)(38100700002)(6486002)(478600001)(186003)(2906002)(26005)(6512007)(6916009)(86362001)(6506007)(83380400001)(8936002)(5660300002)(41300700001)(316002)(36756003)(2616005)(56340200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?RW1wbmNSc3FUV3c3NHVSSHV0dHdBTWM2c0pnQW5pUW9LVHdoaDRvcnc0STVQ?= =?utf-8?B?R2Q1MVJITkhXZjdoOURjK2FwSWFqY2VXUndTbHh3VlZGNVhvbHdURStLN1dL?= =?utf-8?B?Z29BT0srT0Fsenh4QVN6T2x4bGNoUThPM2M2SVlRL1RWQW54Rnh4M2hJYkYv?= =?utf-8?B?UnY0Zm5JNzE0S0lFV1M1VUw0Qjdkcm8yNG0yT3o2Z1NiWUtXMUhhcTI5YnNC?= =?utf-8?B?TkZKSVp1c3NQUmg1NjUxNnh6YkR4ancvd1U4TjhqW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FJaeVl3WXV4Y283U0N0d1NNWS9KcG9UUXBibEFvNXFZNU1wNzhJajBJ?= =?utf-8?B?cmViZERuaUhPclZDVkJIRmlVYlJxOG5kWDI4MEZHUUlRbDlwZEFCTGhkRU52?= =?utf-8?B?N1E9PQ==?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1f630ea6-39bf-4194-4a75-08dad9352a56 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2888.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 15:59:19.6888 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ekbHzXyyjOrIoQbqw+4ko6PqVI7UvFt0nxylWvcHZgerKOZnNC/P0ih0iUsJaycXKaTLW566/pLYvssgsF/wxIu9M90gJf2oCDtUoofxq00= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR10MB6236 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-08_09,2022-12-08_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 spamscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212080132 X-Proofpoint-ORIG-GUID: 6IFM1nBoherjNTd21QmrTe_sHEMfQQuF X-Proofpoint-GUID: 6IFM1nBoherjNTd21QmrTe_sHEMfQQuF X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP 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: >> Am 08.12.2022 um 11:56 schrieb Jose E. Marchesi via Gcc-patches : >>=20 >> =EF=BB=BFThe expand_expr_divmod function in expr.cc attempts to optimize= cases >> where both arguments of a division/modulus are known to be positive >> when interpreted as signed. In these cases, both signed division and >> unsigned division will raise the same value, and therefore the >> cheapest option can be used. >>=20 >> In order to determine what is the cheaper option in the current >> target, expand_expr_divmod actually expands both a signed divmod and >> an unsigned divmod using local "sequences": >>=20 >> start_sequence (); >> ... >> expand_divmod (... signed ...); >> ... >> end_sequence (); >>=20 >> start_sequence (); >> ... >> expand_divmod (... unsigned ...); >> ... >> end_sequence (); >>=20 >> And then compares the cost of each generated sequence, choosing the >> best one. Finally, it emits the selected expanded sequence and >> returns the rtx with the result. >>=20 >> This approach has a caveat. Some targets do not provide instructions >> for division/modulus instructions. In the case of BPF, it provides >> unsigned division/modulus, but not signed division/modulus. >>=20 >> In these cases, the expand_divmod tries can contain calls to funcalls. >> For example, in BPF: >>=20 >> start_sequence (); >> ... >> expand_divmod (... signed ...); -> This generates funcall to __divdi3 >> ... >> end_sequence (); >>=20 >> start_sequence (); >> ... >> expand_divmod (... unsigned ...); -> This generates direct `div' insn. >> ... >> end_sequence (); >>=20 >> The problem is that when a funcall is expanded, an accompanying global >> symbol definition is written in the output stream: >>=20 >> .global __divdi3 >>=20 >> And this symbol definition remains in the compiled assembly file, even >> if the sequence using the direct `div' instruction above is used. >>=20 >> This is particularly bad in BPF, because the kernel bpf loader chokes >> on the spurious symbol __divdi3 and makes the resulting BPF object >> unloadable (note that BPF objects are not linked before processed by >> the kernel.) >>=20 >> In order to fix this, this patch modifies expand_expr_divmod in the >> following way: >>=20 >> - When trying each sequence (signed, unsigned) the expand_divmod calls >> are told to _not_ use libcalls if everything else fails. This is >> done by passing OPTAB_WIDEN as the `methods' argument. (Before it >> was using the default value OPTAB_LIB_WIDEN.) >>=20 >> - If any of the tried expanded sequences contain a funcall, then the >> optimization is not attempted. > > How do libcalls appear in iff you specify OPTABS_WIDEN only? Doesn=E2=80= =99t > that allow to simplify this and also use the sequence without a > libcall? If you pass OPTABS_WIDEN only then libcalls are not an option and (as far as I can tell) expand_divmod returns NULL if a libcall is the only possibility. > Richard=20 > >>=20 >> A couple of BPF tests are also added to make sure this doesn't break >> at any point in the future. >>=20 >> Tested in bpf-unknown-none and x86_64-linux-gnu. >> Regtested in x86_64-linux-gnu. No regressions. >>=20 >> gcc/ChangeLog >>=20 >> * expr.cc (expand_expr_divmod): Avoid side-effects of trying >> sequences involving funcalls in optimization. >>=20 >> gcc/testsuite/ChangeLog: >>=20 >> * gcc.target/bpf/divmod-funcall-1.c: New test. >> * gcc.target/bpf/divmod-funcall-2.c: Likewise. >> --- >> gcc/expr.cc | 44 +++++++++++-------- >> .../gcc.target/bpf/divmod-funcall-1.c | 8 ++++ >> .../gcc.target/bpf/divmod-funcall-2.c | 8 ++++ >> 3 files changed, 41 insertions(+), 19 deletions(-) >> create mode 100644 gcc/testsuite/gcc.target/bpf/divmod-funcall-1.c >> create mode 100644 gcc/testsuite/gcc.target/bpf/divmod-funcall-2.c >>=20 >> diff --git a/gcc/expr.cc b/gcc/expr.cc >> index d9407432ea5..4d4be5d7bda 100644 >> --- a/gcc/expr.cc >> +++ b/gcc/expr.cc >> @@ -9168,32 +9168,38 @@ expand_expr_divmod (tree_code code, machine_mode= mode, tree treeop0, >> do_pending_stack_adjust (); >> start_sequence (); >> rtx uns_ret =3D expand_divmod (mod_p, code, mode, treeop0, treeop1= , >> - op0, op1, target, 1); >> + op0, op1, target, 1, OPTAB_WIDEN); >> rtx_insn *uns_insns =3D get_insns (); >> end_sequence (); >> start_sequence (); >> rtx sgn_ret =3D expand_divmod (mod_p, code, mode, treeop0, treeop1= , >> - op0, op1, target, 0); >> + op0, op1, target, 0, OPTAB_WIDEN); >> rtx_insn *sgn_insns =3D get_insns (); >> end_sequence (); >> - unsigned uns_cost =3D seq_cost (uns_insns, speed_p); >> - unsigned sgn_cost =3D seq_cost (sgn_insns, speed_p); >>=20 >> - /* If costs are the same then use as tie breaker the other other >> - factor. */ >> - if (uns_cost =3D=3D sgn_cost) >> - { >> - uns_cost =3D seq_cost (uns_insns, !speed_p); >> - sgn_cost =3D seq_cost (sgn_insns, !speed_p); >> - } >> - >> - if (uns_cost < sgn_cost || (uns_cost =3D=3D sgn_cost && unsignedp= )) >> - { >> - emit_insn (uns_insns); >> - return uns_ret; >> - } >> - emit_insn (sgn_insns); >> - return sgn_ret; >> + /* Do not try to optimize if any of the sequences tried above >> + resulted in a funcall. */ >> + if (uns_ret && sgn_ret) >> + { >> + unsigned uns_cost =3D seq_cost (uns_insns, speed_p); >> + unsigned sgn_cost =3D seq_cost (sgn_insns, speed_p); >> + >> + /* If costs are the same then use as tie breaker the other >> + other factor. */ >> + if (uns_cost =3D=3D sgn_cost) >> + { >> + uns_cost =3D seq_cost (uns_insns, !speed_p); >> + sgn_cost =3D seq_cost (sgn_insns, !speed_p); >> + } >> + >> + if (uns_cost < sgn_cost || (uns_cost =3D=3D sgn_cost && unsig= nedp)) >> + { >> + emit_insn (uns_insns); >> + return uns_ret; >> + } >> + emit_insn (sgn_insns); >> + return sgn_ret; >> + } >> } >> return expand_divmod (mod_p, code, mode, treeop0, treeop1, >> op0, op1, target, unsignedp); >> diff --git a/gcc/testsuite/gcc.target/bpf/divmod-funcall-1.c b/gcc/tests= uite/gcc.target/bpf/divmod-funcall-1.c >> new file mode 100644 >> index 00000000000..dffb1506f06 >> --- /dev/null >> +++ b/gcc/testsuite/gcc.target/bpf/divmod-funcall-1.c >> @@ -0,0 +1,8 @@ >> +/* { dg-do compile } */ >> +/* { dg-final { scan-assembler-not "__divdi3" } } */ >> + >> +int >> +foo (unsigned int len) >> +{ >> + return ((unsigned long)len) * 234 / 5; >> +} >> diff --git a/gcc/testsuite/gcc.target/bpf/divmod-funcall-2.c b/gcc/tests= uite/gcc.target/bpf/divmod-funcall-2.c >> new file mode 100644 >> index 00000000000..41e8e40c35c >> --- /dev/null >> +++ b/gcc/testsuite/gcc.target/bpf/divmod-funcall-2.c >> @@ -0,0 +1,8 @@ >> +/* { dg-do compile } */ >> +/* { dg-final { scan-assembler-not "__moddi3" } } */ >> + >> +int >> +foo (unsigned int len) >> +{ >> + return ((unsigned long)len) * 234 % 5; >> +} >> --=20 >> 2.30.2 >>=20