From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id ED9053858C5F for ; Sat, 14 Oct 2023 22:14:29 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org ED9053858C5F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=162.254.253.69 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697321672; cv=none; b=mdzct3iz198VpecsBXF0FWbK5dWPjihw5a59X4votOgQLc7Mi34L8gJPfGzUWA32ma74v1DluCG9UY/9v4/qoE8X3RYHV3ePWGPP0CIjfmFj6e9EltfVbaUsBB7LcU2gmTAyo/rv4D6P9rtKSfwGilW/FPkjqKRewGMmcBWvGYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697321672; c=relaxed/simple; bh=lpMxgiW38O4Afr0uH/lt+C3IOuFlvQK9mpb8pCExzIs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=slAAJo4HhiCIUu9ExfYi+ez8Cmqf55H7JbSOGVf7GXrlBcVrq4wMBLahaPrzYjMfF0ko17Ka2cwhQ/yed1JsvxCXx+8denBrDAiSY8UuWJpIV5UKidIfH9gHRpGARKGBbMcDCn8eDCt1HVLqVAsaSLUkzdZnshG/0alaJwZhz9M= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ED9053858C5F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=MR2vVSV+GOB3GYzxG/Fhjm0ftu6gxgnPrfv+xKX6ass=; b=iG423CJel8ysdwd1xlKKRx5rWb CnEhB2mq5KeBjmF67ImlF6N5mM2Gy/+1gzuUOwvBObw6lhFC1zAz9evLJXZMACn6awvIYrQx9ZUD7 9Q7C2l/zKQ5ieL+SxMvjW3zwWdu9WSFnjCpV2nYCs9Z226QBR5IbD6heS5Q2Woy3rhGMj1yf2M3q8 sJlPjy7xKWcYfhETvFQ19OPikrHYsbMKgbStStaM/B5yuJnEdGk8Z8Utq15QpnanARaKUA5oOXxcB CyY/aLiOAXVXn+ciqiKsSD2Imlb01l06ubnXk9AUBaL65aqtRekjecnZSoWpD5ybbNEDV38YnfksI t9xDZicg==; Received: from host86-160-20-38.range86-160.btcentralplus.com ([86.160.20.38]:59797 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.1) (envelope-from ) id 1qrmtx-0007XT-0F; Sat, 14 Oct 2023 18:14:29 -0400 From: "Roger Sayle" To: Cc: "'Jeff Law'" Subject: [PATCH] PR 91865: Avoid ZERO_EXTEND of ZERO_EXTEND in make_compound_operation. Date: Sat, 14 Oct 2023 23:14:29 +0100 Message-ID: <01f701d9feeb$ce8654e0$6b92fea0$@nextmovesoftware.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_01F8_01D9FEF4.304ABCE0" X-Mailer: Microsoft Outlook 16.0 Thread-Index: Adn+6udC0VRdkU1HTCGEixkG7umJPQ== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: 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,SPF_HELO_NONE,SPF_PASS,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: This is a multipart message in MIME format. ------=_NextPart_000_01F8_01D9FEF4.304ABCE0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit This patch is my proposed solution to PR rtl-optimization/91865. Normally RTX simplification canonicalizes a ZERO_EXTEND of a ZERO_EXTEND to a single ZERO_EXTEND, but as shown in this PR it is possible for combine's make_compound_operation to unintentionally generate a non-canonical ZERO_EXTEND of a ZERO_EXTEND, which is unlikely to be matched by the backend. For the new test case: const int table[2] = {1, 2}; int foo (char i) { return table[i]; } compiling with -O2 -mlarge on msp430 we currently see: Trying 2 -> 7: 2: r25:HI=zero_extend(R12:QI) REG_DEAD R12:QI 7: r28:PSI=sign_extend(r25:HI)#0 REG_DEAD r25:HI Failed to match this instruction: (set (reg:PSI 28 [ iD.1772 ]) (zero_extend:PSI (zero_extend:HI (reg:QI 12 R12 [ iD.1772 ])))) which results in the following code: foo: AND #0xff, R12 RLAM.A #4, R12 { RRAM.A #4, R12 RLAM.A #1, R12 MOVX.W table(R12), R12 RETA With this patch, we now see: Trying 2 -> 7: 2: r25:HI=zero_extend(R12:QI) REG_DEAD R12:QI 7: r28:PSI=sign_extend(r25:HI)#0 REG_DEAD r25:HI Successfully matched this instruction: (set (reg:PSI 28 [ iD.1772 ]) (zero_extend:PSI (reg:QI 12 R12 [ iD.1772 ]))) allowing combination of insns 2 and 7 original costs 4 + 8 = 12 replacement cost 8 foo: MOV.B R12, R12 RLAM.A #1, R12 MOVX.W table(R12), R12 RETA This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check, both with and without --target_board=unix{-m32} with no new failures. Ok for mainline? 2023-10-14 Roger Sayle gcc/ChangeLog PR rtl-optimization/91865 * combine.cc (make_compound_operation): Avoid creating a ZERO_EXTEND of a ZERO_EXTEND. gcc/testsuite/ChangeLog PR rtl-optimization/91865 * gcc.target/msp430/pr91865.c: New test case. Thanks in advance, Roger -- ------=_NextPart_000_01F8_01D9FEF4.304ABCE0 Content-Type: text/plain; name="patchmc.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patchmc.txt" diff --git a/gcc/combine.cc b/gcc/combine.cc=0A= index 360aa2f25e6..f47ff596782 100644=0A= --- a/gcc/combine.cc=0A= +++ b/gcc/combine.cc=0A= @@ -8453,6 +8453,9 @@ make_compound_operation (rtx x, enum rtx_code = in_code)=0A= new_rtx, GET_MODE (XEXP (x, 0)));=0A= if (tem)=0A= return tem;=0A= + /* Avoid creating a ZERO_EXTEND of a ZERO_EXTEND. */=0A= + if (GET_CODE (new_rtx) =3D=3D ZERO_EXTEND)=0A= + new_rtx =3D XEXP (new_rtx, 0);=0A= SUBST (XEXP (x, 0), new_rtx);=0A= return x;=0A= }=0A= diff --git a/gcc/testsuite/gcc.target/msp430/pr91865.c = b/gcc/testsuite/gcc.target/msp430/pr91865.c=0A= new file mode 100644=0A= index 00000000000..8cc21c8b9e8=0A= --- /dev/null=0A= +++ b/gcc/testsuite/gcc.target/msp430/pr91865.c=0A= @@ -0,0 +1,8 @@=0A= +/* { dg-do compile } */=0A= +/* { dg-options "-O2 -mlarge" } */=0A= +=0A= +const int table[2] =3D {1, 2};=0A= +int foo (char i) { return table[i]; }=0A= +=0A= +/* { dg-final { scan-assembler-not "AND" } } */=0A= +/* { dg-final { scan-assembler-not "RRAM" } } */=0A= ------=_NextPart_000_01F8_01D9FEF4.304ABCE0--