From patchwork Wed Oct 30 12:33:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jovan Vukic X-Patchwork-Id: 99816 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E1763857C4F for ; Wed, 30 Oct 2024 12:34:01 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx07-0061a602.pphosted.com (mx07-0061a602.pphosted.com [143.55.144.161]) by sourceware.org (Postfix) with ESMTPS id 4FE693858027; Wed, 30 Oct 2024 12:33:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4FE693858027 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=rt-rk.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rt-rk.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4FE693858027 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=143.55.144.161 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1730291610; cv=pass; b=RAv44tenvqf6bTsEKQW/hjl4+CnA1K8J+1Df8hKeQzOTSnF0JNPfI85zMfWSKj1APpzXfKH+RJPKZpb5wikxIMDtHpTk1EFaL7HevVNw3LF4STLytMPQoOcAEy3of0KrEWVLjvUsePih9YrCmcIWasbJPM9o388RUpMAmjrmvgg= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1730291610; c=relaxed/simple; bh=C9C+1yIFRecMAHQoyg0MNEqhtXcq03rwU7qvQEgBoOg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Lf2vnTXzVZ452zj0sZeZ3ap2YofEgxKCsJ9l8vbtqK7Mns6mu+Y1qAMFPgzosTR7k4sMzrcDLQkYhA4bCV0X4cXV/WLARYGfiBxG2BE0PPEWtDAteiOPnE79J7GBjZ8WdwczjQ/NSCFE04OwTcYlepScM/LXsudn8tX3yizNkkY= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0278995.ppops.net [127.0.0.1]) by mx07-0061a602.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49UApvbB022964; Wed, 30 Oct 2024 12:33:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rt-rk.com; h=cc :content-type:date:from:message-id:mime-version:subject:to; s= s2021; bh=7LbsS0S65m9wNnczuXYugTt7+CGEm2WhDrhG96HBW5U=; b=XmuROz miejrA2UQu4t21q0L6ndoDnarW51juVjBbe1rq1pxEKmZjKSMMhcj5d2hZve/Nyh 0JspR4b7UvTj19zFte7NuwaNSEIjvc+tSjgP5LSr10RJ9zAJKkIj+gziuk/4axRL ieP4A9QQLuZzZz6bxRMNWb+RQgIkQABm1e8CsGiisi8kZ3oB1uavB+aVP12GslT4 xK0GAAihXIyAM2jht59tXbMYdA+VPZxK7Q6VqH/ykMzozoT4GkQAkfhb5kDfK+Gk RgmBp4wQigJZ0ZOnIA41n0nGlIDKbVssy3llOVm3y6+3KlxFKFMA/CdfBVuQtIu4 44XwcwFU49VnA93Q== Received: from eur03-am7-obe.outbound.protection.outlook.com (mail-am7eur03lp2241.outbound.protection.outlook.com [104.47.51.241]) by mx07-0061a602.pphosted.com (PPS) with ESMTPS id 42gnhc70e2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Oct 2024 12:33:25 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=S/elxzKZ0tEDkGYrId5NVcuMYq+qMWaoxCP3AvBBVr9bMH4ZDgJdc64PV3OBUYoIBbtqgL/1xWae8WRg1XeRSYnGyq9hc79ijVU+EOTCFoynlO2fAJGxmEGD0LjpjdN/ykdWYExhA9O8T2hxu43lbyndMftpSiuCiPgHAGPYbka6BwUzV0x9PwtWHDDZo2j5jIE9WwTLSqmkSeJPkjHrTj8LacopFn+GhKaDcVg7Fj6DalSHWc703AMVfEggh+OIQbp2hkFS8Kp4GpFJD0bOvk7fxm32Nr7QTAVvlUtScFHS5Bq0LWIkCI+p6jwk5lyhhJbkXI0GTVIDPhOqHTtmMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7LbsS0S65m9wNnczuXYugTt7+CGEm2WhDrhG96HBW5U=; b=O4QEz42SJEblhGt1TZedSIXS8AGAouTo+C+mDoD0+dm2Hq4K6xXDdZVQRHoG96USt7IlLJywG1XtNsKtBz+oJNa9gB8HtyphPJlenOWLsS3IMrNmZ4CjwnoG4DT1IESoyW2HwWT13Lj33nNLqf5Rd0a4VDfiksEYqV2jBQKQ14qT0rfo0y0WDi6lIVTr4nSOLdV8Cew081MquTx8FH4uit43UkJu5RV/6wUFk8uRF1SzousIsQYu+OHRS75mKscgwiMX5g52D0oPRGThZcy3SxB5ysqqqTWetaQQmJyiltEJfYVfa19mvznRjnxOBpIV+Hq34exzeEu4k7DV3cfIYw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=rt-rk.com; dmarc=pass action=none header.from=rt-rk.com; dkim=pass header.d=rt-rk.com; arc=none Received: from DB9PR08MB6634.eurprd08.prod.outlook.com (2603:10a6:10:23f::5) by AS8PR08MB6246.eurprd08.prod.outlook.com (2603:10a6:20b:296::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Wed, 30 Oct 2024 12:33:20 +0000 Received: from DB9PR08MB6634.eurprd08.prod.outlook.com ([fe80::3b98:f8f6:2fc8:a5a]) by DB9PR08MB6634.eurprd08.prod.outlook.com ([fe80::3b98:f8f6:2fc8:a5a%5]) with mapi id 15.20.8093.027; Wed, 30 Oct 2024 12:33:20 +0000 From: Jovan Vukic To: "gcc-patches@gcc.gnu.org" CC: "law@gcc.gnu.org" , Mile Davidovic , Dusan Stojkovic Subject: [PATCH v2] phi-opt: Add missed optimization for "(cond | (a != b)) ? b : a" Thread-Topic: [PATCH v2] phi-opt: Add missed optimization for "(cond | (a != b)) ? b : a" Thread-Index: AQHbKscOfRfoVPdi70mOd1bCEJa0FQ== Date: Wed, 30 Oct 2024 12:33:20 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: msip_labels: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DB9PR08MB6634:EE_|AS8PR08MB6246:EE_ x-ms-office365-filtering-correlation-id: dd9f8c2f-706c-4daf-2240-08dcf8df0999 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230040|1800799024|376014|366016|38070700018; x-microsoft-antispam-message-info: =?iso-8859-1?q?HwuZ+OvedC58BxWhKFgfKHT5ej?= =?iso-8859-1?q?3PmK9JJ/X0mYK4AZfBYd+mMUFFzTLFgEM66vtNhmZcHE6lSzWJnublLdtrpT?= =?iso-8859-1?q?0EDHHKgzVqMC9wBCcSkHcdywtWa/pxv4GRaQNM4z7sAffdB4TECBuQ8aJ2dR?= =?iso-8859-1?q?cx9w54aL1Y0BfDN5Tibz5RaIXpVXMnhknMwfnNvMSIZBkzWTKn3ofFKJo+xQ?= =?iso-8859-1?q?v5SkID952xV4VxbRdGwuogSl7GATEeqgNkkAaaRqx9hnsOxiifOVnAaWxnSQ?= =?iso-8859-1?q?VUfh3PmCpEZWiMheljAUf1L45TM+n/QrWLAExzlaQdDND14puW63z8Q/wVBe?= =?iso-8859-1?q?yrBdm/hHxC+okZ/pM75OMqToXAL/dWrdWtq9X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bA+p?= =?iso-8859-1?q?DnpZpdyOhiVu96BHiLonccGIRFv52BPHkvdNUI3kutqZXfWnWlWusmse1KDy?= =?iso-8859-1?q?81RP9952MPWJVulvCKy9+6/+XI6/S9VdSVd4c7VfhHj6yhQLHKZqaUNNiZ?= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR08MB6634.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(376014)(366016)(38070700018); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?QojNtcKRcSh69YJGaDDBBAM?= =?iso-8859-1?q?l8T/cGODRtN4lmbrNDt4xUEqLsWAjFZZoA4W5QY/VuUouk9dCemxx9gsJvfV?= =?iso-8859-1?q?IzbQtgJE8ibNPTnDQRNAhPF9ELU5dKn5oDTyO7EOp1F2kZC9hW7XWM87e8kI?= =?iso-8859-1?q?3NfNQiZ/aeCpLQVC7Qw8mn/nURaBG1abbIscBybmvOf5McEGC1YildsJGx85?= =?iso-8859-1?q?EPQLXzA2CbZYhGMdCKy783e2mqQAhQvZaTa0eGLr+mZjG7mvPtnOdKUKUH7C?= =?iso-8859-1?q?/yyZQplfQLRVnsyzIb0QymYCT3VGoLdP3RG2dbdIi/n1w/P14dTIarK5gmEB?= =?iso-8859-1?q?ozx7mcXhgMSqBjJum3iEow4E+NhR+qieUzVjvpB/r4zoYcR5x31w8QmhG4re?= =?iso-8859-1?q?wR8gu/y+6cVP2C+uY97cIGt2IuTO5cGkb7wb+BV/kdePCWM1KkpUGcHL6IPt?= =?iso-8859-1?q?1a26HU4QHlZhECcEqiOJVvF5k2zrSPd10kMGxeF/QnA+zwTWq4sRd78X2GBF?= =?iso-8859-1?q?2+wCikEnaeomLzFpHPb3vrcuOM0b/UaTu40O7m7R+iv8/tIN7fwxMZY5ceht?= =?iso-8859-1?q?4AJ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MBvEEAo89wlyJgpcG7j8mDFnIRq4VmYeMxFrNA?= =?iso-8859-1?q?QntI9hjHfClfMOQcN+KVRFt21Vj6zSS/ZeKyyQBGrQUStijWkZgBSw2OFh1b?= =?iso-8859-1?q?hTbjZbYVhQ6tAQAYyxbpypEmDiKyjlrxxNKeL9H+XslcDKnVCgUzRL+7U1D5?= =?iso-8859-1?q?/GlZGoTFV3N/O1u6d?= MIME-Version: 1.0 X-OriginatorOrg: rt-rk.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DB9PR08MB6634.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: dd9f8c2f-706c-4daf-2240-08dcf8df0999 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Oct 2024 12:33:20.2161 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 9bc3ed46-a3ca-43f0-b84e-9a557209a7df X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: NHwjPptm8eJt09Kc8KWm0r7zWx00NVy5Hq9hQR4sCfCNJ3vvNdy68zws2sxtf2pH0xYkaOej/lJv9gN/qqHmXg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6246 X-Authority-Analysis: v=2.4 cv=WrV5Msfv c=1 sm=1 tr=0 ts=67222795 cx=c_pps a=wOx2noN6cQSiNhTpOOYBYQ==:117 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=DAUX931o1VcA:10 a=bp5mhLeJ-vUA:10 a=wT45_P3iAAAA:8 a=N4GjFFZzyrDMAdM9P48A:9 a=wPNLvfGTeEIA:10 a=UL3_PAIEFygKHNRVUmsA:9 a=m-Z_27IZkzAA:10 a=RJRP_u8kRGsxlTjV8B5_:22 X-Proofpoint-GUID: zgJaxD2qynwgn4NLBg2v_paKkBuNMIN- X-Proofpoint-ORIG-GUID: zgJaxD2qynwgn4NLBg2v_paKkBuNMIN- X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, PLING_QUERY, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Thanks for the feedback on the first version of the patch. Accordingly: I have corrected the code formatting as requested. I added new tests to the existing file phi-opt-11.c, instead of creating a new one. I performed testing before and after applying the patch on the x86 architecture, and I confirm that there are no new regressions. The logic and general code of the patch itself have not been changed. > So the A EQ/NE B expression, we can reverse A and B in the expression > and still get the same result. But don't we have to be more careful for > the TRUE/FALSE arms of the ternary? For BIT_AND we need ? a : b for > BIT_IOR we need ? b : a. > > I don't see that gets verified in the existing code or after your > change. I suspect I'm just missing something here. Can you clarify how > we verify that BIT_AND gets ? a : b for the true/false arms and that > BIT_IOR gets ? b : a for the true/false arms? I did not communicate this clearly last time, but the existing optimization simplifies the expression "(cond & (a == b)) ? a : b" to the simpler "b". Similarly, the expression "(cond & (a == b)) ? b : a" simplifies to "a". Thus, the existing and my optimization perform the following simplifications: (cond & (a == b)) ? a : b -> b (cond & (a == b)) ? b : a -> a (cond | (a != b)) ? a : b -> a (cond | (a != b)) ? b : a -> b For this reason, for BIT_AND_EXPR when we have A EQ B, it is sufficient to confirm that one operand matches the true/false arm and the other matches the false/true arm. In both cases, we simplify the expression to the third operand of the ternary operation (i.e., OP0 ? OP1 : OP2 simplifies to OP2). This is achieved in the value_replacement function after successfully setting the value of *code within the rhs_is_fed_for_value_replacement function to EQ_EXPR. For BIT_IOR_EXPR, the same check is performed for A NE B, except now *code remains NE_EXPR, and then value_replacement returns the second operand (i.e., OP0 ? OP1 : OP2 simplifies to OP1). 2024-10-30 Jovan Vukic gcc/ChangeLog: * tree-ssa-phiopt.cc (rhs_is_fed_for_value_replacement): Add a new optimization opportunity for BIT_IOR_EXPR and a != b. (operand_equal_for_value_replacement): Ditto. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/phi-opt-11.c: Add more tests. CONFIDENTIALITY: The contents of this e-mail are confidential and intended only for the above addressee(s). If you are not the intended recipient, or the person responsible for delivering it to the intended recipient, copying or delivering it to anyone else or using it in any unauthorized manner is prohibited and may be unlawful. If you receive this e-mail by mistake, please notify the sender and the systems administrator at straymail@rt-rk.com immediately. --- gcc/testsuite/gcc.dg/tree-ssa/phi-opt-11.c | 31 +++++++++++++- gcc/tree-ssa-phiopt.cc | 48 ++++++++++++++-------- 2 files changed, 60 insertions(+), 19 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-11.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-11.c index 14c82cd5216..d1e284c5325 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-11.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-11.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O1 -fdump-tree-optimized --param logical-op-non-short-circuit=1" } */ +/* { dg-options "-O1 -fdump-tree-phiopt2 -fdump-tree-optimized --param logical-op-non-short-circuit=1" } */ int f(int a, int b, int c) { @@ -22,4 +22,33 @@ int h(int a, int b, int c, int d) return a; } +int i(int a, int b, int c) +{ + if ((a > c) & (a == b)) + return a; + return b; +} + +int j(int a, int b, int c) +{ + if ((a > c) & (a == b)) + return b; + return a; +} + +int k(int a, int b, int c) +{ + if ((a > c) | (a != b)) + return b; + return a; +} + +int l(int a, int b, int c) +{ + if ((a > c) | (a != b)) + return a; + return b; +} + +/* { dg-final { scan-tree-dump-times "if" 0 "phiopt2" } } */ /* { dg-final { scan-tree-dump-times "if" 0 "optimized" } } */ diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index cffafe101a4..61b33bfc361 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -1078,17 +1078,18 @@ jump_function_from_stmt (tree *arg, gimple *stmt) return false; } -/* RHS is a source argument in a BIT_AND_EXPR which feeds a conditional - of the form SSA_NAME NE 0. +/* RHS is a source argument in a BIT_AND_EXPR or BIT_IOR_EXPR which feeds + a conditional of the form SSA_NAME NE 0. - If RHS is fed by a simple EQ_EXPR comparison of two values, see if - the two input values of the EQ_EXPR match arg0 and arg1. + If RHS is fed by a simple EQ_EXPR or NE_EXPR comparison of two values, + see if the two input values of the comparison match arg0 and arg1. If so update *code and return TRUE. Otherwise return FALSE. */ static bool rhs_is_fed_for_value_replacement (const_tree arg0, const_tree arg1, - enum tree_code *code, const_tree rhs) + enum tree_code *code, const_tree rhs, + enum tree_code bit_expression_code) { /* Obviously if RHS is not an SSA_NAME, we can't look at the defining statement. */ @@ -1096,11 +1097,15 @@ rhs_is_fed_for_value_replacement (const_tree arg0, const_tree arg1, { gimple *def1 = SSA_NAME_DEF_STMT (rhs); - /* Verify the defining statement has an EQ_EXPR on the RHS. */ - if (is_gimple_assign (def1) && gimple_assign_rhs_code (def1) == EQ_EXPR) + /* Verify the defining statement has an EQ_EXPR or NE_EXPR on the RHS. */ + if (is_gimple_assign (def1) + && ((bit_expression_code == BIT_AND_EXPR + && gimple_assign_rhs_code (def1) == EQ_EXPR) + || (bit_expression_code == BIT_IOR_EXPR + && gimple_assign_rhs_code (def1) == NE_EXPR))) { - /* Finally verify the source operands of the EQ_EXPR are equal - to arg0 and arg1. */ + /* Finally verify the source operands of the EQ_EXPR or NE_EXPR + are equal to arg0 and arg1. */ tree op0 = gimple_assign_rhs1 (def1); tree op1 = gimple_assign_rhs2 (def1); if ((operand_equal_for_phi_arg_p (arg0, op0) @@ -1119,8 +1124,9 @@ rhs_is_fed_for_value_replacement (const_tree arg0, const_tree arg1, /* Return TRUE if arg0/arg1 are equal to the rhs/lhs or lhs/rhs of COND. - Also return TRUE if arg0/arg1 are equal to the source arguments of a - an EQ comparison feeding a BIT_AND_EXPR which feeds COND. + Also return TRUE if arg0/arg1 are equal to the source arguments of an + EQ comparison feeding a BIT_AND_EXPR, or NE comparison feeding a + BIT_IOR_EXPR which feeds COND. Return FALSE otherwise. */ @@ -1139,27 +1145,33 @@ operand_equal_for_value_replacement (const_tree arg0, const_tree arg1, return true; /* Now handle more complex case where we have an EQ comparison - which feeds a BIT_AND_EXPR which feeds COND. + feeding a BIT_AND_EXPR, or a NE comparison feeding a BIT_IOR_EXPR, + which then feeds into COND. First verify that COND is of the form SSA_NAME NE 0. */ if (*code != NE_EXPR || !integer_zerop (rhs) || TREE_CODE (lhs) != SSA_NAME) return false; - /* Now ensure that SSA_NAME is set by a BIT_AND_EXPR. */ + /* Now ensure that SSA_NAME is set by a BIT_AND_EXPR or BIT_OR_EXPR. */ def = SSA_NAME_DEF_STMT (lhs); - if (!is_gimple_assign (def) || gimple_assign_rhs_code (def) != BIT_AND_EXPR) + if (!is_gimple_assign (def) + || (gimple_assign_rhs_code (def) != BIT_AND_EXPR + && gimple_assign_rhs_code (def) != BIT_IOR_EXPR)) return false; - /* Now verify arg0/arg1 correspond to the source arguments of an - EQ comparison feeding the BIT_AND_EXPR. */ + /* Now verify arg0/arg1 correspond to the source arguments of an EQ + comparison feeding the BIT_AND_EXPR or a NE comparison feeding the + BIT_IOR_EXPR. */ tree tmp = gimple_assign_rhs1 (def); - if (rhs_is_fed_for_value_replacement (arg0, arg1, code, tmp)) + if (rhs_is_fed_for_value_replacement (arg0, arg1, code, tmp, + gimple_assign_rhs_code (def))) return true; tmp = gimple_assign_rhs2 (def); - if (rhs_is_fed_for_value_replacement (arg0, arg1, code, tmp)) + if (rhs_is_fed_for_value_replacement (arg0, arg1, code, tmp, + gimple_assign_rhs_code (def))) return true; return false;