From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id E26573858D32 for ; Mon, 26 Sep 2022 10:35:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E26573858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id BB1481F899; Mon, 26 Sep 2022 10:35:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664188519; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1HKYGFnIfekwVI2U/lpcGzmwYMG6H1Wx+/YWY1+HQsI=; b=i65GgGOAeNVTeoUKIf/MuH9sXfhXetzHabr+SwYOUoUgKxA1ncMisLgy1yU4xVscfvIXQ8 5S5UzZVasPy4v5XtO7fnzUIqqUNYDkHASOqJWm+U/IbrJWHbXOzN6Whf7+yty9FF3dh3Iw BP4203uEETvg3Q65J5/6ms4r6OOsqSQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664188519; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1HKYGFnIfekwVI2U/lpcGzmwYMG6H1Wx+/YWY1+HQsI=; b=WZtVYDdEmVRo/lu9SuaGSPafEM/Ysjz09vfdlN1ENjXgStBKlRImaxfx+DQAMNzPEoEXep Y3d48IBw4R+HuzAg== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id B32902C14F; Mon, 26 Sep 2022 10:35:19 +0000 (UTC) Date: Mon, 26 Sep 2022 10:35:19 +0000 (UTC) From: Richard Biener To: Tamar Christina cc: gcc-patches@gcc.gnu.org, nd@arm.com, jeffreyalaw@gmail.com, richard.sandiford@arm.com Subject: Re: [PATCH 1/2]middle-end: RFC: On expansion of conditional branches, give hint if argument is a truth type to backend In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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 List-Id: On Fri, 23 Sep 2022, Tamar Christina wrote: > Hi All, > > This is an RFC to figure out how to deal with targets that don't have native > comparisons against QImode values. > > Booleans, at least in C99 and higher are 0-1 valued. This means that we only > really need to test a single bit. However in RTL we no longer have this > information available and just have an SImode value (due to the promotion of > QImode to SImode). > > This RFC fixes it by emitting an explicit & 1 during the expansion of the > conditional branch. > > However it's unlikely that we want to do this unconditionally. Most targets > I've tested seem to have harmless code changes, like x86 changes from testb to > andl, $1. > > So I have two questions: > > 1. Should I limit this behind a target macro? Or should I just leave it for all > targets and deal with the fallout. > 2. How can I tell whether the C99 0-1 values bools are being used or the older > 0, non-0 variant? > > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. > However there are some benign codegen changes on x86, testb changed to andl $1. > > This pattern occurs more than 120,000 times in SPECCPU 2017 and so is quite common. How does this help a target? Why does RTL nonzerop bits not recover this information and the desired optimization done later during combine for example? Why's a SImode compare not OK if there's no QImode compare? We have undocumented addcc, negcc, etc. patterns, should we have a andcc pattern for this indicating support for andcc + jump as opposed to cmpcc + jump? So - what's the target and what's a testcase? Thanks, Richard. > Thanks, > Tamar > > gcc/ChangeLog: > > * tree.h (tree_zero_one_valued_p): New. > * dojump.cc (do_jump): Add & 1 if truth type. > > --- inline copy of patch -- > diff --git a/gcc/dojump.cc b/gcc/dojump.cc > index 2af0cd1aca3b6af13d5d8799094ee93f18022296..8eaf1be49cd12298e61c6946ae79ca9de6197864 100644 > --- a/gcc/dojump.cc > +++ b/gcc/dojump.cc > @@ -605,7 +605,17 @@ do_jump (tree exp, rtx_code_label *if_false_label, > /* Fall through and generate the normal code. */ > default: > normal: > - temp = expand_normal (exp); > + tree cmp = exp; > + /* If the expression is a truth type then explicitly generate an & 1 > + to indicate to the target that it's a zero-one values type. This > + allows the target to further optimize the comparison should it > + choose to. */ > + if (tree_zero_one_valued_p (exp)) > + { > + type = TREE_TYPE (exp); > + cmp = build2 (BIT_AND_EXPR, type, exp, build_int_cstu (type, 1)); > + } > + temp = expand_normal (cmp); > do_pending_stack_adjust (); > /* The RTL optimizers prefer comparisons against pseudos. */ > if (GET_CODE (temp) == SUBREG) > diff --git a/gcc/tree.h b/gcc/tree.h > index 8f8a9660c9e0605eb516de194640b8c1b531b798..be3d2dee82f692e81082cf21c878c10f9fe9e1f1 100644 > --- a/gcc/tree.h > +++ b/gcc/tree.h > @@ -4690,6 +4690,7 @@ extern tree signed_or_unsigned_type_for (int, tree); > extern tree signed_type_for (tree); > extern tree unsigned_type_for (tree); > extern bool is_truth_type_for (tree, tree); > +extern bool tree_zero_one_valued_p (tree); > extern tree truth_type_for (tree); > extern tree build_pointer_type_for_mode (tree, machine_mode, bool); > extern tree build_pointer_type (tree); > > > > > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; HRB 36809 (AG Nuernberg)