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)