From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80084.outbound.protection.outlook.com [40.107.8.84]) by sourceware.org (Postfix) with ESMTPS id 16212385703B for ; Mon, 26 Oct 2020 13:19:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 16212385703B Received: from AM6PR10CA0056.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:80::33) by AM6PR08MB3335.eurprd08.prod.outlook.com (2603:10a6:209:4c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18; Mon, 26 Oct 2020 13:19:36 +0000 Received: from AM5EUR03FT009.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:80:cafe::fa) by AM6PR10CA0056.outlook.office365.com (2603:10a6:209:80::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Mon, 26 Oct 2020 13:19:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; gcc.gnu.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;gcc.gnu.org; dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT009.mail.protection.outlook.com (10.152.16.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Mon, 26 Oct 2020 13:19:36 +0000 Received: ("Tessian outbound a64c3afb6fc9:v64"); Mon, 26 Oct 2020 13:19:35 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 19ee39944e2ac8b9 X-CR-MTA-TID: 64aa7808 Received: from afa9cf015e55.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 516BDC54-C597-4AAE-8A38-788756FBE44B.1; Mon, 26 Oct 2020 13:18:58 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id afa9cf015e55.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 26 Oct 2020 13:18:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OHyYKLKFoR2LbPkpX/6G17xyymN3FzDUK2fp9xt/D+g5k02vZA3Z+Al9/nHdpcAOOquPeXu1I6KLtI+haviHpkp7mJBWHHWatGqVTl3WrVFZWVKmylCwQrMO9XnSV+LRteveUiI2NbjXFL/59lPb7R23nVZcn8iOQ0iLhj9/mgY6McqmS5UgSliTyaQJsOV80HRYt3wAgRz+p0pSNOUsAVOmPTWbt0+4d0sVj7VzP5jUSR7HZAEmI/4PNFMSkJhq3cSjSH7rB8eYMyerxum2NG/Yegd231oo5uUz/wdOMDdYZGwWfXKwDSUml5puREo2LZL//JwZ07q+TMOQFuqlfg== 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-SenderADCheck; bh=r0ioJk5MEhjD1vaXwF8vEoiF5J1fV6MXLtIbk9op7JE=; b=g4FwPC10VA/Ta65+GNO0zJlJnRLYQBDrmJuAe3qwtg6rcvC1zz0AHOsN4F8s++lyhBBh1FuB0MCm1GGBP/Nex9UHJCa97etX8UQP3+iBhTdwXnjUiPdtu6pmN4VRmskn9GEfY0CBAxVFVWW3jTpSwXz0hQXRG8PRoVDdTWnRpA3CORVQheZGi7C6jL4lOz68OrvztfWOuj0DJ2SW4h2Qf/D5M4JG+knfI6/67rs1I+wzpWtRxCQSDEUFWN9UKdFl2zmMbvQFSAD1S9D/iVH0xlbv8qXTz5jn5AHb8miAkihCY/MpVLfVz90Sn/Alm76pG5oD3l5cOyKit/feXLqwjA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: kernel.crashing.org; dkim=none (message not signed) header.d=none;kernel.crashing.org; dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB4029.eurprd08.prod.outlook.com (2603:10a6:803:ec::14) by VI1PR08MB4285.eurprd08.prod.outlook.com (2603:10a6:803:f8::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.20; Mon, 26 Oct 2020 13:18:56 +0000 Received: from VI1PR08MB4029.eurprd08.prod.outlook.com ([fe80::9d3c:5e65:2ad4:a5c6]) by VI1PR08MB4029.eurprd08.prod.outlook.com ([fe80::9d3c:5e65:2ad4:a5c6%7]) with mapi id 15.20.3477.029; Mon, 26 Oct 2020 13:18:56 +0000 Date: Mon, 26 Oct 2020 13:18:54 +0000 From: Alex Coplan To: Segher Boessenkool Cc: gcc-patches@gcc.gnu.org, Richard Sandiford Subject: Re: [PATCH 2/2] combine: Don't turn (mult (extend x) 2^n) into extract Message-ID: <20201026131852.fusxjvqrkoo2vwa2@arm.com> References: <20201015085922.qmtum7kw2dlaixq3@arm.com> <20201022203950.GW2672@gate.crashing.org> <20201026100940.3o4clltk76sdsluf@arm.com> <20201026104806.GR2672@gate.crashing.org> <20201026110620.xxwowuw6og4dlaqg@arm.com> <20201026115148.GS2672@gate.crashing.org> Content-Type: multipart/mixed; boundary="tmja5itdh72phrpy" Content-Disposition: inline In-Reply-To: <20201026115148.GS2672@gate.crashing.org> User-Agent: NeoMutt/20171215 X-Originating-IP: [217.140.106.53] X-ClientProxiedBy: PR1PR01CA0032.eurprd01.prod.exchangelabs.com (2603:10a6:102::45) To VI1PR08MB4029.eurprd08.prod.outlook.com (2603:10a6:803:ec::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from arm.com (217.140.106.53) by PR1PR01CA0032.eurprd01.prod.exchangelabs.com (2603:10a6:102::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.22 via Frontend Transport; Mon, 26 Oct 2020 13:18:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 97de2b32-fa02-4460-d495-08d879b1c8f9 X-MS-TrafficTypeDiagnostic: VI1PR08MB4285:|AM6PR08MB3335: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: /h5LYh3r6gcqJhdJd7/FDMAZmhjjXFu/cUELUZhkG4shHcAKqPCBdwS+P7BU+pwYMCUoNH3fOgAQRuzcOUTw9zhy0w5RGmaqWmQM9KKB7mDNIWHE6i7VQRvnnxtGp1o/Dli51VOMlALkUeQ6HPp1dk/9DvvVRRWs+rfEXMmjtf7wdnM8BqiZu3KR4mKPcIoMLaAxMqcxBkQs9AG8+XtCrv2tekHGXgX3c3Zw/vRTDaRaWl75UG365eYlbgf8D38cfjaHDdNAnGN0PU2GJZZo/xqcBNHOMNJ7Y+1VDtk6eAycp8aQtNGBzvVra5VbrVb7j+XDtK6ITcrQpNVJ6X11WJrFGjfB1SW2HPJkuACmQYqnfYXI5GWNZcS1Y+DZyBnbzKkUjmZFO2Q+ZF9unUvKtw== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR08MB4029.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(376002)(346002)(366004)(136003)(39860400002)(66616009)(4326008)(478600001)(83380400001)(26005)(6916009)(2906002)(21480400003)(8886007)(44832011)(86362001)(316002)(66476007)(66556008)(8936002)(7696005)(52116002)(66946007)(8676002)(16526019)(186003)(33964004)(36756003)(235185007)(956004)(1076003)(5660300002)(2616005)(55016002)(53546011)(44144004)(81973001)(2700100001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 2qkl6V3iKL/7bx/m8dh5DRpDkUaG6n1jmaf2TDb6XJFCrMhIK94anQgchz2Wv0VDey7aouj5GjC6BmVRVhfZs+Lau85GvRKtVROspcX+t8JdZuJTYG8tvGSuz06JiQJ04uCuCQIagjInyi1AlBAkW7xrx9E7X2NxsTJKEr92pQB6WpGtcNPrIvFjHscGIVgrpTFdfgU96IOzlYLz3LVeiHgmnndxrHM1ZBMEW/zPFdAr18q+1jpEPfKhpEJTHGbIYw9bC1WGBTvfNYWTyq4078skeigm/ueMUBtHZ6/jrrFVvsKS0UcuiaRcMamK7dKR4iRTuSLTGJZiuhN3KiORgluWGEUlmG+EYh4ca5kUqQfv55Fc8N2gJuDvbWPhuyRbF2MRDdvPyEI2WF3z2rT3U2nCyDNyDevnigB6/2PsrwpxKsu6ldk9vuES25QGIW74b33QqzHyJ7Zr1qqMxdhEYHZNHMIyOKjevPIKdNut7yANEmYtwmhez2dVbZiuwto4H6whLyvdoyxSBr9U3DlpB4udJmqIWsrRY/lrPswNPDibwiWlxXT3bnbnCiywcaeoE6hVFtn/KF3FS4THsXGoQwS+zgJz1wrCbWAXL9zB2HI95HmndELKhDXHbrCZGa/mehOancBYwb8pUEzCAZyKYA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB4285 Original-Authentication-Results: kernel.crashing.org; dkim=none (message not signed) header.d=none;kernel.crashing.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT009.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: c11b788b-c315-4621-03c3-08d879b1b13b X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Bj5TUT+nWWv8yzk61fGnkl6+G92tFG9im7PWEV4S7GCJJBc/FpiWAAqrHdczNYPeK49/3Nn5ONSFFkZC5xkQSd6IBu2a5sMuuSdpvTeHE+04uWGpp3eO8wWNOBd9FGSJ9vuh4a+7EjF25QUhaV6aCQtipyh1lwHiEDcu91boR/OgZUuNoakA8XYQTjFfu3H+rw41QQp3gp0MuQC9VYU0Qh83aLQ9UPO93CJP8c0ls6OAngoUfN5pnwUe0nqidlHn9G6JHsz7p/dbpJnrE9rF+pxXp+m3y7V0iWWZq6OZ9DUGwdML//CvjfOUpbogGz21isKv5emplI2ZXs5xKCwNRoZc0fMyUJsioyKw5MIJ86Zy/IFrVBLf2wsQkwWHXIXow3JhH0K0bMECF8baPCcgAaHeyeHZcCkSztgK2EkXwTNILqCHw3WUJ8p6ND/b0PhVXey2rHtQ2VPWta2VVmSUow== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(39860400002)(136003)(396003)(376002)(346002)(46966005)(44144004)(33964004)(44832011)(81166007)(70206006)(82740400003)(55016002)(336012)(8886007)(6862004)(66616009)(70586007)(7696005)(83380400001)(235185007)(2906002)(1076003)(5660300002)(82310400003)(356005)(53546011)(21480400003)(478600001)(956004)(47076004)(316002)(2616005)(36906005)(8936002)(4326008)(16526019)(26005)(186003)(8676002)(36756003)(86362001)(81973001)(2700100001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2020 13:19:36.0303 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 97de2b32-fa02-4460-d495-08d879b1c8f9 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT009.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3335 X-Spam-Status: No, score=-15.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Oct 2020 13:19:50 -0000 --tmja5itdh72phrpy Content-Type: text/plain; charset=utf-8 Content-Disposition: inline On 26/10/2020 06:51, Segher Boessenkool wrote: > On Mon, Oct 26, 2020 at 11:06:22AM +0000, Alex Coplan wrote: > > Well, only the low 32 bits of the subreg are valid. But because those > > low 32 bits are shifted left 2 times, the low 34 bits of the ashift are > > valid: the bottom 2 bits of the ashift are zeros, and the 32 bits above > > those are from the inner SImode reg (with the upper 62 bits being > > undefined). > > Ugh. Yes, I think you are right. One more reason why we should only > use *explicit* sign/zero extends, none of this confusing subreg > business :-( Yeah. IIRC expand_compound_operation() introduces the subreg because it explicitly wants to rewrite the sign_extend using a pair of shifts (without using an extend rtx). Something like: (ashiftrt:DI (ashift:DI (subreg:DI (reg:SI r) 0) (const_int 32)) (const_int 32)) > > > > > diff --git a/gcc/combine.c b/gcc/combine.c > > > > index c88382efbd3..fe8eff2b464 100644 > > > > --- a/gcc/combine.c > > > > +++ b/gcc/combine.c > > > > @@ -7419,8 +7419,8 @@ expand_compound_operation (rtx x) > > > > } > > > > > > > > /* If we reach here, we want to return a pair of shifts. The inner > > > > - shift is a left shift of BITSIZE - POS - LEN bits. The outer > > > > - shift is a right shift of BITSIZE - LEN bits. It is arithmetic or > > > > + shift is a left shift of MODEWIDTH - POS - LEN bits. The outer > > > > + shift is a right shift of MODEWIDTH - LEN bits. It is arithmetic or > > > > logical depending on the value of UNSIGNEDP. > > > > > > > > If this was a ZERO_EXTEND or ZERO_EXTRACT, this pair of shifts will be > > > > > > MODEWIDTH isn't defined here yet, it is initialised just below to > > > MODE_PRECISION (mode). > > > > Yes, but bitsize isn't defined at all in this function AFAICT. Are > > comments not permitted to refer to variables defined immediately beneath > > them? > > Of course you can -- comments are free form text after all -- but as > written it suggest there already is an initialised variable "modewidth". > > Just move the initialisation to above this comment? Sure, see the revised patch attached. Thanks, Alex --tmja5itdh72phrpy Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="patch.txt" diff --git a/gcc/combine.c b/gcc/combine.c index 4782e1d9dcc..d4793c1c575 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -7418,9 +7418,11 @@ expand_compound_operation (rtx x) } + modewidth = GET_MODE_PRECISION (mode); + /* If we reach here, we want to return a pair of shifts. The inner - shift is a left shift of BITSIZE - POS - LEN bits. The outer - shift is a right shift of BITSIZE - LEN bits. It is arithmetic or + shift is a left shift of MODEWIDTH - POS - LEN bits. The outer + shift is a right shift of MODEWIDTH - LEN bits. It is arithmetic or logical depending on the value of UNSIGNEDP. If this was a ZERO_EXTEND or ZERO_EXTRACT, this pair of shifts will be @@ -7433,7 +7435,6 @@ expand_compound_operation (rtx x) extraction. Then the constant of 31 would be substituted in to produce such a position. */ - modewidth = GET_MODE_PRECISION (mode); if (modewidth >= pos + len) { tem = gen_lowpart (mode, XEXP (x, 0)); @@ -7650,20 +7651,27 @@ make_extraction (machine_mode mode, rtx inner, HOST_WIDE_INT pos, is_mode = GET_MODE (SUBREG_REG (inner)); inner = SUBREG_REG (inner); } - else if (GET_CODE (inner) == ASHIFT + else if ((GET_CODE (inner) == ASHIFT || GET_CODE (inner) == MULT) && CONST_INT_P (XEXP (inner, 1)) - && pos_rtx == 0 && pos == 0 - && len > UINTVAL (XEXP (inner, 1))) - { - /* We're extracting the least significant bits of an rtx - (ashift X (const_int C)), where LEN > C. Extract the - least significant (LEN - C) bits of X, giving an rtx - whose mode is MODE, then shift it left C times. */ - new_rtx = make_extraction (mode, XEXP (inner, 0), - 0, 0, len - INTVAL (XEXP (inner, 1)), - unsignedp, in_dest, in_compare); - if (new_rtx != 0) - return gen_rtx_ASHIFT (mode, new_rtx, XEXP (inner, 1)); + && pos_rtx == 0 && pos == 0) + { + const HOST_WIDE_INT ci = INTVAL (XEXP (inner, 1)); + const auto code = GET_CODE (inner); + const HOST_WIDE_INT shift_amt = (code == MULT) ? exact_log2 (ci) : ci; + + if (shift_amt > 0 && len > (unsigned HOST_WIDE_INT)shift_amt) + { + /* We're extracting the least significant bits of an rtx + (ashift X (const_int C)) or (mult X (const_int (2^C))), + where LEN > C. Extract the least significant (LEN - C) bits + of X, giving an rtx whose mode is MODE, then shift it left + C times. */ + new_rtx = make_extraction (mode, XEXP (inner, 0), + 0, 0, len - shift_amt, + unsignedp, in_dest, in_compare); + if (new_rtx) + return gen_rtx_fmt_ee (code, mode, new_rtx, XEXP (inner, 1)); + } } else if (GET_CODE (inner) == TRUNCATE /* If trying or potentionally trying to extract --tmja5itdh72phrpy--