From patchwork Wed May 8 20:07:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1933178 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=M1DEr9ov; 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 4VZR5P2gRcz20fc for ; Thu, 9 May 2024 06:07:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5B3833858C50 for ; Wed, 8 May 2024 20:07:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id B39E43858C35 for ; Wed, 8 May 2024 20:07:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B39E43858C35 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 B39E43858C35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::32a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715198836; cv=none; b=Rfuhwu8TPw6kz18iBqYcsn+9pLjzE8dniimTfA+pJeUrXLuhi+EnoeVrsbOh1z2QfijlJ+bVPeXu1sPv9CKrxCDPcZlHGu4dm3ygaa9V/GgMk3Z5VM0V3UqfzIkLgzGtdR3nka7mQddi4LqjCvgMFq9hVekxe6HNr96UEaBcRgs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715198836; c=relaxed/simple; bh=HwIIyfqzjD+W2Y12qPoo0mZsW0nt1zDd2hGvrmVTFXs=; h=DKIM-Signature:Message-ID:Date:MIME-Version:From:Subject:To; b=lWBlqfY5DutWT5TseaqDQ4/6i8oqCHOM7/Q1g/I3VmyC3yQfLqsligPW+ascteLwDRcVS91GVEeG7yzZ3/gi2S7UClyC0rSXN7GWX2744uuvRZTLnZVmVrXCx8tQ4vE5hgWUl4jO51UCb0w8Jyu+r1DW+OdTJYaN53rS2zRwHPE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-6f0794fdb95so65735a34.2 for ; Wed, 08 May 2024 13:07:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1715198833; x=1715803633; darn=gcc.gnu.org; h=content-language:to:subject:from:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=mHZe30gvkASYFHk22NJKDXO7biGcOT2Oyk9w+Z9kmEw=; b=M1DEr9ovo6WQeY1WJ/J5nQUh9KVqkmIcpPpj3gclZoeQJhs9kgfPfIyaveU0B+U4ue 84HwYsDWNU7INwlNesWmhmoZWPlSZZef2hYce1GEnxtFHJ0RUVw0N/2b3Y/aJhtUj76g 1RSjNCzQdy1ees+lFfWF0npV1JPiJ1j7beJrjI+a10Psnrf1wC7WDkBTi4XMNbaCTmxL cVQAvl3jSrBhwnbN44SSZwa1NsaYY1yPDzwBzjyiTJ3vtpnBVRIpgzX8mVTvz73edgVp 56h9VxfZls0hJ1X4U5ZYmuTcTL3ADNCkt1fXm/cuofQ+8B92vbfetN98MVjhH+Br3+Pb HbOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715198833; x=1715803633; h=content-language:to:subject:from:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mHZe30gvkASYFHk22NJKDXO7biGcOT2Oyk9w+Z9kmEw=; b=FS8sogdsixwPk+RcFYVf46w6Lr5XjbpPsb9RGLHWQIs4w+NDP/wBdzjVyDIkZyJGKG bQv7UgfIAmyZKQTGYwv1+lCJjEN5kOsT5h0QNMSXIGwJKRES7wcY3UcM09IDK8lupYzk l9udzkjhSSx058IQNQGD0gLCZk6MFeYPum7UEAIyKmrIbk50UBaii/2U8RR+pI7+9Qix mwGvmWmgfkMLjMJoGrLOSmpTV+raWdQHIsemQcZu1gPf5VHQkM05U+kn9G4vmeV466Yz gEo4c6XW5Sr+hp1FP2AH8EvLai0WxrwK/IhoDitLvP31XXFsOxNunrCvZQtEEix2ACNP L+KA== X-Gm-Message-State: AOJu0Yw/BWO3/JzTOgZWJpuoq9Bl864WzJWvyxIhBkGNVi87+cm/ir0m hX9tL8K+9QiVXe2IjdTQ06eUgJB2YIrLkaRaf/opRIYwUGDxVF0CH/++AWSm2HhteVZqT/PpGqm 3 X-Google-Smtp-Source: AGHT+IHWsLcgugqOevNOKdjvkg8wfRalNHXvQaGmbpn4iO6KrzXiy+QFoNBOyZF9Sz7Vm1jiuBItqw== X-Received: by 2002:a05:6830:39d8:b0:6f0:4d28:442f with SMTP id 46e09a7af769-6f0b795465bmr3455028a34.18.1715198832930; Wed, 08 May 2024 13:07:12 -0700 (PDT) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id ek7-20020a056830710700b006eb80dd6c97sm3025929otb.68.2024.05.08.13.07.11 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 May 2024 13:07:12 -0700 (PDT) Message-ID: Date: Wed, 8 May 2024 14:07:11 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta From: Jeff Law Subject: [committed] [RISC-V] Provide splitting guidance to combine to faciliate shNadd.uw generation To: "gcc-patches@gcc.gnu.org" Content-Language: en-US X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 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 fixes a minor code quality issue I found while comparing GCC and LLVM. Essentially we want to do a bit of re-association to generate shNadd.uw instructions. Combine does the right thing and finds all the necessary instructions, reassociates the operands, combines constants, etc. Where is fails is finding a good split point. The backend can trivially provide guidance on how to split via a define_split pattern. This has survived both Ventana's internal CI system (rv64gcb) as well as my own (rv64gc, rv32gcv). I'll wait for the external CI system to give the all-clear before pushing. jeff diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md index ad3ad758959..d76a72d30e0 100644 --- a/gcc/config/riscv/bitmanip.md +++ b/gcc/config/riscv/bitmanip.md @@ -184,6 +184,23 @@ (define_insn "*slliuw" [(set_attr "type" "bitmanip") (set_attr "mode" "DI")]) +;; Combine will reassociate the operands in the most useful way here. We +;; just have to give it guidance on where to split the result to facilitate +;; shNadd.uw generation. +(define_split + [(set (match_operand:DI 0 "register_operand") + (plus:DI (plus:DI (and:DI (ashift:DI (match_operand:DI 1 "register_operand") + (match_operand:QI 2 "imm123_operand")) + (match_operand 3 "consecutive_bits32_operand")) + (match_operand:DI 4 "register_operand")) + (match_operand 5 "immediate_operand")))] + "TARGET_64BIT && TARGET_ZBA" + [(set (match_dup 0) + (plus:DI (and:DI (ashift:DI (match_dup 1) (match_dup 2)) + (match_dup 3)) + (match_dup 4))) + (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 5)))]) + ;; ZBB extension. (define_expand "clzdi2" diff --git a/gcc/testsuite/gcc.target/riscv/zba-shadduw.c b/gcc/testsuite/gcc.target/riscv/zba-shadduw.c new file mode 100644 index 00000000000..5b77447e681 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zba-shadduw.c @@ -0,0 +1,35 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=rv64gc_zba -mabi=lp64" } */ + +typedef struct simple_bitmap_def +{ + unsigned char *popcount; + unsigned int n_bits; + unsigned int size; + unsigned long elms[1]; +} *sbitmap; +typedef const struct simple_bitmap_def *const_sbitmap; + +typedef unsigned long *sbitmap_ptr; +typedef const unsigned long *const_sbitmap_ptr; +static unsigned long sbitmap_elt_popcount (unsigned long); + +void +sbitmap_a_or_b (sbitmap dst, const_sbitmap a, const_sbitmap b) +{ + unsigned int i, n = dst->size; + sbitmap_ptr dstp = dst->elms; + const_sbitmap_ptr ap = a->elms; + const_sbitmap_ptr bp = b->elms; + unsigned char has_popcount = dst->popcount != ((void *) 0); + + for (i = 0; i < n; i++) + { + const unsigned long tmp = *ap++ | *bp++; + *dstp++ = tmp; + } +} + + +/* { dg-final { scan-assembler "sh3add.uw" } } */ +/* { dg-final { scan-assembler-not {\mslli.uw} } } */