From patchwork Thu Nov 16 04:09:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "juzhe.zhong@rivai.ai" X-Patchwork-Id: 165690 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2977640vqg; Wed, 15 Nov 2023 20:09:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXmz5Y2+euzcEO4NuBSskLadDTa1aDrFPjTAdoZkWVCaTZZK58XnQUyuRaIMuI0YHJqHXD X-Received: by 2002:a0c:c34b:0:b0:66d:627e:24c0 with SMTP id j11-20020a0cc34b000000b0066d627e24c0mr7340277qvi.38.1700107787261; Wed, 15 Nov 2023 20:09:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700107787; cv=pass; d=google.com; s=arc-20160816; b=BFmVtUhsrzClkJIxdAcCBTvJw0JmYQ6Rg9p4rUsPVk3ynH8ltYrZu9R/+rXJGbUcqd X7Wjj6nw8R9zXdrGWVoYXBgBfl/1SmxIthIE9GXQQuetcnE8VCzBE66inBRKdn7hZD1t yPftFSOs5+GjsIQc3AIV2uBnviBccxaxn+alCujMXc0qj9hjJm1PHK2LDDiuOveSu2iY sJ2X/YKJBSYPsNDb0lZyKt9X45t7yyimaaLylzYNbF95InbnrwDFdlYwJAtTaSvd2O2e x5ZJMoosbsuFVWpRtLhA4YsXjwhfAW108VylOH+Hp5KiksyUxDgiCoOKxijM3oDSHV+K ZQ6Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:feedback-id :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:arc-filter:dmarc-filter:delivered-to; bh=3xAlvZY8gmBbVqyrwQLbC8mVTzkSty+Iry6ixEko8eE=; fh=Hxj0cw/2jAkyitv6gv3v4BQlApRvZwleU4172JThTNQ=; b=ifI5QY1tVj4jPFEiYdVElRqdGy7ihIdjP7eusQ+IwY5NGXLHqxHe8EOJ7x/3gUNwhX 1MfzhZFAcP4WUmMvNkQgzcCX2mn29UyVfeDovWDWeTddi+2Qfae9eNnN/69RjQwYIO0m CBXOWIv5W80SwF40ei6szHsSDnXTi0C8ZouvgfbRr0Pz6k+oUAfqo0s9RHDpXyAXnc6P rnmFwXbf9SJj/e5DUMUScXVSjD02kFHWukGBvUPLTH+h13lDP2KndrCSTGP5xIbeVFnK 2jP4+vzAHOs8REgusJ2+/LxGyUL9YVLrSLt/ihnHa3tBMh+WD8iY1UcFJUAqdV2EXqkx WK4A== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qb7-20020ad44707000000b0066d1a15d84csi9992346qvb.414.2023.11.15.20.09.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 20:09:47 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B8443858CD1 for ; Thu, 16 Nov 2023 04:09:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbguseast1.qq.com (smtpbguseast1.qq.com [54.204.34.129]) by sourceware.org (Postfix) with ESMTPS id 829213858D20 for ; Thu, 16 Nov 2023 04:09:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 829213858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 829213858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=54.204.34.129 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700107762; cv=none; b=sl+BBfeBoMxgq1A6ODYD/NGKPB2FiHvczKHjLg3BfyLz2XzBlNXk04qjjvrhXPdEeerYr6dDRMuKi5pfbcrtyVRiMnxOCA/j4usKAahGdvG4EKZwq7cd0W8arC2oa3zJI8dnyn2MBXcc2Y+N5MCYpOQA0rXk5IGkvnCr35Xsfag= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700107762; c=relaxed/simple; bh=Gt6rxvQNrRSUckbMDp5uWDDHq1D7Jf/yoZnxB2L4NkA=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=DwKrxwMnpX2af2TAav5ih+DrLe2T/bm1Agg+cBNUwhF2ql2ilbgygKqKm8bASkL2FDSbFvcG3B0XqvLaZTt1HFvIjXgCrCANVnyeAvgdFBsUdKGwD0W5gpiw95XMPoUNCXzIDvymd8XaeLuAue0GJhnEx+pWCt2v3Tc9tc7snCg= ARC-Authentication-Results: i=1; server2.sourceware.org X-QQ-mid: bizesmtp85t1700107749t22izvml Received: from rios-cad121.hadoop.rioslab.org ( [58.60.1.9]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 16 Nov 2023 12:09:08 +0800 (CST) X-QQ-SSF: 01400000000000G0V000000A0000000 X-QQ-FEAT: XBN7tc9DADJyn9iWVB/EycgCH8zGq5jkRHNOf4KvptgPwBKfMTFXi5KVow5p6 MLOJajvHVbozRiB0+w1ycZOthDv5kXN8IC/4HjHBiHmPmLrsgdfTk93PbhIgWVUCQeyHCU6 icqRKRB/Smuwa8//rMsoYLVWlyzg7kQ8XPpXwg48SdB58IQ6FOLNZ/qVvY2sB3/SFzDtglw P4l1bPExiTeBr52o5XFDdxgGMXjT5+pvWLd9nWc0p8/9MRf+Vl6PdbtvwzWaBxcKwGTLIkE 0YnFZ5KivWMkxmiEB8GHKFT2ZDUce5bqTxeXKIsMbaUa+33Xhh8N9nqQSMv/oBkDHxepFIn kOBmtxjObRTeVr1/lFztkDkSTiUFpeptJWBdYcs7qtCI58FcTe4ZmmRsVbYutrthjvPNeL3 7IgLVv/sscQ= X-QQ-GoodBg: 2 X-BIZMAIL-ID: 9859263868467854946 From: Juzhe-Zhong To: gcc-patches@gcc.gnu.org Cc: richard.sandiford@arm.com, rguenther@suse.de, Juzhe-Zhong Subject: [PATCH] VECT: Clear LOOP_VINFO_USING_SELECT_VL_P when loop is not partial vectorized Date: Thu, 16 Nov 2023 12:09:07 +0800 Message-Id: <20231116040907.1647406-1-juzhe.zhong@rivai.ai> X-Mailer: git-send-email 2.36.3 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz7a-one-0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782692222818862126 X-GMAIL-MSGID: 1782692222818862126 This patch fixes ICE: https://godbolt.org/z/z8T6o6qov : In function 'b': :2:6: error: missing definition 2 | void b() { | ^ for SSA_NAME: loop_len_8 in statement: _1 = -loop_len_8; during GIMPLE pass: vect :2:6: internal compiler error: verify_ssa failed 0x7f1b56331082 __libc_start_main ???:0 Please submit a full bug report, with preprocessed source (by using -freport-bug). Please include the complete backtrace with any bug report. See for instructions. Compiler returned: 1 The root cause is we generate such IR in vectorization: _1 = -loop_len_8; vect_cst__11 = {_1, _1}; _18 = vect_vec_iv_.6_14 + vect_cst__11; loop_len_8 is uninitialized value. The IR _18 = vect_vec_iv_.6_14 + vect_cst__11; is generated because of we are adding induction variable with the result of SELECT_VL instead of VF. The code is: else if (LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo)) { /* When we're using loop_len produced by SELEC_VL, the non-final iterations are not always processing VF elements. So vectorize induction variable instead of _21 = vect_vec_iv_.6_22 + { VF, ... }; We should generate: _35 = .SELECT_VL (ivtmp_33, VF); vect_cst__22 = [vec_duplicate_expr] _35; _21 = vect_vec_iv_.6_22 + vect_cst__22; */ gcc_assert (!slp_node); gimple_seq seq = NULL; vec_loop_lens *lens = &LOOP_VINFO_LENS (loop_vinfo); tree len = vect_get_loop_len (loop_vinfo, NULL, lens, 1, vectype, 0, 0); expr = force_gimple_operand (fold_convert (TREE_TYPE (step_expr), unshare_expr (len)), &seq, true, NULL_TREE); new_name = gimple_build (&seq, MULT_EXPR, TREE_TYPE (step_expr), expr, step_expr); gsi_insert_seq_before (&si, seq, GSI_SAME_STMT); step_iv_si = &si; } LOOP_VINFO_USING_SELECT_VL_P is set before loop vectorization analysis so we don't know whether it is partial vectorization or not but the induction variable depends on SELECT_VL_P is true. So update SELECT_VL_P as false when it is not partial vectorization. PR middle-end/112554 gcc/ChangeLog: * tree-vect-loop.cc (vect_determine_partial_vectors_and_peeling): Clear SELECT_VL_P for non-partial vectorization. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/pr112554.c: New test. --- .../gcc.target/riscv/rvv/autovec/pr112554.c | 12 ++++++++++++ gcc/tree-vect-loop.cc | 13 +++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112554.c diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112554.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112554.c new file mode 100644 index 00000000000..4afa7c2b15c --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112554.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64d -O3 --param=riscv-autovec-preference=fixed-vlmax" } */ + +int a; +void b() { + unsigned long c = 18446744073709551612UL; +d: + --c; + a ^= c; + if (c) + goto d; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index fb8d999ee6b..3f59139cb01 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -2657,6 +2657,19 @@ vect_determine_partial_vectors_and_peeling (loop_vec_info loop_vinfo) = (!LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo) && need_peeling_or_partial_vectors_p); + /* We set LOOP_VINFO_USING_SELECT_VL_P as true before loop vectorization + analysis that we don't know whether the loop is vectorized by partial + vectors (More details see tree-vect-loop-manip.cc). + + However, SELECT_VL vectorizaton style should only applied on partial + vectorization since SELECT_VL is the GIMPLE IR that calculates the + number of elements to be process for each iteration. + + After loop vectorization analysis, Clear LOOP_VINFO_USING_SELECT_VL_P + if it is not partial vectorized loop. */ + if (!LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo)) + LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo) = false; + return opt_result::success (); }