From patchwork Mon Aug 19 18:37:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 1973927 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=jLoEEWzR; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WnhDW56dQz1yfj for ; Tue, 20 Aug 2024 04:38:03 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CF723384A442 for ; Mon, 19 Aug 2024 18:38:01 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by sourceware.org (Postfix) with ESMTPS id 9A3DE384A86E for ; Mon, 19 Aug 2024 18:37:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A3DE384A86E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=quicinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9A3DE384A86E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724092651; cv=none; b=H6laCb7U1hcoofB8z5MUtmUwg87A5KTSeqCJPZSbY4YEi9vvx00bM/ux/zE6DZAcWvE2L0rabcMXeatt2Yv+1qxcCJp13gkE9hsJVoswT/0R2IZZ9eaIFyX1CCsZy4S4c7r1sufoaynIkYLya42lNsI5Ts0UmUV+mpDFh1rBVDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724092651; c=relaxed/simple; bh=gQZMun4B5GqI6ehbNHvVblHPFEGxOOhCKUblf+sbzew=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=LgmqeogFomf0kPDkH71MWd7e2QYBbzTGyA5weHpEh+sSeobwraZ0G532jE7o6e+MCOOBAz/GDz42U2VtFWf0BM8oeU5VULcZHklY0N8A7AaAeZdS95rbAAOUEPSW8wqLq0UhfcLOQyR83vvl/d4BfSHU6W9ypDXYnOuo98UgJqc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47JBG0Pg022124 for ; Mon, 19 Aug 2024 18:37:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= S7eVADABM4GA+vBhfxHkHVT0zRKi9NpUTS4Hxs//wbQ=; b=jLoEEWzRty5iylqz atntWe2gxSiQedDvda3w5b1UCrtlfCSj+lQSzqjRW+hDzz1vuTViCEza/oAZeJgb LCpZabrhEsNVmbRoFgqRUY+A9WjUAFurJHxYpADo7/KtuNH17cAIo7+Xv1SZWWNI 5R3Fn1YXfaYdPceJ8djdbIMzYuhaEyjFPGKxmo2GypXDtpu+VSlEXyWlqQe4KNdo NNyuLKyHuUb3VC0ux/UIArIRUYuhm4s6eUOb8MFw917NvCf+s7gezSWht423/ZMc m0DipI+6Pg86b85vlMBGpbvEEC7lDSjmowNoz0S9OuIyb/Y+MayPFoSn8SZBYDLv EiQzAg== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 412m32n78g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 19 Aug 2024 18:37:28 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 47JIbRR5032413 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 19 Aug 2024 18:37:27 GMT Received: from hu-apinski-lv.qualcomm.com (10.49.16.6) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 19 Aug 2024 11:37:27 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 2/2] phiopt: Reject non gimple val inside factor_out_conditional_operation [PR116412] Date: Mon, 19 Aug 2024 11:37:14 -0700 Message-ID: <20240819183714.3028693-2-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240819183714.3028693-1-quic_apinski@quicinc.com> References: <20240819183714.3028693-1-quic_apinski@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: s56jU52WF5NxlnHxQuEGT5IILs_FbTWy X-Proofpoint-ORIG-GUID: s56jU52WF5NxlnHxQuEGT5IILs_FbTWy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-19_16,2024-08-19_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxscore=0 suspectscore=0 priorityscore=1501 phishscore=0 bulkscore=0 lowpriorityscore=0 impostorscore=0 clxscore=1015 mlxlogscore=842 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2407110000 definitions=main-2408190126 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org After the conversion to use maybe_push_res_to_seq, sometimes (REALPART_EXPR and IMAGPART_EXPR and VCE) the argument will not be a gimple value and then phiopt here would create an invalid PHI. Just add a check for gimple val is the way to fix this. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/116412 gcc/ChangeLog: * tree-ssa-phiopt.cc (factor_out_conditional_operation): Make sure new_arg0 and new_arg1 are both gimple values. gcc/testsuite/ChangeLog: * gcc.dg/torture/pr116412-1.c: New test. Signed-off-by: Andrew Pinski --- gcc/testsuite/gcc.dg/torture/pr116412-1.c | 6 ++++++ gcc/tree-ssa-phiopt.cc | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr116412-1.c diff --git a/gcc/testsuite/gcc.dg/torture/pr116412-1.c b/gcc/testsuite/gcc.dg/torture/pr116412-1.c new file mode 100644 index 00000000000..3bc26ecd8b8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr116412-1.c @@ -0,0 +1,6 @@ +/* { dg-do compile } */ +double f(_Complex double a, _Complex double *b, int c) +{ + if (c) return __real__ a; + return __real__ *b; +} diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 770f3629fe1..be95798a065 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -368,6 +368,10 @@ factor_out_conditional_operation (edge e0, edge e1, gphi *phi, if (!types_compatible_p (TREE_TYPE (new_arg0), TREE_TYPE (new_arg1))) return NULL; + /* The new args need to be both gimple values. */ + if (!is_gimple_val (new_arg0) || !is_gimple_val (new_arg1)) + return NULL; + /* Function calls can only be const or an internal function as maybe_push_res_to_seq only handles those currently. */ if (!arg0_op.code.is_tree_code ())