From patchwork Sat Oct 12 15:05:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1996420 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=YNohhvTw; 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 4XQmyw0ZxCz1xtp for ; Sun, 13 Oct 2024 02:06:00 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E42673858282 for ; Sat, 12 Oct 2024 15:05:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by sourceware.org (Postfix) with ESMTPS id D72903858C60 for ; Sat, 12 Oct 2024 15:05:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D72903858C60 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ventanamicro.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D72903858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728745528; cv=none; b=iDRs+swCPxuJPHJEDKSoNsP4jKyUIZpokE7HU9uq7QECDfvhnIwdicsLkljHoWctROaxX1r/EcFo/YtQaL35ONoY/FgLyoBUbvdZbcPAy7VwsugH3CU38occUs/Ae9T14Iz0XtoxBR0/pAhDyQjlH5GUX/ttnWybECtWntT5v7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728745528; c=relaxed/simple; bh=vhhviU9rhaTe/wR1Y+Mbd+GiLAEgbD3Avy5crE0Yi2w=; h=DKIM-Signature:Message-ID:Date:MIME-Version:From:Subject:To; b=hN9wokqzVFHEKn1K8A68oSy34HTTd4AowjYPrfEIbskv79YYBM//oFLHeBsQR82xym7e04swUJNcZ4OadUeiRBPnca8AC97JzkQ9x+jEpAx08LtM49mqeyUbxVy8fa3Ln1tS8jmIOMaiTzXzycUpFPAhoQVwEmoHH3o1N0vTwv0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-7163489149eso2414440a12.1 for ; Sat, 12 Oct 2024 08:05:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1728745524; x=1729350324; darn=gcc.gnu.org; h=to:subject:from:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=9zXynUGjjiaPNSOar8kjUTKFtyE2RQKubfGyHjtn07I=; b=YNohhvTwOnFGkt0Nm0xKSh2sEvMXKG2Clwbp52aXE133LbE3JZnXm5xXtP6SmLeGbr t5hUV6AOeSSCWfq0mGYcmaiDCyX6W5hxlU3rvVPIc69pLhQRGIGDphbpEnEvyxymoh4e 2VSHydkNq7HZCN5vpj6z1PoiK6mE+fAwc2LwNfriATsYOyuxGaTFQosqKrSonkvYo2FV wEwil2PSbB0e9ONWzOApXT5t4CCJ/bro3AEwNVHCPn0FCnB70Gb3CDoQmE6XhuK6OJPj km1L72mWQ81y/lLyvSjvsH1pLoFgXtvruWENS77fWwtFzwNP8JDvXBvJS/4RRcjl1/sH 4/0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728745524; x=1729350324; h=to:subject:from:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=9zXynUGjjiaPNSOar8kjUTKFtyE2RQKubfGyHjtn07I=; b=Dukzm1hnh6+DAig7agzxKEDEzPbinviNh3KK9yeMJFxHeAhYMpyaedJZgaRC8rFfcJ ipOLmSFnqYwRaCpG1Mmit/2LLxLJfSQH54g0wDxa85jOy1MZXVgpLJi47Yl5N9MATnzs VjSYQ7SSQ6vDYjL/k3r3+01S2VZr7SXNBFHeNCihTfqCUxjrj7oXGRSn97BCJkCAFV5O uod1ud7elz8egtL/w+1PDM9TutQ/7TxakN1Wc+WYDeq/Zjw20lYuWHjSAC3pQnCoouV3 ECSEE6qExBN6Uvdn1hVjUOLu+Pi0T16Xq5SdgAzClMASAQ4MkF9QzBt8sdnvebb1J9D4 lsrQ== X-Gm-Message-State: AOJu0YwOn5WLiwOJa+b5lNlDTiQDsKay8ZRZyOnU3EMXlXfIyDbrpj3q FcOsEGOw9AQg1144NeGH1Ceqp4nmt/JZF6VaQWsy1RBDUs3o299S2+fSQNwpPqjOhsyWXNp9JEJ W X-Google-Smtp-Source: AGHT+IGa1QeuKhJn1OTQS8D5RqmLbQdhHwd9iryqIa1Axr0gkEZ13NS1hF94rtZKdOI8Mh4fuYOzqQ== X-Received: by 2002:a05:6a21:3944:b0:1d3:e4e:ff55 with SMTP id adf61e73a8af0-1d8c95770e5mr4099326637.7.1728745524214; Sat, 12 Oct 2024 08:05:24 -0700 (PDT) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e4640772csm2225851b3a.63.2024.10.12.08.05.22 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 12 Oct 2024 08:05:23 -0700 (PDT) Message-ID: Date: Sat, 12 Oct 2024 09:05:20 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US From: Jeff Law Subject: [to-be-committed][RISC-V] Avoid unnecessary extensions when value is already extended To: "gcc-patches@gcc.gnu.org" X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 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 is a minor patch from Jivan from roughly a year ago. The basic idea here is similar to what we do when extending values for the sake of comparisons. Specifically if the value is already known to be properly extended, then an extension is just a copy. The original idea was to use a similar patch, but which aborted to identify cases where these unnecessary promotions where emitted. All that showed up when doing a testsuite run with that abort was the promotions created by the arithmetic with overflow patterns such as addv. Things like addv aren't *that* common so this never got high on my todo list, even after a minor issue in this space was raised in bugzilla. But with stage1 closing soon and no good reason not to go forward, I'm submitting this into the pre-commit tester now. My tester has been using it since roughly Feb :-) Plan would be to commit after the pre-commit tester renders its verdict. Jeff * config/riscv/riscv.md (zero_extendsidi2): If RHS is already zero extended, then this is just a copy. (extendsidi2): Similarly, but for sign extension. diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index 89095afeea5..ec00ce1c463 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -1773,7 +1773,15 @@ (define_insn "truncdfhf2" (define_expand "zero_extendsidi2" [(set (match_operand:DI 0 "register_operand") (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))] - "TARGET_64BIT") + "TARGET_64BIT" +{ + if (SUBREG_P (operands[1]) && SUBREG_PROMOTED_VAR_P (operands[1]) + && SUBREG_PROMOTED_UNSIGNED_P (operands[1])) + { + emit_insn (gen_movdi (operands[0], SUBREG_REG (operands[1]))); + DONE; + } +}) (define_insn_and_split "*zero_extendsidi2_internal" [(set (match_operand:DI 0 "register_operand" "=r,r") @@ -1854,7 +1862,15 @@ (define_expand "extendsidi2" [(set (match_operand:DI 0 "register_operand" "=r,r") (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" " r,m")))] - "TARGET_64BIT") + "TARGET_64BIT" +{ + if (SUBREG_P (operands[1]) && SUBREG_PROMOTED_VAR_P (operands[1]) + && SUBREG_PROMOTED_SIGNED_P (operands[1])) + { + emit_insn (gen_movdi (operands[0], SUBREG_REG (operands[1]))); + DONE; + } +}) (define_insn "*extendsidi2_internal" [(set (match_operand:DI 0 "register_operand" "=r,r")