From patchwork Wed Jun 9 01:32:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1489676 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=uDi2yket; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G08kR5hh0z9sW6 for ; Wed, 9 Jun 2021 11:33:01 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 14CAC3893C58 for ; Wed, 9 Jun 2021 01:32:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 14CAC3893C58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1623202378; bh=y5GRI0Beq/i3tSkwr/EyqzDbi3VLVXeJskIfUcGrCHg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=uDi2yket2OF69ecOXCIopQYpzedCSr3PFRDzkEndpD+LfnCLQCrZAGDsy3nDRvaul fOMKqVGHR8BGx1853aNgzFsDipkdYlOiy7Vn8DMZrbYyWC5D3OgYYGjdYfdBCQtbZl 90a+Mv3u4Q5WK5bgxmEiaaDjGZ29fmFN5RGvCPKE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id E88453893C47 for ; Wed, 9 Jun 2021 01:32:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E88453893C47 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 1590W1KD009085 for ; Tue, 8 Jun 2021 18:32:14 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com with ESMTP id 39262bugj1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 08 Jun 2021 18:32:14 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 18:32:12 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 18:32:12 -0700 Received: from linux.wrightpinski.org.com (unknown [10.69.242.197]) by maili.marvell.com (Postfix) with ESMTP id DFBE23F703F; Tue, 8 Jun 2021 18:32:11 -0700 (PDT) To: Subject: [PATCH 1/2] Fix PR 100925: Limit some a?CST1:CST2 optimizations to intergal types only Date: Tue, 8 Jun 2021 18:32:07 -0700 Message-ID: <1623202328-13664-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: e6VmRDUANRUCqapMB2klXtEgSfnSztqB X-Proofpoint-GUID: e6VmRDUANRUCqapMB2klXtEgSfnSztqB X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-06-08_17:2021-06-04, 2021-06-08 signatures=0 X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Cc: Andrew Pinski Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" From: Andrew Pinski The problem here is with offset (and pointer) types is we produce a negative expression when this optimization hits. It is easier to disable this optimization for all non-integeral types instead of finding an integer type which is the same precission as the type to do the negative expression on it. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: PR tree-optimization/100925 * match.pd (a ? CST1 : CST2): Limit transformations that would produce a negative to integeral types only. Change !POINTER_TYPE_P to INTEGRAL_TYPE_P also. gcc/testsuite/ChangeLog: * g++.dg/torture/pr100925.C: New test. --- gcc/match.pd | 8 ++++---- gcc/testsuite/g++.dg/torture/pr100925.C | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/torture/pr100925.C diff --git a/gcc/match.pd b/gcc/match.pd index d06ff170684..bf22bc3a198 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3733,10 +3733,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (integer_onep (@1)) (convert (convert:boolean_type_node @0))) /* a ? -1 : 0 -> -a. */ - (if (integer_all_onesp (@1)) + (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@1)) (negate (convert (convert:boolean_type_node @0)))) /* a ? powerof2cst : 0 -> a << (log2(powerof2cst)) */ - (if (!POINTER_TYPE_P (type) && integer_pow2p (@1)) + (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@1)) (with { tree shift = build_int_cst (integer_type_node, tree_log2 (@1)); } @@ -3750,10 +3750,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (integer_onep (@2)) (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } ))) /* a ? -1 : 0 -> -(!a). */ - (if (integer_all_onesp (@2)) + (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2)) (negate (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } )))) /* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */ - (if (!POINTER_TYPE_P (type) && integer_pow2p (@2)) + (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@2)) (with { tree shift = build_int_cst (integer_type_node, tree_log2 (@2)); } diff --git a/gcc/testsuite/g++.dg/torture/pr100925.C b/gcc/testsuite/g++.dg/torture/pr100925.C new file mode 100644 index 00000000000..de13950dca0 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr100925.C @@ -0,0 +1,24 @@ +// { dg-do compile } + +struct QScopedPointerDeleter { + static void cleanup(int *); +}; +class QScopedPointer { + typedef int *QScopedPointer::*RestrictedBool; + +public: + operator RestrictedBool() { return d ? nullptr : &QScopedPointer::d; } + void reset() { + if (d) + QScopedPointerDeleter::cleanup(d); + } + int *d; +}; +class DOpenGLPaintDevicePrivate { +public: + QScopedPointer fbo; +} DOpenGLPaintDeviceresize_d; +void DOpenGLPaintDeviceresize() { + if (DOpenGLPaintDeviceresize_d.fbo) + DOpenGLPaintDeviceresize_d.fbo.reset(); +}