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.129.124]) by sourceware.org (Postfix) with ESMTPS id EE30F385734B for ; Wed, 5 Oct 2022 12:22:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EE30F385734B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664972569; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zQGAZ2WWv38f7FeLr1n4qrRXXg3uJ+ZOf2uYw4QSCvE=; b=cwKaanrllAnJQDGTXRa+V+LyY4xoV2YI8TE9daG8KF0uhfrtj+s3tM8kG3uxp//p311g18 wmacS7qu5uxtm6ibJlkWIx2wxWzZ6sPDE0iQq1P8Lvotsiizag1tBNAM5T18buyePDo3KA 9xC1sm6CsqOfOz1yZvKgJu8vprLjFKY= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-561-b7Au1hAMPiOm2tYwRXV_YQ-1; Wed, 05 Oct 2022 08:22:48 -0400 X-MC-Unique: b7Au1hAMPiOm2tYwRXV_YQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7A7931C0CE63 for ; Wed, 5 Oct 2022 12:22:48 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.194.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2AFE62028DC1; Wed, 5 Oct 2022 12:22:40 +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 295CMbpL1579778 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 5 Oct 2022 14:22:37 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 295CMbD61579777; Wed, 5 Oct 2022 14:22:37 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , drepper@redhat.com, Aldy Hernandez Subject: [COMMITTED] [PR tree-optimization/107052] range-ops: Pass nonzero masks through cast. Date: Wed, 5 Oct 2022 14:22:35 +0200 Message-Id: <20221005122236.1579762-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.3 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 List-Id: 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; } -- 2.37.1