From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 746873858418 for ; Tue, 12 Dec 2023 10:59:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 746873858418 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 746873858418 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702378796; cv=none; b=poC6omhTN4F5NvuWUGufC303Ab00IfHBCZaLFBr4FoEvjmmey/MNGMICjB0+TYsArwxONjjvOhllCEogYCWoAoJwOn2pd0/JN91YFzBX7YnOU5TGRUyHtIohjR1YNa4lGByu/JvNcjbElQ4GAEj6Q2RkRbzJJ/Qw8vb68hjegBU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702378796; c=relaxed/simple; bh=bWj9Ebxo2Au+aaOc+ifm0CLK2ksXJzjgPVSiIov0sgc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=mcRAWJVTKdjom9oc87MW/JOOithamu8rGHJBokexGFM/giDqpmeuhUQR+mIqO63KJAkvKcnlRneA/14r0fY4n4HeL3O1j2fuTOZHG0c/nA0k9X3Oqr83wo/0LDcUwmMKA4HFjV5BUB1NWjoV7xzvXtgc3O6eolJ7ZxFwKSOwolY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5509A143D; Tue, 12 Dec 2023 03:00:40 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1EE9F3F762; Tue, 12 Dec 2023 02:59:53 -0800 (PST) From: Richard Sandiford To: Richard Biener Mail-Followup-To: Richard Biener ,Tamar Christina , "gcc-patches\@gcc.gnu.org" , nd , "jlaw\@ventanamicro.com" , richard.sandiford@arm.com Cc: Tamar Christina , "gcc-patches\@gcc.gnu.org" , nd , "jlaw\@ventanamicro.com" Subject: Re: [PATCH 9/21]middle-end: implement vectorizable_early_exit for codegen of exit code References: <85570n66-1540-0r07-7q80-269p3o133585@fhfr.qr> <5r3p7378-q309-ooqo-7o76-q9r567ns1890@fhfr.qr> <3o102so4-34pp-3o01-o002-0q245oo10303@fhfr.qr> Date: Tue, 12 Dec 2023 10:59:51 +0000 In-Reply-To: <3o102so4-34pp-3o01-o002-0q245oo10303@fhfr.qr> (Richard Biener's message of "Tue, 12 Dec 2023 11:10:11 +0100 (CET)") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-15.8 required=5.0 tests=BAYES_00,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Richard Biener writes: > On Mon, 11 Dec 2023, Tamar Christina wrote: >> @@ -5553,6 +5554,83 @@ integer_type_for_mask (tree var, vec_info *vinfo) >> return build_nonstandard_integer_type (def_stmt_info->mask_precision, 1); >> } >> >> +/* Function vect_recog_gcond_pattern >> + >> + Try to find pattern like following: >> + >> + if (a op b) >> + >> + where operator 'op' is not != and convert it to an adjusted boolean pattern >> + >> + mask = a op b >> + if (mask != 0) >> + >> + and set the mask type on MASK. >> + >> + Input: >> + >> + * STMT_VINFO: The stmt at the end from which the pattern >> + search begins, i.e. cast of a bool to >> + an integer type. >> + >> + Output: >> + >> + * TYPE_OUT: The type of the output of this pattern. >> + >> + * Return value: A new stmt that will be used to replace the pattern. */ >> + >> +static gimple * >> +vect_recog_gcond_pattern (vec_info *vinfo, >> + stmt_vec_info stmt_vinfo, tree *type_out) >> +{ >> + gimple *last_stmt = STMT_VINFO_STMT (stmt_vinfo); >> + gcond* cond = NULL; >> + if (!(cond = dyn_cast (last_stmt))) >> + return NULL; >> + >> + auto lhs = gimple_cond_lhs (cond); >> + auto rhs = gimple_cond_rhs (cond); >> + auto code = gimple_cond_code (cond); >> + >> + tree scalar_type = TREE_TYPE (lhs); >> + if (VECTOR_TYPE_P (scalar_type)) >> + return NULL; >> + >> + if (code == NE_EXPR && zerop (rhs)) > > I think you need && VECT_SCALAR_BOOLEAN_TYPE_P (scalar_type) here, > an integer != 0 would not be an appropriate mask. I guess two > relevant testcases would have an early exit like > > if (here[i] != 0) > break; > > once with a 'bool here[]' and once with a 'int here[]'. > >> + return NULL; >> + >> + tree vecitype = get_vectype_for_scalar_type (vinfo, scalar_type); >> + if (vecitype == NULL_TREE) >> + return NULL; >> + >> + /* Build a scalar type for the boolean result that when vectorized matches the >> + vector type of the result in size and number of elements. */ >> + unsigned prec >> + = vector_element_size (tree_to_poly_uint64 (TYPE_SIZE (vecitype)), >> + TYPE_VECTOR_SUBPARTS (vecitype)); >> + >> + scalar_type >> + = build_nonstandard_integer_type (prec, TYPE_UNSIGNED (scalar_type)); >> + >> + vecitype = get_vectype_for_scalar_type (vinfo, scalar_type); >> + if (vecitype == NULL_TREE) >> + return NULL; >> + >> + tree vectype = truth_type_for (vecitype); > > That looks awfully complicated. I guess one complication is that > we compute mask_precision & friends before this pattern gets > recognized. See vect_determine_mask_precision and its handling > of tcc_comparison, see also integer_type_for_mask. For comparisons > properly handled during pattern recog the vector type is determined > in vect_get_vector_types_for_stmt via > > else if (vect_use_mask_type_p (stmt_info)) > { > unsigned int precision = stmt_info->mask_precision; > scalar_type = build_nonstandard_integer_type (precision, 1); > vectype = get_mask_type_for_scalar_type (vinfo, scalar_type, > group_size); > if (!vectype) > return opt_result::failure_at (stmt, "not vectorized: unsupported" > " data-type %T\n", scalar_type); > > Richard, do you have any advice here? I suppose vect_determine_precisions > needs to handle the gcond case with bool != 0 somehow and for the > extra mask producer we add here we have to emulate what it would have > done, right? How about handling gconds directly in vect_determine_mask_precision? In a sense it's not needed, since gconds are always roots, and so we could calculate their precision on the fly instead. But handling it in vect_determine_mask_precision feels like it should reduce the number of special cases. Thanks, Richard