From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15438 invoked by alias); 28 Oct 2015 15:22:03 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 15425 invoked by uid 89); 28 Oct 2015 15:22:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-yk0-f175.google.com Received: from mail-yk0-f175.google.com (HELO mail-yk0-f175.google.com) (209.85.160.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 28 Oct 2015 15:22:01 +0000 Received: by ykek133 with SMTP id k133so11237970yke.2 for ; Wed, 28 Oct 2015 08:22:00 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.13.202.141 with SMTP id m135mr20269562ywd.305.1446045719905; Wed, 28 Oct 2015 08:21:59 -0700 (PDT) Received: by 10.37.117.136 with HTTP; Wed, 28 Oct 2015 08:21:59 -0700 (PDT) In-Reply-To: <20151028131339.GC20857@msticlxl57.ims.intel.com> References: <20151028131339.GC20857@msticlxl57.ims.intel.com> Date: Wed, 28 Oct 2015 15:24:00 -0000 Message-ID: Subject: Re: [PATCH] Use signed boolean type for boolean vectors From: Richard Biener To: Ilya Enkovich Cc: GCC Patches Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-10/txt/msg03049.txt.bz2 On Wed, Oct 28, 2015 at 2:13 PM, Ilya Enkovich wrote: > Hi, > > Testing boolean vector conversions I found several runtime regressions > and investigation showed it's due to incorrect conversion caused by > unsigned boolean type. When boolean vector is represented as an > integer vector on target it's a signed integer actually. Unsigned > boolean type was chosen due to possible single bit values, but for > multiple bit values it causes wrong casting. The easiest way to fix > it is to use signed boolean value. The following patch does this and > fixes my problems with conversion. Bootstrapped and tested on > x86_64-unknown-linux-gnu. Is it OK? Hmm. Actually formally the "boolean" vectors were always 0 or -1 (all bits set). That is also true for a signed boolean with precision 1 but with higher precision what makes sure to sign-extend 'true'? So it's far from an obvious change, esp as you don't change the precision == 1 case. [I still think we should have precision == 1 for all boolean types] Richard. > Thanks, > Ilya > -- > gcc/ > > 2015-10-28 Ilya Enkovich > > * optabs.c (expand_vec_cond_expr): Always get sign from type. > * tree.c (wide_int_to_tree): Support negative values for boolean. > (build_nonstandard_boolean_type): Use signed type for booleans > with precision greater than 1. > > > diff --git a/gcc/optabs.c b/gcc/optabs.c > index e1ac0b8..37a67f1 100644 > --- a/gcc/optabs.c > +++ b/gcc/optabs.c > @@ -5373,7 +5373,6 @@ expand_vec_cond_expr (tree vec_cond_type, tree op0, tree op1, tree op2, > op0a = TREE_OPERAND (op0, 0); > op0b = TREE_OPERAND (op0, 1); > tcode = TREE_CODE (op0); > - unsignedp = TYPE_UNSIGNED (TREE_TYPE (op0a)); > } > else > { > @@ -5382,9 +5381,9 @@ expand_vec_cond_expr (tree vec_cond_type, tree op0, tree op1, tree op2, > op0a = op0; > op0b = build_zero_cst (TREE_TYPE (op0)); > tcode = LT_EXPR; > - unsignedp = false; > } > cmp_op_mode = TYPE_MODE (TREE_TYPE (op0a)); > + unsignedp = TYPE_UNSIGNED (TREE_TYPE (op0a)); > > > gcc_assert (GET_MODE_SIZE (mode) == GET_MODE_SIZE (cmp_op_mode) > diff --git a/gcc/tree.c b/gcc/tree.c > index e77d4b8..712390f 100644 > --- a/gcc/tree.c > +++ b/gcc/tree.c > @@ -1451,7 +1451,7 @@ wide_int_to_tree (tree type, const wide_int_ref &pcst) > case BOOLEAN_TYPE: > /* Cache false or true. */ > limit = 2; > - if (hwi < 2) > + if (IN_RANGE (hwi, 0, 1)) > ix = hwi; > break; > > @@ -8076,7 +8076,10 @@ build_nonstandard_boolean_type (unsigned HOST_WIDE_INT precision) > > type = make_node (BOOLEAN_TYPE); > TYPE_PRECISION (type) = precision; > - fixup_unsigned_type (type); > + if (precision > 1) > + fixup_signed_type (type); > + else > + fixup_unsigned_type (type); > > if (precision <= MAX_INT_CACHED_PREC) > nonstandard_boolean_type_cache[precision] = type;