From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 566103858C52 for ; Thu, 29 Feb 2024 13:28:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 566103858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 566103858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709213312; cv=none; b=HuTEQpILALlM2Dzdg5GruEMDxXGZYeWJAgi912mgPSGxws1lgcUYY/4bjlRxYpXx7ODa3bj/bvexMiu9G/oI1p2mG99X35h42Cc3wpG3DCOYGhoRVUwZ06BQLBrBBaEZdUIDnULFwJcYEFnkjkapXBbXzQtkuhomnj3z/+twwMw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709213312; c=relaxed/simple; bh=+q5sufiWaKFLcxHpDuYqJgMIH9DcDqG9T6VXbzGuQMQ=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=RmE31ViktLQdn9EkYfAYLOhPf23zWoLylOWiGhFDblqjdInUyql4OuYhsvZfNXNOnykgP1JehG+0MKB77lQkc+d08+EvLtKxoBdmI+gx36ZJ6bfbOG7nhBz8rOJu3wTKrQR3EVw0SiDF+zfelmn9C7uhiXyZMGtsiQhGh9339t0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709213311; h=from:from:reply-to:reply-to:subject:subject: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=UCLsAXNCZxTatGteXC29sQPkgip5X4HefEShiyHFkyw=; b=M1AT05sCF9dAqfBZxUDPBqRU+b6o9iuzUg7vty/x1opB5o/rfqnqBnrlTNxhwGfgoifujK Ct/TbCtvn75hEWMW2VJN05JjXSPz2XuxochuG99beos24jAxHg0Rwxco4GwLCMcyS/yW45 5kMX4d3ZKyvgbZZ5Jqo4nuZ6H/VBA+g= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-QKhtM7XFMjuMXvecpVPaXw-1; Thu, 29 Feb 2024 08:28:28 -0500 X-MC-Unique: QKhtM7XFMjuMXvecpVPaXw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8976F185A781; Thu, 29 Feb 2024 13:28:28 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 43561200A382; Thu, 29 Feb 2024 13:28:28 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 41TDSPTn1808160 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 29 Feb 2024 14:28:25 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 41TDSOCk1808157; Thu, 29 Feb 2024 14:28:24 +0100 Date: Thu, 29 Feb 2024 14:28:24 +0100 From: Jakub Jelinek To: Richard Biener Cc: richard.sandiford@arm.com, gcc-patches@gcc.gnu.org Subject: Re: [PATCH] tree-optimization/114151 - handle POLY_INT_CST in get_range_pos_neg Message-ID: Reply-To: Jakub Jelinek References: <20240229082111.024291329E@imap2.dmz-prg2.suse.org> <3os422s3-n361-n94s-06r8-69s8108n029q@fhfr.qr> MIME-Version: 1.0 In-Reply-To: <3os422s3-n361-n94s-06r8-69s8108n029q@fhfr.qr> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: On Thu, Feb 29, 2024 at 02:08:19PM +0100, Richard Biener wrote: > > So, wouldn't it be better to outline what you have above + POLY_INT_CST > > handling into a helper function, which similarly to get_range_pos_neg > > returns a bitmask, but rather than 1 bit for may be [0, max] and another bit for > > may be [min, -1] you return 3 bits, 1 bit for may be [1, max], another for > > may be [0, 0] and another for may be [min, -1]? > > Also, I bet you actually want to handle TREE_UNSIGNED just as [0, 0] > > and [1, max] ranges unlike get_range_pos_neg. > > I'm just lazy and given TYPE_OVERFLOW_WRAPS (and thus unsigned) doesn't > ever get here and I special-case integer_zerop it doesn't really matter > that in these cases get_range_pos_neg isn't exactly what's wanted - I'm > asking it only for those cases where it works just fine. Just handling integer_zerop doesn't cover the case where the chrec operand isn't INTEGER_CST, just includes zero in its range. And I'd think that is something quite common (sure, INTEGER_CST chrec operands are likely more common than that) that we know that something isn't negative, or isn't positive, or is non-negative, or is non-positive etc. > > So perhaps > > int ret = 7; > > if (TYPE_UNSIGNED (TREE_TYPE (arg))) > > ret = 3; > > if (poly_int_tree_p (arg)) > > { > > poly_wide_int w = wi::to_poly_wide (arg); > > if (known_lt (w, 0)) > > return 4; > > else if (known_eq (w, 0)) > > return 2; > > else if (known_gt (w, 0)) > > return 1; > > else > > return 7; > > } > > value_range r; > > if (!get_range_query (cfun)->range_of_expr (r, arg) > > || r.undefined_p ()) > > return ret; > > if (r.nonpositive_p ()) > > ret &= ~1; > > if (r.nonzero_p ()) > > ret &= ~2; > > if (r.nonnegative_p ()) > > ret &= ~4; > > return ret; And the above should be short/simple enough to be added even if it just has a single user (ok, 2 in the same stmt). Could be even just a lambda if there are no other uses for it, so you would need to care less how to name it/where to declare etc. > > I doubt POLY_INT_CST will appear on what the function is being called on > > (types with scalar integral modes, mainly in .*_OVERFLOW expansion or say > > division/modulo expansion, but maybe my imagination is limited); > > so, if you think this is a good idea and the poly int in that case somehow > > guarantees the existing behavior (guess for signed it would be at least when > > not -fwrapv in action UB if the addition of the first POLY_INT_CST coeff > > and the others multiplied by the runtime value wraps around, but for > > unsigned is there a guarantee that if all the POLY_INT_CST coefficients > > don't have msb set that the resulting value will not have msb set either? > > I hope so, but ... Let's wait for Richard there. Anyway, if for the chrec case it only uses it on non-wrapping signed, then the POLY_INT_CST handling is fine in there... Jakub