From patchwork Sat Oct 14 22:14:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1848856 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=iG423CJe; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S7Hjd1kTTz20Vq for ; Sun, 15 Oct 2023 09:14:45 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C24B3858C3A for ; Sat, 14 Oct 2023 22:14:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 diff --git a/gcc/combine.cc b/gcc/combine.cc index 360aa2f25e6..f47ff596782 100644 --- a/gcc/combine.cc +++ b/gcc/combine.cc @@ -8453,6 +8453,9 @@ make_compound_operation (rtx x, enum rtx_code in_code) new_rtx, GET_MODE (XEXP (x, 0))); if (tem) return tem; + /* Avoid creating a ZERO_EXTEND of a ZERO_EXTEND. */ + if (GET_CODE (new_rtx) == ZERO_EXTEND) + new_rtx = XEXP (new_rtx, 0); SUBST (XEXP (x, 0), new_rtx); return x; } diff --git a/gcc/testsuite/gcc.target/msp430/pr91865.c b/gcc/testsuite/gcc.target/msp430/pr91865.c new file mode 100644 index 00000000000..8cc21c8b9e8 --- /dev/null +++ b/gcc/testsuite/gcc.target/msp430/pr91865.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mlarge" } */ + +const int table[2] = {1, 2}; +int foo (char i) { return table[i]; } + +/* { dg-final { scan-assembler-not "AND" } } */ +/* { dg-final { scan-assembler-not "RRAM" } } */