From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 549E03858D20 for ; Sat, 14 Oct 2023 23:02:47 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 549E03858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697324569; cv=none; b=ojsBETCTCx3v7EhZ8tvVZcYZrrRMxQpKFeNqTIKlV/1oDbM+9aqubmYifG2BS/OPU+Zov80IUTus4XZSAlpGxZH3Mm1uSdLMfZTWRCT3eLHANvbFVtDBeEuT5C3xmUNlIFQKy3/Dh8aj6IWpXOU7NPyK9wYvqczzF87ozaL/vEY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697324569; c=relaxed/simple; bh=aHKrm2lV1ICTmoj/nyd5nIH2GIWryscktcAbZHOJD+M=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=FcgAaBWVS8tZiz+6G6vLGtwb40m8e+gJE5BhalIL5jhyiTLjFwknqD4pHDBe4f00OdK0kqH69wahCTx2qMOxF1dFm1vMLgdTiFy7fxAsl7bGeaNixiBdjOB/h8Jd8zmncAWRig2i2UQGjoJhLoK9cuNqIKgsxokKpp9m27D6MEo= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 549E03858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6b497c8575aso1543404b3a.1 for ; Sat, 14 Oct 2023 16:02:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697324566; x=1697929366; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ztERNm+DTGpMaYIjR+ZHH8Th10OM19IBq449KzYFPiQ=; b=T6LsnP3JC3r5PioI1M30712wdgNpoCMHYQteABayjel8RRRFDl9oYJQrODu0dIkHL6 frsKoS7DCRIjj6KDBzk2IHh8wZrGTdpFFrdZKoZc0YFkpZFXvs0lfXeK4xFQctr0VY1D n9cnl/1oAYN++/P3HFBagwwfldG02c6/CwdXbbd9NRJvEnBTKgo+ZKL8Riz5q9Ewci2e semvTydt2CqMhaPBliMGD/45MMZi2dmKd60RDG8NXOe2IX3Ie7AtBvbOv9mGw+Ldfv/M Tc/K1rrFut1L2+AB881abgxy8aTJV3ki5rWAxz4bI1LTRWDN93YVrNwxXWdMfI3bL9/m 4aog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697324566; x=1697929366; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ztERNm+DTGpMaYIjR+ZHH8Th10OM19IBq449KzYFPiQ=; b=nBc33b+/x31ORDEKDJio0I+gPeaK1mpqUYMUgi7iZ3czYhQ09KxrpetJlk5fuNWobA Eoq7pz2oqJOd4XdTg7yuN+34CLx+FqcIynBJdRGhQ6/KRsSrXhdRj8qBmi2LsaviuQRG b4tYir+YkWrGrOCIu8piVmX3Mn20232mlaOT1t4JHgf6AqJKawoAE3OwOM/xRw+Qh/cm BvBax8fids5ZoblrC08MqldBNaRvOoSM2JA7um2xzV0WuOIwtiihV/TfikYzA1XDTWfN 85/ZlIRGMVz9lmqhclNSJB9Cg7ehZwexLXEyprWEdn9+s1sqPsOPUSBZhiITBpb19E3o crBw== X-Gm-Message-State: AOJu0YyrmRFsCvTJvJuzuAngnKj4g19YkrVECPBx8D0GYPjM+EXPhOky +PeLt68XnmCRnokAVOgv6C0f2SSE+no= X-Google-Smtp-Source: AGHT+IGOJetNJkKhP779KT8hARUXcR4CzFUiYeKcLMG85wWqvHLtOOqTvgL7bShwx0rPwU21yZzFRg== X-Received: by 2002:a05:6a00:1587:b0:6b4:6b34:8ce0 with SMTP id u7-20020a056a00158700b006b46b348ce0mr5937003pfk.31.1697324566057; Sat, 14 Oct 2023 16:02:46 -0700 (PDT) Received: from [172.31.0.109] ([136.36.130.248]) by smtp.gmail.com with ESMTPSA id f24-20020aa78b18000000b0068fd026b496sm15279793pfd.46.2023.10.14.16.02.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 14 Oct 2023 16:02:45 -0700 (PDT) Message-ID: <443998e0-99f3-4b67-972e-0f6746cc4c9c@gmail.com> Date: Sat, 14 Oct 2023 17:02:40 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] PR 91865: Avoid ZERO_EXTEND of ZERO_EXTEND in make_compound_operation. Content-Language: en-US To: Roger Sayle , gcc-patches@gcc.gnu.org References: <01f701d9feeb$ce8654e0$6b92fea0$@nextmovesoftware.com> From: Jeff Law In-Reply-To: <01f701d9feeb$ce8654e0$6b92fea0$@nextmovesoftware.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,RCVD_IN_DNSWL_NONE,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: On 10/14/23 16:14, Roger Sayle wrote: > > 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. Neither an ACK or NAK at this point. The bug report includes a patch from Segher which purports to fix this in simplify-rtx. Any thoughts on Segher's approach and whether or not it should be considered? The BZ also indicates that removal of 2 patterns from msp430.md would solve this too (though it may cause regressions elsewhere?). Any thoughts on that approach as well? Thanks, jeff