From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 176C73858D3C; Sat, 23 Dec 2023 16:51:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 176C73858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 176C73858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::332 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703350302; cv=none; b=Z+8SmhUpj7rMp4Jfz8YqKkAQersEoLvOGpgBL01S/r6oYX90kOpjfBEWCPSWPBnWhhpKzq+6ySXjO4UEz7fugITMu5TQAbbyqhNsUD2KOKGO11YL+sBpot7lNagw1YZHQijd2agBdOw+zQZHzi0wr3L0MQqykSIckvWTv3F/ypE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703350302; c=relaxed/simple; bh=/vGsO9eP+cnKrg+fNJu1Playb7b2EnC8a4jVYyeN6D4=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=G+HghSQn/4y/Dv5Gkb4qoYE5MOgIrdvWnccZ/HJOcxBzvAkYiavwwkqrrAzjNa0ibNXSGj1IiogsveyppiQIBiFOhOco8GCQlqWQVhnFt94PDF34mAlEhEArb5PDKIoDCHGwn/cqDEVAPARLuSJsqgd7cqfXBLQEdQMX4e5CXmM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-6dbc4675749so844739a34.3; Sat, 23 Dec 2023 08:51:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703350298; x=1703955098; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=eSMurxTX6DgK53Vey+dwH2rfNKJYVZ+MjHPdIm+n15I=; b=SBSL1mn/IyZ+IlN122EeNhyuxq77tMJuzB30KYI3uAPgRIYI7O3y8M77ug1im11IxF Jh25sSK2j3B9noCSF1Sc0o0J3WBXq6tqla6FnPdG5HnPMWpvOMee5/ulX8UwQkPQPSyX a8P5EtPD/2j6P91gYkr0HZSfV7qJkWf66eB3umhVGfoNr6Nif/4xnQ81IyVN8eHhVD1A 7s2zctbRPvKcJkRiaMtqgbkc3yvODij0aozknggOzVDcCyu9QUdy+oDDQdbbw49SScc2 WQfVy1MA+jOsTd1VZbevfyZoyR3rFyiu18KeRxv8+bECpoUwAPNRswDzXR7EAkFqZ36A +LZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703350298; x=1703955098; h=content-transfer-encoding:in-reply-to:from:references:cc: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=eSMurxTX6DgK53Vey+dwH2rfNKJYVZ+MjHPdIm+n15I=; b=UK4pLjTPOZdaa5DWefXZeeFev3I9n36wS59MwMjuYVlaEHaa73y1p2MttQX0dOAjxN vAv8troG3M1PRgYXvYMvQpkjqnGSylnsprKvZRVnW7ZQEm50iNR1+arQFGy3xh8oCCWU avH5fy6N1kWe32rR2P78G2WbKWhDYUa13vZ1EawjQ1564PN0Dy5O3nlwaYyIwSy1HEpG doxxSblUdVos8KpuBlREo9gRyw9hRaQcxtpEPgSIVDf91XweBdgD6HmYjIK1XRZfnxRO uxsqEUoim8F25Wm396RrFj4nY2DqWSp4hbpGRYWfbLDaVahLjl5v73jLA4sQ1QVXkT8H hoWg== X-Gm-Message-State: AOJu0YzS7gkpKx/JIHjatmSMDIzu+TJZ8FinoFcm4rA3jJHCMvkA3Tew FmsLQe40fGvyq+LPKbKUw4kTwiX2glE= X-Google-Smtp-Source: AGHT+IEMO3+e76BWC5IlVA1GHlYd/bSrOkI9CDKM5SMvLSuaZpYQutfoR0oo6btttU2L9XhNkMcg0w== X-Received: by 2002:a05:6808:2f10:b0:3b9:e8d0:6df0 with SMTP id gu16-20020a0568082f1000b003b9e8d06df0mr4281946oib.24.1703350298096; Sat, 23 Dec 2023 08:51:38 -0800 (PST) Received: from [172.31.1.103] ([172.56.168.179]) by smtp.gmail.com with ESMTPSA id k188-20020a633dc5000000b005ce033f3b54sm1395463pga.27.2023.12.23.08.51.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 23 Dec 2023 08:51:37 -0800 (PST) Message-ID: <04a01582-2bff-496f-95b1-4643b5a2f494@gmail.com> Date: Sat, 23 Dec 2023 09:51:34 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] EXPR: Emit an truncate if 31+ bits polluted for SImode Content-Language: en-US To: YunQiang Su , gcc-patches@gcc.gnu.org Cc: richard.sandiford@arm.com, pinskia@gmail.com, rguenther@suse.de References: <20231223085858.4136369-1-syq@gcc.gnu.org> From: Jeff Law In-Reply-To: <20231223085858.4136369-1-syq@gcc.gnu.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_SBL_CSS,SPAM_BODY,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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 12/23/23 01:58, YunQiang Su wrote: > On TRULY_NOOP_TRUNCATION_MODES_P (DImode, SImode)) == true platforms, > if 31 or above bits is polluted by an bitops, we will need an > truncate. Let's emit one, and mark let's use the same hardreg > as in and out, the RTL may like: > > (insn 21 20 24 2 (set (subreg/s/u:SI (reg/v:DI 200 [ val ]) 0) > (truncate:SI (reg/v:DI 200 [ val ]))) "../xx.c":7:29 -1 > (nil)) > > We use /s/u flags to mark it as really needed, as in > combine_simplify_rtx, this insn may be considered as truncated, > so let's skip this combination. > > gcc/ChangeLog: > PR: 104914. > * combine.cc (try_combine): Skip combine with truncate if > dest is subreg and has /u/s flags on platforms > TRULY_NOOP_TRUNCATION_MODES_P (DImode, SImode)) == true. > * expr.cc (expand_assignment): Emit a truncate insn, if > 31+ bits is polluted for SImode. > > gcc/testsuite/ChangeLog: > PR: 104914. > * gcc.target/mips/pr104914.c: New testcase. I would suggest you show the RTL before/after whatever transformation has caused problems on your target and explain why you think the transformation is incorrect. Focus on the RTL semantics as well as the target specific semantics because both are critically important here. I strongly suspect you're just papering over a problem elsewhere. > --- > gcc/combine.cc | 23 +++++++++++++++++++++- > gcc/expr.cc | 17 ++++++++++++++++ > gcc/testsuite/gcc.target/mips/pr104914.c | 25 ++++++++++++++++++++++++ > 3 files changed, 64 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/gcc.target/mips/pr104914.c > > diff --git a/gcc/combine.cc b/gcc/combine.cc > index 1cda4dd57f2..04b9c414053 100644 > --- a/gcc/combine.cc > +++ b/gcc/combine.cc > @@ -3294,6 +3294,28 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0, > n_occurrences = 0; /* `subst' counts here */ > subst_low_luid = DF_INSN_LUID (i2); > > + /* Don't try to combine a TRUNCATE INSN, if it's DEST is SUBREG and has > + FLAG /s/u. We use these 2 flags to mark this INSN as really needed: > + normally, it means that the bits of 31+ of this variable is polluted > + by a bitops. The reason of existing of case (subreg:SI (reg:DI)) is > + that, the same hardreg may act as src and dest. */ > + if (TRULY_NOOP_TRUNCATION_MODES_P (DImode, SImode) > + && INSN_P (i2)) > + { > + rtx i2dest_o = SET_DEST (PATTERN (i2)); > + rtx i2src_o = SET_SRC (PATTERN (i2)); > + if (GET_CODE (i2dest_o) == SUBREG > + && GET_MODE (i2dest_o) == SImode > + && GET_MODE (SUBREG_REG (i2dest_o)) == DImode > + && SUBREG_PROMOTED_VAR_P (i2dest_o) > + && SUBREG_PROMOTED_GET (i2dest_o) == SRP_SIGNED > + && GET_CODE (i2src_o) == TRUNCATE > + && GET_MODE (i2src_o) == SImode > + && rtx_equal_p (SUBREG_REG (i2dest_o), XEXP (i2src_o, 0)) > + ) > + return 0; > + } So checking SI/DI like this is just wrong. There's nothing special about SI/DI. Checking for equality between the destination and source also seems wrong -- if the state of the sign bit is wrong, it's wrong regardless of whether or not the source/destination register is the same. > > @@ -5326,7 +5348,6 @@ find_split_point (rtx *loc, rtx_insn *insn, bool set_src) > > UNIQUE_COPY is true if each substitution must be unique. We do this > by copying if `n_occurrences' is nonzero. */ > - > static rtx > subst (rtx x, rtx from, rtx to, bool in_dest, bool in_cond, bool unique_copy) > { > diff --git a/gcc/expr.cc b/gcc/expr.cc > index 9fef2bf6585..f7236040a34 100644 > --- a/gcc/expr.cc > +++ b/gcc/expr.cc > @@ -6284,6 +6284,23 @@ expand_assignment (tree to, tree from, bool nontemporal) > nontemporal, reversep); > convert_move (SUBREG_REG (to_rtx), to_rtx1, > SUBREG_PROMOTED_SIGN (to_rtx)); > + > + rtx last = get_last_insn (); > + if (TRULY_NOOP_TRUNCATION_MODES_P (DImode, SImode) > + && known_ge (bitregion_end, 31) > + && SUBREG_PROMOTED_VAR_P (to_rtx) > + && SUBREG_PROMOTED_SIGN (to_rtx) == SRP_SIGNED > + && GET_MODE (to_rtx) == SImode > + && GET_MODE (SUBREG_REG (to_rtx)) == DImode > + && GET_CODE (SET_SRC (PATTERN (last))) == SIGN_EXTEND > + ) > + { > + insn_code icode = convert_optab_handler > + (trunc_optab, SImode, DImode); > + if (icode != CODE_FOR_nothing) > + emit_unop_insn (icode, to_rtx, > + SUBREG_REG (to_rtx), TRUNCATE); > + } Similar comments about the modes apply here. But again, my sense is there's a higher level problem here and that these changes are just papering over it. Jeff