From patchwork Wed Oct 5 12:21:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1729 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp570999wrs; Wed, 5 Oct 2022 05:22:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Oua3UE/Ka40uHgHcQyCkLkoby5fmh2P4DbskKRJ1Aiqck1DwrkWFfULwBfwYDaLHeKb3R X-Received: by 2002:a05:6402:5106:b0:451:787c:9fcc with SMTP id m6-20020a056402510600b00451787c9fccmr27992638edd.164.1664972578870; Wed, 05 Oct 2022 05:22:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664972578; cv=none; d=google.com; s=arc-20160816; b=0vOWVP0PdWFNdGG1qZr3mE2pGesmJm7YVGrT/gXeiHxePMG57efxdxbkPUjccvJD4a BlCHYDxTEuDPdyMCN6PlgPj1hRQFsJrCzkLkMMIujT5JGLGniHaRXAzvATBPXU48z3fS 3PC+hHrBoI2cHFkZDBTZh7dBSxnBltcJd9+6wQP1wb5Kqe+ImAUO+aCAUgqiaGagflNp WWq63dQLEBddHFs7xAFovFXr8sqTuOlrcmlwWEoOgIXtVSKCfwI3G7g1b+gSr+pE41ww Vh36KTH6pR+/bpiqCaq5guLoVD6yofGCgCywGTGnU3mG+JUXWZnrFBzd03bO5sj3aRoR p88g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=zQGAZ2WWv38f7FeLr1n4qrRXXg3uJ+ZOf2uYw4QSCvE=; b=F7/UUbIeAYtTUPCzb29uYLSgKbpOsxR+CF5srZ6cD5mEeLrDLAzkjEECUk6OuDUy9f 5H1nQhfOmN+dGv2+FJ7yz6qL7eZEI+byo+eBxGRhvj54e5PwEqGj8Cs1QvBYvgRRFVsk ojrAtzYWp41G/tFkPUV/t7Vq7Nbj7FYgtYvo7crTkuRdxq5QEJvO5pgPxw0/blQ/ZSF6 hGUzLRYRkmSCH0xqTrrSk5ntZ7GjL6aNQJGbmqwAMpkQiMsHWoaV2Cx7HXPS5cLmuuko h7qIjqiDnC5Glpb1gUzDlZ0ixfol3l/z+/AGwCijS5p6aaoA2hrOqtD1NIZhkrg/uh2V 9kag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YaddNqkQ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id z19-20020a056402275300b00451d1712f5dsi15835925edd.40.2022.10.05.05.22.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 05:22:58 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YaddNqkQ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9C3FF385736C for ; Wed, 5 Oct 2022 12:22:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C3FF385736C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664972577; bh=zQGAZ2WWv38f7FeLr1n4qrRXXg3uJ+ZOf2uYw4QSCvE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=YaddNqkQ4I8mAMqDs/tvEmiVXjyO3LiNK4zDxgClcrXAfURQG4jKvrZh/gPQ0QLwJ MuFlv9p/FWlEdtg3ceWp7vr7NmTPQG/mJtRapJW3gRBpxwjn0z7WdqNxJPCuxqbty0 ucEMRh4F8KaLzJS239DLu/GuQuO8yV7rQfkp2r08= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 507833858D37 for ; Wed, 5 Oct 2022 12:22:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 507833858D37 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-411-ZiFOCloHOpuL-JghSmmEXw-1; Wed, 05 Oct 2022 08:22:11 -0400 X-MC-Unique: ZiFOCloHOpuL-JghSmmEXw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8646C86EB2F for ; Wed, 5 Oct 2022 12:22:05 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.194.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1EAC44099B51; Wed, 5 Oct 2022 12:21:57 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 295CLuS51579718 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 5 Oct 2022 14:21:56 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 295CLuax1579717; Wed, 5 Oct 2022 14:21:56 +0200 To: GCC patches Subject: [COMMITTED] [PR tree-optimization/107052] range-ops: Pass nonzero masks through cast. Date: Wed, 5 Oct 2022 14:21:53 +0200 Message-Id: <20221005122154.1579701-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Cc: uli@abulafia.quesejoda.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745850286977014998?= X-GMAIL-MSGID: =?utf-8?q?1745850286977014998?= Track nonzero masks through a cast in range-ops. We could also track through a truncating cast if the mask fits in the outer type. I will do that as a follow-up patch because I already have this patchset tested. PR tree-optimization/107052 gcc/ChangeLog: * range-op.cc (operator_cast::fold_range): Set nonzero mask. --- gcc/range-op.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 4f647abd91c..6fa27a8904e 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -2515,6 +2515,14 @@ operator_cast::fold_range (irange &r, tree type ATTRIBUTE_UNUSED, if (r.varying_p ()) return true; } + + // Pass nonzero mask through the cast. + if (!truncating_cast_p (inner, outer)) + { + wide_int nz = inner.get_nonzero_bits (); + nz = wide_int::from (nz, TYPE_PRECISION (type), TYPE_SIGN (inner.type ())); + r.set_nonzero_bits (nz); + } return true; }