From patchwork Wed Oct 25 05:01:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 1854712 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=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=SiXNwCv6; 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 4SFcHN615fz23jn for ; Wed, 25 Oct 2023 16:02:22 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4A1AD3858020 for ; Wed, 25 Oct 2023 05:02:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oo1-xc34.google.com (mail-oo1-xc34.google.com [IPv6:2607:f8b0:4864:20::c34]) by sourceware.org (Postfix) with ESMTPS id 5D4CC3858D28 for ; Wed, 25 Oct 2023 05:02:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5D4CC3858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5D4CC3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698210129; cv=none; b=xAepFHln4gRQDB42CPkAxx1pR1modtwNvjuAnpYa8dI7kcZ7yPDCyhasyxWpjAoED8Cx0s4obllLL9EPeXCOTlDio/yUkjjmhKo9hz13Lgkyx+Z0U8S3q7+c1IcBoMc8qziottTRvbjda+XhL9qijoB/wZ683Pr9AsLl+k2TNOU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698210129; c=relaxed/simple; bh=0jW1WXtANPS4NKDojGiOm5pGzlzfZTJN9N314zfKF78=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Dl6pkXim/JVi+alxlxxPEgNO/yAwjgqUDY7AMSRYDPcHSiK8y/hjBhQsqmxzLdB9kOhTWGQRrLqYpisGNdZa/z+jNcZhsd7B0o8RTaXWktT66hUVH8uSBH6Q9GK31AAHgZL4NUi5EAWXYnjdL1bFcrhSTnfe4ml81l+mc45M9uw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc34.google.com with SMTP id 006d021491bc7-581b6b93bd1so3026709eaf.1 for ; Tue, 24 Oct 2023 22:02:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1698210125; x=1698814925; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=6KCvFlq1WtgLx6UYFre/ofeA4PjEAi/fZxVy5CvgdNk=; b=SiXNwCv6veIa5p8R+oi8KD/+RBEh7WYUb8JOKVuGZp8YGxMBj6uSVgdLTqxgRLeDay RyQV6sqq6QTzOshKxsl7wZq17K/e4hlCUgBNZVc01DCLZf2mU05r93JKNusO4N1ju80a i9RSUEaIyxAkk0kVvVhoKJlnnt3d+Q2LcnaJ3bVg8tcjbogr1JjleVEaIxbuaBH2g4xS CWEFIzOwmdFd1plpg1URMf+bdpZLM6Va4llN0rFjB4Hen1sBiGiTTugZN7EBlkeqqSAl MQZMTrf8PIR/6U6ZtJVJMZOkNzQghbOadJEF4FP0pUEAIN0ff2FqKBcXBf8uJ6bx+T71 HYYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698210125; x=1698814925; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6KCvFlq1WtgLx6UYFre/ofeA4PjEAi/fZxVy5CvgdNk=; b=rRfsldYUlAHR3KJL5zBcWDXJcajtHfoTe3ltcpAbloOr4WGtBPVHwwFRO5sUi1hmSJ cSXGctuxDLz5cWZby3GIDyaIZsQAjq+J7SDXbR9s1KcTIpLbJWRiHXqTfrbZlcj5F5U2 6capnbqKU3ibNbewA6aVRPxa0s1xWRVyP2zfdAre2faJgNE3e10fRBzBwXsUHmT1FulO HUSCbI3fNWSU4WEPtQ9DQFjovMgt5ls0Mlx2FOfcBoXGMsDZ3yVST5UEU+acgqz+PlW9 +7UCityJ/LkrKJcQZPEq1YNsKd9xdFpTJobYkmyz4YbZFHvj/AjkjNGoaLRsdIeLsfQk rjFw== X-Gm-Message-State: AOJu0Yy9mSRWrdfoIlRvWazk+NyulQRYX4fWXHHVfz/AWKexzVIoTBYA QFOVfgutymy+1AHqgs/kCsdkbKMCQMMhfPPdaOWjIg== X-Google-Smtp-Source: AGHT+IFTpkZKy4Q5Z9WauPQUFSoIkpF1q0WH8DTOBljeuxmKPI+epnFu4YX7R+lfvInrdli45kAJPA== X-Received: by 2002:a05:6820:54e:b0:586:9048:1887 with SMTP id n14-20020a056820054e00b0058690481887mr1118544ooj.2.1698210125334; Tue, 24 Oct 2023 22:02:05 -0700 (PDT) Received: from vineet-framework.ba.rivosinc.com (c-98-210-197-24.hsd1.ca.comcast.net. [98.210.197.24]) by smtp.gmail.com with ESMTPSA id l9-20020a9d4c09000000b006ce2ec1d000sm2106784otf.59.2023.10.24.22.02.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 22:02:04 -0700 (PDT) From: Vineet Gupta To: gcc-patches@gcc.gnu.org Cc: gnu-toolchain@rivosinc.com, Jeff Law , Vineet Gupta Subject: [RFC] RISC-V: elide sign extend when expanding cmp_and_jump Date: Tue, 24 Oct 2023 22:01:55 -0700 Message-Id: <20231025050155.627837-1-vineetg@rivosinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, 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 RV64 comapre and branch instructions only support 64-bit operands. The backend unconditionally generates zero/sign extend at Expand time for compare and branch operands even if they are already as such e.g. function args which ABI guarantees to be sign-extended (at callsite). And subsequently REE fails to eliminate them as "missing defintion(s)" specially for function args since they show up as missing explicit definition. So elide the sign extensions at Expand time for a subreg promoted var with inner word sized value whcih doesn't need explicit sign extending (fairly good represntative of an incoming function arg). There are patches floating to enhance REE and/or new passes to elimiate extensions, but it is always better to not generate them if possible, given Expand is so early, the elimiated extend would help improve outcomes of later passes such as combine if they have fewer operations/combinations to deal with. The test used was existing gcc.c-torture/execute/20020506-1.c -O2 zbb It elimiates the SEXT.W and an additional branch before after ------- ------ test2: test2: sext.b a0,a0 blt a0,zero,.L15 bne a1,zero,.L17 bne a1,zero,.L17 This is marked RFC as I only ran a spot check with a directed test and want to use Patrick's pre-commit CI to do the A/B testing for me. gcc/ChangeLog: * config/riscv/riscv.cc (riscv_extend_comparands): Don't sign-extend operand if subreg promoted with inner word size. Signed-off-by: Vineet Gupta --- gcc/config/riscv/riscv.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index f2dcb0db6fbd..a8d12717e43d 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -3707,7 +3707,16 @@ riscv_extend_comparands (rtx_code code, rtx *op0, rtx *op1) } else { - *op0 = gen_rtx_SIGN_EXTEND (word_mode, *op0); + /* A subreg promoted SI of DI could be peeled to expose DI, eliding + an unnecessary sign extension. */ + if (GET_CODE (*op0) == SUBREG + && SUBREG_PROMOTED_VAR_P (*op0) + && GET_MODE_SIZE (GET_MODE (XEXP (*op0, 0))).to_constant () + == GET_MODE_SIZE (word_mode)) + *op0 = XEXP (*op0, 0); + else + *op0 = gen_rtx_SIGN_EXTEND (word_mode, *op0); + if (*op1 != const0_rtx) *op1 = gen_rtx_SIGN_EXTEND (word_mode, *op1); }