From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 07D7E3858D1E for ; Mon, 30 Jan 2023 18:56:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 07D7E3858D1E 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 (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30UHY5wG023347; Mon, 30 Jan 2023 18:56:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : in-reply-to : references : date : message-id : content-type : mime-version; s=corp-2022-7-12; bh=yMcufOrMakN2i6eC0myGer2PZsdVDyD6Gp34G7zTtPQ=; b=zWSRyr5Im/YvD6p7FzWlHIRfQb3RLUNGIBAiJdYW9LM2OnvajJMo+CkysuTwV6tidvz2 h9jwqsEpc7RLZCqqVSuSBCaRMNWlS5zv1xkn2QvJebp6ZgegZ7bMiw2gQ/XQljtZK0BS H8xXLkyHQjAFAjFd+xR4/T1D7EQXwdyxa7HeykUZCfHcEtRCQzifPwD2s4DYXwqsj9dY jAZbprGBlwfeoQvoVlyTRvK+FHCn77Vnz3/WP85veUjitzhfoMDelYMT4m8mCu54ktla b9km2SNyOqsWNYUG3qzEVnIB0/znM5Tu9fMWj2kDu8wvUQkcnxOM/GV5qdOQhIHrTgXx ZA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ncvm13rp1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Jan 2023 18:56:07 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30UIKT8G010584; Mon, 30 Jan 2023 18:56:07 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2175.outbound.protection.outlook.com [104.47.57.175]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3nct54s8dt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Jan 2023 18:56:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U89Fjtu/ApyA48WyXvo/Ge1ivLgvHr4DKYq/ocoWjTlaul7OVCtWmCitvzkdclZDs1pQRsmhJ2aKiKITd3LmHvGBo6eD8RyV/vcqFEhhHVpk2LnmoA2YvJ3WnfDqSuCChx+fS5OYolz/48AJDw8ipkT/JhyVzQ7uhVlvcg1OzCKQW4V/lUjPUg3SJPhmygkzaVYHTMwTZRfV1CZM5FZdWtqeHg7Y8gB2mVMbCnMpOGm1Ee2Mkj+ipQ784XGazfPNWegdICkG1RSeoJMlOPpD5/4PCpEyVfOABAnR8wWUMKEngzkZ0rPWI5+jVsNES0UzqXOTffH69i0iSZ3kFuIa2A== 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=yMcufOrMakN2i6eC0myGer2PZsdVDyD6Gp34G7zTtPQ=; b=fiLvBKNfxMgAGav/mIxSPCl4gxnCzJ+oMWfaK8O2YWaT796IUBT954J/Vgx10PQmjHd44pVsR88KypxE3O3Rr1A3M5Z/4ZXH18zJhZlOLEewFZNpKNc0jjpf9cniv6R3NsM0Lh2kNqhVX67BQHAvGKX4qtAkjFu4cHlM48gd6oge4/M8N17MLSYoBzMb8F/u9P8JqhyqEVLunnjfbOYL8v7vJyIj8L2iDKDtEYclNTezPzoeGGmCK1i+g3SVXRStRPfzAmcY4ryn7+DViekBgiqsFXxaPRw7XSuDup7YSy0HdaNBMUgBK5Wb7xDE+t9ATBM6lBi7wI/jFHQT2Z9erw== 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=yMcufOrMakN2i6eC0myGer2PZsdVDyD6Gp34G7zTtPQ=; b=vugf6Bn9M55cMJnSx6Jyac6aua6r1tnqdSGVieYSBRLDln3W638uoqo1nv5DK5WZ5/5/cEtqS40BIrspLPpopcVFjDd2+70JYDEj2PNwH9m0r7C5d0Fxb0QIO1qoNdBrRS8+hSd5Yo5V4/sEWjZEUDDcdHOs6ZeVlzH9QMMHbsY= Received: from BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) by MW4PR10MB6324.namprd10.prod.outlook.com (2603:10b6:303:1ee::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.17; Mon, 30 Jan 2023 18:56:05 +0000 Received: from BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::3cd3:9bef:83f:5a85]) by BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::3cd3:9bef:83f:5a85%7]) with mapi id 15.20.6064.019; Mon, 30 Jan 2023 18:56:05 +0000 From: "Jose E. Marchesi" To: Andrew Pinski Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] expr.cc: avoid unexpected side effects in expand_expr_divmod optimization In-Reply-To: (Andrew Pinski's message of "Mon, 30 Jan 2023 10:45:10 -0800") References: <20221208105944.660323-1-jose.marchesi@oracle.com> Date: Mon, 30 Jan 2023 19:55:58 +0100 Message-ID: <875ycnhmwx.fsf@oracle.com> User-Agent: Gnus/5.13 (Gnus v5.13) Content-Type: text/plain X-ClientProxiedBy: LO2P123CA0016.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:a6::28) To BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB2888:EE_|MW4PR10MB6324:EE_ X-MS-Office365-Filtering-Correlation-Id: fb57902a-e046-4887-84e0-08db02f3a386 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: St/oEq9d4OjjTbeYLBxrJojB1y6eyzv2hMc4kS58gOjaYex2slETO1o8av8XJJZY+lQKVMeJXM77k0a8RcGAPX+4X84zE5TxRP5VHhaQp+0LS54Ulxa/sRrIfKGJJw/Ne4I52Z6+t0/67KA5tj5+C9sFiGTTGcO3s42KEryk9h+zu/kPXSowFgPNlUDHWJncR9BHQNMFwgUdvaw8f8B0TVLHeSLU5bNdrDfgfEDdHXdYb2uTi8T+A9JN8q78IIaGbxKWKx7yYHMb4kkOIUWv4x94yba7RovI3wSOKRCi8fveZb7NGohzQZJD2k1059j4UjtkttMt73eAj7nWLrZZKHQ+9ChnjbU3sSBD83pspkaMTJYagrmRQ+9eooqxiKZF5awUZ5te8IQn8vet7i/KqtJgiWXU/81vCSgeShg4tGgb7RNySwnqiCGsWzQ7rkKbyS9PRSowP8xk5BQrgTNnn3+76TkeQWGcnxGPnJwgfOU8UjFQXjNBWOyPKLr3lEYMDRny9V7U0PB3XorUDK/PjWRND2vWlIffZoVj4v3BC7tFXTDo85ZH+lXMHnmhNtdRpLE+wefS0l255UyN16yoKb4AyIXQ7Cp3oN6wNEpi8mfxGphgTCAb2OOj8hd8Es/LaPV6Ky/o36GfEREJYHwGYQJWbMi03szls3Ca8PKSYZivAkVxu0EBAMJ4zkQligAJZTlzoUV2vVahSF8gblehCh/J2Eb1yvlj++YiA45KZEw= 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:(13230025)(366004)(136003)(346002)(376002)(396003)(39860400002)(451199018)(36756003)(2906002)(6486002)(83380400001)(53546011)(6506007)(66946007)(4326008)(2616005)(6666004)(478600001)(6512007)(26005)(316002)(6916009)(8676002)(41300700001)(66556008)(86362001)(5660300002)(38100700002)(66476007)(8936002)(186003)(84970400001)(56340200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?N0o1zgf6H7jU5GF4CMuZIjsEq0OIlt5NCVCqQpisM9qcykVlYpv6+eqcbITp?= =?us-ascii?Q?dG9eCcFBSMBzMgKqC6cvci2esKH8IBh9YEk1qN+oap2UkGv1gKJpyqpv4bCm?= =?us-ascii?Q?TFELyGI0+Vaqg2+c5sc8QRKbixc+Yyz9QWK0LdeGQWGRHiv3QpwXKZGwTxIH?= =?us-ascii?Q?gGsu544n5smdeKiSDrNYBnlGtJL9FYfVXzwmmq6HALB6Idaa46dvtSsqg7Pa?= =?us-ascii?Q?rqOz4gM0qnQY0VA2kpqbf1guYLO/Gf9zCZS10loWuba/R3rBSmBD+EMmftSA?= =?us-ascii?Q?L7lc1UHFjmrWJfLGziIGII6B/+Hxu6WiEMulsFx3pi90Cfxg8BOuj1FPAkm7?= =?us-ascii?Q?P5ScPeUXqPbDYkXt9QW5mqKYLXBcZ5zmdxCQLJ2tZNUizCLpmgc9hDUKsTGp?= =?us-ascii?Q?efocxQAz4tFraI27dubDqDFr8Zuqbmh2I0OP8Wqqq0CCCU3szHYmmYEsdcvT?= =?us-ascii?Q?rjG56oCYbCH/4CCLKWpevnCu/p2Ux0pne+wCIAGOOl+Q7BTOF3ZhwOVAD1yG?= =?us-ascii?Q?S1NfT6I+S4HWsCEfeUkxM5ELafgQWCaAsyFzkJntuvoTHxEHhKD6fNsC+evz?= =?us-ascii?Q?p3DnrcQAyhAhdGiSPlsm64a8YuL0POzc3P//8O4WRmnevq5AGCOukxNkuA4A?= =?us-ascii?Q?KwaBmtGcxfBMKo/z62vLKJTCeyGABtx1dfs+V1wDLiAW++WZtme2kE92Jh4h?= =?us-ascii?Q?BEvY/Ad4//I8PA2xFqgSEJ3WQoeu5mGF7xElDj1/MX2H869Pyhoos08ZTmSm?= =?us-ascii?Q?f8pd3UzqYUak4skcUQnR8VWVeS63ArX4k3bk1g9CX4DBIw+Eqr9Luu0Z7Z/A?= =?us-ascii?Q?F1v4N1nE+rZmMQ+TqbRlGEDv2RMeIQS3GiAYVugfLhypYfsJ3+RL8auPEl1F?= =?us-ascii?Q?xsZJ1krC0jlJb+WRYDf/Dm8lpOCdm5uZzyjexBHMOAPC/bwHy9r0eOl/D1lk?= =?us-ascii?Q?GpT1tKOJLZmIpaF7oa0pbQFr/7ARlzSSzkM9VSkd9yEDzopCNvEAtJfZOARp?= =?us-ascii?Q?BRKk4cIQuP9HueQ71yeEmXbvFCXpyWkLLpS+OJXnTQOkXpSsHi+A3KaeMP8o?= =?us-ascii?Q?lLPlNWlFmOXk/qwGv/jTVDpTmddi3p+56q2LKOXoMW1jSv1hBswoREcrJADT?= =?us-ascii?Q?shnCOuYCxzJEpBmURTYN0WONJ64Vmo/KVeNLlUqiYM+9LZQktsKrWaFT8VRB?= =?us-ascii?Q?r/22LaJQ0ts5jx+mVy/H+NpI7NU0OOJRoBJbAFZY57vC4p4iXebgreb/ewea?= =?us-ascii?Q?ZEB8xf/YWIVxETr84lFYYaNgRoZPe9vdPw1SmNyWYSquKm6Tj98E9gc4ggrU?= =?us-ascii?Q?YA0PMHYKhFEn9hiDhrZdVf1d3c4N+iYvSZeTjIv5Ef7/ClSEQPtvwryaag/G?= =?us-ascii?Q?lvKUkeJq2LFp5I6qtKz92i7nB/4lqYhTVeHpvihINJ/4RUbpjZGdCE8fo4SG?= =?us-ascii?Q?rGl5EfrLdLmmkpcve7RHbHsKq9K9rCGWa11C/TlxW0PFWYGUFbNyQdndS1rL?= =?us-ascii?Q?uLlFwnnN2R+s/LUZhrp8mIsjb9ujV2mhcfrVS6xH1fw97EE+UkakH5LK/bR1?= =?us-ascii?Q?DJf6RFNVXwf2dhU1lWVDbaJKhyMSXE8lVAgYTj03wjqfxEpZoNw95W1+8qHJ?= =?us-ascii?Q?8g=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: iG5U4QdGCbHOB4ker9l733Wryc8piPaUpoi5efanj3O3roI0oAYHMS7Cp6MPA1SskJHVVZXSt67c5orTqrUTAOyC/El2kGjfz3lSdzqifzTAxU6yDkR0aG6O20yq+ErIC/+KKjIQQTRB4Q8wyGqjdlWwjlnFTNAoUNanQ4btTbcHW48NrRarHLIzYstxxUnYZVFib1j/+06zZvPWsTYYRuoeNgwInRDQSbuLV9oXkfXXRSlO8YAndlx7k1LOmwO6hKKeaBnz5ZAaf0gEHcVZcXflYPFDwUWr09pFxctm9yySSx3Pi0jio7LywuODU2TsZkEJ4s08SE/BzqTRZZO/7cynzfUZE2ckzh0B8f8CGFNqsFZIlcYbCuISyeeX+Q9cdD2sCRyqJ4oAH9opZty724q6COEq9r3P23mC6McT2yomTIrwm9vjHcE3SZBGCK8EOUh1v81uVbjgPwpg41TwDPFVTNVgxlQP3tF1gUHG0GXUijiAEqXF/CMkVC8APG7r6fWSvZeDO4Ei7RYAMMeQi8mGDY/J8LAwLU5AahSuNna5NOkZrTRgESOyH2tHqQduOVNyKDHTLhNr7pyo9FcIZnmG4BrME9uruV+0AM1uw/s4q1ofGqTmIjKMM92AFCTiZi0qjoDqQ2Yh2awQB7RprtdzClBb+VYpgCiG8BN3OGtDv1AgFSVcK5ELKSrX99Ywg3hHKjg+B3yXMUFzkqBDwRZk4EEf22/i4f+XO2TUYzhD3TufkzQIruNhtpuvy875yONY1hotRmlTVtFU8hG3EQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fb57902a-e046-4887-84e0-08db02f3a386 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2888.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jan 2023 18:56:04.9211 (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: KJsAJnpLqBbqdq+NNgbVgzg3PFA66uesnf7g8ojxvxcLx3RwSdAjur+rFj5kLsVOQmJQoE2uu4cDQBhabMRmFLvKYo7t4lTolgAWarxcoFc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6324 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-30_17,2023-01-30_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301300179 X-Proofpoint-GUID: 0HbttOPZ1YjfbizWwbnWcaaTjT9tRJuW X-Proofpoint-ORIG-GUID: 0HbttOPZ1YjfbizWwbnWcaaTjT9tRJuW X-Spam-Status: No, score=-12.2 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: > On Thu, Dec 8, 2022 at 2:56 AM Jose E. Marchesi via Gcc-patches > wrote: >> >> The 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. > > I suspect this issue is also the same as PR 48783 . Yeah I kinda dropped the ball here. Will look into Jeff's suggestions on how to fix this without exhausting the CALL_INSN bits. > Thanks, > Andrew > >> >> 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": >> >> start_sequence (); >> ... >> expand_divmod (... signed ...); >> ... >> end_sequence (); >> >> start_sequence (); >> ... >> expand_divmod (... unsigned ...); >> ... >> end_sequence (); >> >> 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. >> >> 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. >> >> In these cases, the expand_divmod tries can contain calls to funcalls. >> For example, in BPF: >> >> start_sequence (); >> ... >> expand_divmod (... signed ...); -> This generates funcall to __divdi3 >> ... >> end_sequence (); >> >> start_sequence (); >> ... >> expand_divmod (... unsigned ...); -> This generates direct `div' insn. >> ... >> end_sequence (); >> >> The problem is that when a funcall is expanded, an accompanying global >> symbol definition is written in the output stream: >> >> .global __divdi3 >> >> And this symbol definition remains in the compiled assembly file, even >> if the sequence using the direct `div' instruction above is used. >> >> 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.) >> >> In order to fix this, this patch modifies expand_expr_divmod in the >> following way: >> >> - 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.) >> >> - If any of the tried expanded sequences contain a funcall, then the >> optimization is not attempted. >> >> A couple of BPF tests are also added to make sure this doesn't break >> at any point in the future. >> >> Tested in bpf-unknown-none and x86_64-linux-gnu. >> Regtested in x86_64-linux-gnu. No regressions. >> >> gcc/ChangeLog >> >> * expr.cc (expand_expr_divmod): Avoid side-effects of trying >> sequences involving funcalls in optimization. >> >> gcc/testsuite/ChangeLog: >> >> * 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 >> >> 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 = expand_divmod (mod_p, code, mode, treeop0, treeop1, >> - op0, op1, target, 1); >> + op0, op1, target, 1, OPTAB_WIDEN); >> rtx_insn *uns_insns = get_insns (); >> end_sequence (); >> start_sequence (); >> rtx sgn_ret = expand_divmod (mod_p, code, mode, treeop0, treeop1, >> - op0, op1, target, 0); >> + op0, op1, target, 0, OPTAB_WIDEN); >> rtx_insn *sgn_insns = get_insns (); >> end_sequence (); >> - unsigned uns_cost = seq_cost (uns_insns, speed_p); >> - unsigned sgn_cost = seq_cost (sgn_insns, speed_p); >> >> - /* If costs are the same then use as tie breaker the other other >> - factor. */ >> - if (uns_cost == sgn_cost) >> - { >> - uns_cost = seq_cost (uns_insns, !speed_p); >> - sgn_cost = seq_cost (sgn_insns, !speed_p); >> - } >> - >> - if (uns_cost < sgn_cost || (uns_cost == 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 = seq_cost (uns_insns, speed_p); >> + unsigned sgn_cost = seq_cost (sgn_insns, speed_p); >> + >> + /* If costs are the same then use as tie breaker the other >> + other factor. */ >> + if (uns_cost == sgn_cost) >> + { >> + uns_cost = seq_cost (uns_insns, !speed_p); >> + sgn_cost = seq_cost (sgn_insns, !speed_p); >> + } >> + >> + if (uns_cost < sgn_cost || (uns_cost == sgn_cost && unsignedp)) >> + { >> + 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/testsuite/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/testsuite/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; >> +} >> -- >> 2.30.2 >>