From patchwork Thu Jul 11 12:12:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 1959295 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=PtAY6dve; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4WKYYG3SQ1z1xqj for ; Thu, 11 Jul 2024 22:13:54 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A046938708A5 for ; Thu, 11 Jul 2024 12:13:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A046938708A5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1720700032; bh=oVsqaXjZzMAbcI82Iot5cqKa62PsjCE6vmBw+KURFMw=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=PtAY6dvetfcE194cA06mgBr2OpusQTFQ6XtMJWu5G9xp3a3GWI7nFmcWTAKxiM8ui /CoCGSTuVwB51BMFr6sXhVx0juzhzrccmopf2N4stUEvifKAnIP7Us4IHhf/W45Rjv 9RDOZvXkeV4N77QjcRhtrDuyr3I2FVeMWb0p5aks= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by sourceware.org (Postfix) with ESMTPS id C4EA738708C0 for ; Thu, 11 Jul 2024 12:12:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C4EA738708C0 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C4EA738708C0 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720699948; cv=none; b=Fdhc7xNWUwQBxRbSxe8KRn5wJf+asUuBX4QGdIh7cSztr2lX+9eJwP0m7UhuOW1UNejQGXMvoLZsBR3uoJkGFyWgSdmGM6WgjcZZxqzyM9BixyrAbKrZ7rrlCYRRpU8FM3onqyhzKeK4hmWOGFJkEpK2webgptOFeOHn4fZtY3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720699948; c=relaxed/simple; bh=ErUU1sPE//PNlNZBL738yvt3PUcfd16Xk33COhA9ud4=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=uYufl0+DoAIbt05jZjKH/Y1taPBAa3LGYKEXgTygKf1R6CtBnDwXoAKATbQ0mJd9lmoq9JzEzngSFjNMHcnVh8KwvUljW+pI4UbI23VpEUj47d5v0izMPVxzm3Z7dw5CNGw4swKGVbCqZvrWEto0GZyPkDBdZqOjxlTJUsJf6RA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1fb64d627b0so4868635ad.0 for ; Thu, 11 Jul 2024 05:12:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720699945; x=1721304745; 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=oVsqaXjZzMAbcI82Iot5cqKa62PsjCE6vmBw+KURFMw=; b=AbYgoJa1UjQg3/90GpBL6136yvhfN9PSECSMaxnwbxcB2MbLG0VYW5Wb7kx/cn+gj4 8GfSPqPegxBM1J9J6IACAmQbCO1JPJhCC5SnwwPrh3GDelFdySmvGbqSsRacKgrytbi+ 1sP1De0lNPrE3eadHX9tUmcJ0QvSo8SXYa5FJ+wRHhAytaPdf0IamAdXsEit3SkmgQHw 0ctaM/hJB89PI5bsgH2l5YaO7/zfCu54rhCrxk9iZzIh2DNxAY6sFa6FI+Yo83XiP/yH z2pSG/dftBY65y5daO7IQxPKVRytFcR5XesDlFO9d+jNwX3I7KA+szMfaO6k8Xdteq46 6yxQ== X-Gm-Message-State: AOJu0YyN6w2aNU0Yqz6IMx41BlDH8rzvZQXzRaLmctoCvPrEpR/StTHH XmDySwfHO64I/e8g53+1syodhj02oAe79vqqf+zOiUHQxzfgTa2R/6siO1jI X-Google-Smtp-Source: AGHT+IGd8Ww5LY2N8B+VM1apDt/RDUp7mPUn0XdOwr6+PCsKC+rDpC3KpSrN9rv2Yt44GsuO4+cfcg== X-Received: by 2002:a17:903:190:b0:1fb:3b2f:73f8 with SMTP id d9443c01a7336-1fbb6edea3bmr71432635ad.66.1720699945501; Thu, 11 Jul 2024 05:12:25 -0700 (PDT) Received: from localhost.localdomain ([194.169.55.179]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6abfc56sm49010545ad.196.2024.07.11.05.12.24 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 11 Jul 2024 05:12:25 -0700 (PDT) From: YunQiang Su To: gcc-patches@gcc.gnu.org Cc: YunQiang Su Subject: [PATCH 1/2] Add allow_uninitialized to tree_base.u.bits for VAR_DECL Date: Thu, 11 Jul 2024 20:12:07 +0800 Message-Id: <20240711121208.45328-1-syq@gcc.gnu.org> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 From: YunQiang Su Uninitialized internal temp variable may be useful in some case, such as for COND_LEN_MUL etc on RISC-V with V extension: If an const or pre-exists VAR is used, we have to use "undisturbed" policy; if an uninitialized VAR is used, we can use "agnostic". With "agnostic", the microarchitectures can omit copying part of the VAR. gcc * tree-core.h(tree_base): Add u.bits.allow_uninitialized. * tree.h: Add new macro TREE_ALLOW_UNINITIALIZED. * tree-ssa-uninit.cc(warn_uninit): Don't warn if VAR is marked as allow_uninitialized. --- gcc/tree-core.h | 5 ++++- gcc/tree-ssa-uninit.cc | 4 ++++ gcc/tree.h | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/gcc/tree-core.h b/gcc/tree-core.h index 27c569c7702..984201199f6 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -1101,7 +1101,10 @@ struct GTY(()) tree_base { unsigned nameless_flag : 1; unsigned atomic_flag : 1; unsigned unavailable_flag : 1; - unsigned spare0 : 2; + /* Don't warn if uninitialized. RISC-V V has tail agnostic/undisturbed + policy, which may be get benifits if we use an uninitialized var. */ + unsigned allow_uninitialized : 1; + unsigned spare0 : 1; unsigned spare1 : 8; diff --git a/gcc/tree-ssa-uninit.cc b/gcc/tree-ssa-uninit.cc index 726684e472a..12861e1dbc9 100644 --- a/gcc/tree-ssa-uninit.cc +++ b/gcc/tree-ssa-uninit.cc @@ -142,6 +142,10 @@ warn_uninit (opt_code opt, tree t, tree var, gimple *context, if (!has_undefined_value_p (t)) return; + /* VAR may mark itself as allow_uninitialized. */ + if (TREE_ALLOW_UNINITIALIZED (var)) + return; + /* Ignore COMPLEX_EXPR as initializing only a part of a complex turns in a COMPLEX_EXPR with the not initialized part being set to its previous (undefined) value. */ diff --git a/gcc/tree.h b/gcc/tree.h index 28e8e71b036..381780fde2e 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -3311,6 +3311,10 @@ extern void decl_fini_priority_insert (tree, priority_type); #define VAR_DECL_IS_VIRTUAL_OPERAND(NODE) \ (VAR_DECL_CHECK (NODE)->base.u.bits.saturating_flag) +/* In a VAR_DECL, nonzero if NODE is allowed to be uninitialized. */ +#define TREE_ALLOW_UNINITIALIZED(NODE) \ + (VAR_DECL_CHECK (NODE)->base.u.bits.allow_uninitialized) + /* In a VAR_DECL, nonzero if this is a non-local frame structure. */ #define DECL_NONLOCAL_FRAME(NODE) \ (VAR_DECL_CHECK (NODE)->base.default_def_flag) From patchwork Thu Jul 11 12:12:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 1959293 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=aqLr5Hvr; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4WKYXN3pDtz1xqj for ; Thu, 11 Jul 2024 22:13:08 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BB84F3870C26 for ; Thu, 11 Jul 2024 12:13:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB84F3870C26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1720699986; bh=OrD3Wpd5BKlAriXEUSal0wESn3DIqvf1knfE+nhhpqA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=aqLr5HvrrIxL04WHhSLD28TzTooWbdAfohT5OF5MPg2ifpa0GoipPMPOp02gAxNmM 7dMcfa3UjTB/3C/gu/06GH1062guWjyQ6IZDVYn7v0WxLk9zwsjO6CKNXtVEuF3UuP BLgsCyK5iGFlCROYbsROm7GWaN3sbPrcGTDOt25s= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by sourceware.org (Postfix) with ESMTPS id E3A2D38432FD for ; Thu, 11 Jul 2024 12:12:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E3A2D38432FD Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E3A2D38432FD Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.215.170 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720699955; cv=none; b=NdGzcaZ7oHblpuUQyHBIqgfv9poSLnHCPz8CwCMXRviIwE2j6pH2/OwW/0OcUu2iRQ8d1ZIafENmwbG3lPFHmCevLEbQrLBFRv+kGSbEq2dwrZT3Ooq7MyF6ZJ/6SPNf1HgWs1W87vXnIBPnL/9r+hKUt6Xz5S9VpKaGpxKC7e8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720699955; c=relaxed/simple; bh=Z09s1LIkC7QvGQ1Y4egt791aMVS7utw2vZcIdKUV9mU=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=LmIM3ElktN3jUrS2XcX+eL2yMkp1vygCCqVhHCgdVEg2A9I/u/BUOwGXOjNWFrZGVzKYMd5NdlyS5cvojsbM1rYmZ+1j/7rVvshykXgDCQOAJnOQPzldpjytM3dVuqr7jlIucWzAhI8QL4gc/xU77h7+YaNYBN8ojgAJHKVhLv8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-71871d5e087so524345a12.1 for ; Thu, 11 Jul 2024 05:12:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720699950; x=1721304750; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OrD3Wpd5BKlAriXEUSal0wESn3DIqvf1knfE+nhhpqA=; b=uXKheHiOWtEBQBROHtSJxNB0OUpGwLJuYXNvAmW2QcWnlIgVbYzpkRg0j/i4HCSZX2 Q64uSK5IlmC1byqgypeTlRHEP0rXXipoc+JFRlkNmMQnWcRGqIcdbtC6paqp/boTQrfr RlZK0fW2luCbIPtRZK+8tDyw84tvQ6tbThkeM6DYedsbeRJ+TloD+I2Fmod//9taFwxc K5zv8tL1gdfUSQLA+Hb5quJr6kAp2mwzvtelsNcqY5DTv5AMxGCpWd2/2xnlRKkXNUT+ gmEShaBYI2xQBUtvug8pChRs3lMdBoZaku2rgGgGFqpKb7WBM5Qfcx4p2Dk121tWRpyE s3+Q== X-Gm-Message-State: AOJu0YySnGdQlBzuEgGKfKhWW+pURibb5bV8r89khW4lOGOxFMfDPNmt Rdgz+l5IZ+NiZnma3Ogme168V4nbPQ+sEweAstZMEPSAgmTqHkwvskHvTmqC X-Google-Smtp-Source: AGHT+IG9tmDFjdEUe8qWyEU5qxOc+BjutRIT+DpjeUBdDa8lJzNEwh91rLZO2MoNu5mMhVXwCD5zPQ== X-Received: by 2002:a05:6a20:3948:b0:1c0:e4d6:9bec with SMTP id adf61e73a8af0-1c29820b7d0mr9763322637.7.1720699949634; Thu, 11 Jul 2024 05:12:29 -0700 (PDT) Received: from localhost.localdomain ([194.169.55.179]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6abfc56sm49010545ad.196.2024.07.11.05.12.28 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 11 Jul 2024 05:12:29 -0700 (PDT) From: YunQiang Su To: gcc-patches@gcc.gnu.org Cc: YunQiang Su Subject: [PATCH 2/2] RISC-V: Allow uninitialized preferred_else_value for RVV Date: Thu, 11 Jul 2024 20:12:08 +0800 Message-Id: <20240711121208.45328-2-syq@gcc.gnu.org> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240711121208.45328-1-syq@gcc.gnu.org> References: <20240711121208.45328-1-syq@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLACK 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 From: YunQiang Su PR target/115840. In riscv_preferred_else_value, we create an uninitialized tmp var for else value, instead of the 0 (as default_preferred_else_value) or the pre-exists VAR (as aarch64 does), so that we can use agnostic policy. The problem is that `warn_uninit` will emit a warning: ({anonymous})’ may be used uninitialized Let's mark this tmp var as "allow_uninitialized". This problem is found when I try to build glibc with V extension. gcc PR target/115840. * config/riscv/riscv.cc(riscv_preferred_else_value): Mark tmp_var as allow_unitialized. gcc/testsuite * gcc.dg/vect/pr115840.c: New testcase. --- gcc/config/riscv/riscv.cc | 6 +++++- gcc/testsuite/gcc.dg/vect/pr115840.c | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/vect/pr115840.c diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 61fa74e9322..08159d7cbbc 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -11431,7 +11431,11 @@ riscv_preferred_else_value (unsigned ifn, tree vectype, unsigned int nops, tree *ops) { if (riscv_v_ext_mode_p (TYPE_MODE (vectype))) - return get_or_create_ssa_default_def (cfun, create_tmp_var (vectype)); + { + tree tmp_var = create_tmp_var (vectype); + TREE_ALLOW_UNINITIALIZED (tmp_var) = 1; + return get_or_create_ssa_default_def (cfun, tmp_var); + } return default_preferred_else_value (ifn, vectype, nops, ops); } diff --git a/gcc/testsuite/gcc.dg/vect/pr115840.c b/gcc/testsuite/gcc.dg/vect/pr115840.c new file mode 100644 index 00000000000..09dc9e4eb7c --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr115840.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-Wall -Werror" } */ + +double loads[16]; + +void +foo (double loadavg[], int count) +{ + for (int i = 0; i < count; i++) + loadavg[i] = loads[i] / 1.5; +}