| Message ID | 20250914181521.272481-1-andrew.pinski@oss.qualcomm.com |
|---|---|
| State | New |
| Headers |
Return-Path: <gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org> 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 EE5E93858CD1 for <patchwork@sourceware.org>; Sun, 14 Sep 2025 18:17:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE5E93858CD1 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=ZqCy7oAD 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 99A0A3858D1E for <gcc-patches@gcc.gnu.org>; Sun, 14 Sep 2025 18:15:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 99A0A3858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=oss.qualcomm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oss.qualcomm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 99A0A3858D1E 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=1757873748; cv=none; b=PSqU+Xmgyslzz6twi4FKNZm46mzYKOB300Yh49/LSD3u6UlxLxTG6YTryRfdx6rsbAxJce8sgEsDARoyWwm61z+rmNwBq5g+DNrdMt2gXx4vZrUJJL6ivZBRXNI7y+sFESg2vv7eXzTNmC5u12AsthQCzzn86C8E9W/XcT7/MPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757873748; c=relaxed/simple; bh=ixNh5lyGmlH6RbJENgZUDuOHtAEHzpq9PX3isRuqV+c=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=CeraHpUb6H8fvaQLWp9RUVpzIcE1k8uLV+Y0Cel9s+flitn3WJakfaM+V3vaCchViAzvoP/aeQmHQw8iV97GSohjveOkhZCJqho6Dc0kGKRw0T4Vz0WBh3p5nULaBqWhDH8U4OQ0ekvDOoioGalIdUMZD8MYHxJqGcJzRkglaZo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 99A0A3858D1E Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 58EDTinJ020555 for <gcc-patches@gcc.gnu.org>; Sun, 14 Sep 2025 18:15:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=qcppdkim1; bh=q5ZvwEGWp4sKJLECZe1y6sA7ArxxSI79bze T6NUav8o=; b=ZqCy7oADNgJYtiiabrKe3S+E3AP7F6UglAOisY5Td76TFb3+si6 WI8VcWLUITa2qOR4E/qljMHuW+qcB5LVpsVvpBvviY0WMq7BMFkxNozTj/Vd3hK/ OxjqIctVjgAUKLtIGF1ecOtAU0MbJ0nbHQKATf5UwXtD5iEVjcxo/Z8+0gzgXCZO CVMmVS6K58CCIIb2sBYJBtueRDdydsYVpzoe5m6mhtO5DDf5FuwnOigj4YTfRtBM uISj/cnzJ+HEhAnzfmHmK6LuM61xUzr3i8Fy2gVe5jc+ldnJIdcDtnmD1OKX+QG0 W+2aDUnnnsamOP7N/UFEA3B3HZ1dIAh7swQ== Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4951chah6q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for <gcc-patches@gcc.gnu.org>; Sun, 14 Sep 2025 18:15:47 +0000 (GMT) Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-32dd692614aso5269732a91.1 for <gcc-patches@gcc.gnu.org>; Sun, 14 Sep 2025 11:15:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757873746; x=1758478546; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=q5ZvwEGWp4sKJLECZe1y6sA7ArxxSI79bzeT6NUav8o=; b=YspoOShcwxrtfpjqc8ZHCNb01ytWGXWe5nNBH0yOwfGtuMgf6K0ZW6cALql1sFs72M 4kjcH2E3KAS5Mh9ugp40SJL75EMK6jzm1L5LvUNP0lp/QVc0F4ivxXthI65JZWR3JVOa waeoeuvEEAkkPKJvevLCXH6tbwKOdUtgO63En0YMyx8tavCICyZutBa69DFvvsv7VyqV R0iNwzQ6UonxLk6EDs/b5NLYE294atI8aMKZiHQyREbVayfNbYID4ORU04ifUYf2XokP rz7y94Zob3f18ZddA2ndP6I9kl4is0T9adu7P6/+4Mq1cxYlVuniQEpNRpLudj4IXkXN YGSA== X-Gm-Message-State: AOJu0Yxe/Y0k+0W7Lb+wMt7e+ATRqgr3F+X55caouzUHvDZ2G7EtRhC5 ssTmQvoE1OTJlEPoaamYG6PPX44mLpaghelHdnpfsajBVX5WQLCskFFiiFrHstpmQpx3iSU1y/q cFE0Jiml8V0Bh0IumIU+mhLsm8uYl6DwEAB7b2DwTQllCt2ts7vlJW6qU40WytTAd2z0H X-Gm-Gg: ASbGnctZGLUdwJzRBpxoE/qdy+CPC9dNaxm+wVlZOqL341SFrS4HhXst4kY4WL0REhn PCx2dFlpqK2PJsH3SbBo99e//eIDs9oUwxC9f14FfxrrExVTYxyfrfsbST0kbMe5Q8YUG6Q1qjn 9DF9V95CYKniMbI9vKxpjTimMVQ2Bk/cNC/mVr7itYulbrVZzdKm/bdfPVjJfCMwsCeOss2RpRf LKmHS7nuBBUS+3tn9ojoA33TSHLW+RX5FSV1VR6oaVetwLcZQisxVG+KLYoKgQtF9TE3Wo0DbdQ 4sLia6XD8xqb0R6wJsnGA6Jso5pVFDP1k+he4zLflonNCTWmA0GPvPXDcIkhAgw/G14= X-Received: by 2002:a17:90b:1802:b0:32e:38f5:e860 with SMTP id 98e67ed59e1d1-32e38f5ea82mr2995606a91.15.1757873746234; Sun, 14 Sep 2025 11:15:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3T+NQxZ+wu/dqoyhUnHLwct9z+qG9bab02wIc4ReCe9DGdZfA4LLcChd62Tpz+OpZ/nJa8Q== X-Received: by 2002:a17:90b:1802:b0:32e:38f5:e860 with SMTP id 98e67ed59e1d1-32e38f5ea82mr2995577a91.15.1757873745667; Sun, 14 Sep 2025 11:15:45 -0700 (PDT) Received: from xeond2.wrightpinski.org ([98.97.40.147]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32deacdf9bcsm8399398a91.23.2025.09.14.11.15.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Sep 2025 11:15:45 -0700 (PDT) From: Andrew Pinski <andrew.pinski@oss.qualcomm.com> To: gcc-patches@gcc.gnu.org Cc: Andrew Pinski <andrew.pinski@oss.qualcomm.com> Subject: [PATCH] match: Simplify `ptr0 - (ptr0 - ptr1)` into ptr1 [PR121921] Date: Sun, 14 Sep 2025 11:15:21 -0700 Message-ID: <20250914181521.272481-1-andrew.pinski@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Authority-Analysis: v=2.4 cv=eeo9f6EH c=1 sm=1 tr=0 ts=68c70653 cx=c_pps a=UNFcQwm+pnOIJct1K4W+Mw==:117 a=2mqOQD9H2PM3++1fUlZQ2w==:17 a=yJojWOMRYYMA:10 a=EUspDBNiAAAA:8 a=1QY4Lv1Fp_pEeinB4LwA:9 a=uKXjsCUrEbL0IQVhDsJ9:22 X-Proofpoint-ORIG-GUID: kVRGXQF87jMli4DL4ksPDkUx4f6lgTpU X-Proofpoint-GUID: kVRGXQF87jMli4DL4ksPDkUx4f6lgTpU X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwOTEzMDAzNiBTYWx0ZWRfX8GUZUo9dt482 rhVa/DZZQOVHrRYp53UJH8Dl1pnV6RcHJK3MT5M9DsnNy3vs+8nU72Iqq97sPtqxTyMWSe80Kw2 LWk9QxwIU1gIbZx7HBUyEXRv0i6RHuRSxA6UzwVwLCXsjy1Gqogl7md0zDE2CHYB8r8EjuIXs3t HI/53c5LI8xTAAW3zBcgESrVwm5iZoRLaUB/P+UKkZ7g/nN4WBjnWBVJTBV4XGlONB+QSUO9N32 W7GQssGviPFqEWgT53lZSzjgd5GXXLAgCQjxbU2GC3DkI0gmCgUZWC0UbTbidP9PbkkIEtLYsH2 5RFmcmUNxrfbw4PqOATQzoiwmqipuDVEgi86pujZENBL1e5xHCt0tfE0VwoSESdQp/2LpBze4vf +zwDhb4Z X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1117,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-09-14_07,2025-09-12_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 impostorscore=0 bulkscore=0 adultscore=0 priorityscore=1501 phishscore=0 spamscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2507300000 definitions=main-2509130036 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org |
| Series |
match: Simplify `ptr0 - (ptr0 - ptr1)` into ptr1 [PR121921]
|
|
Commit Message
Andrew Pinski
Sept. 14, 2025, 6:15 p.m. UTC
This pattern shows up with some C++ code (std::vector<bool>) where we get:
```
_9 = _201 - _36;
_10 = (long unsigned int) _9;
_11 = -_10;
_12 = _201 + _11;
```
In the original code it was `end - (end - begin)` but with inlined functions so it
is not direct fixable.
This patch adds a new amtch pattern like what was added in
r0-128019-g77574c353464b3 (and then moved to match with r5-4705-ga499aac5dfa5d9).
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/121921
gcc/ChangeLog:
* match.pd (`eptr - (eptr - bptr)`): New patterns.
gcc/testsuite/ChangeLog:
* gcc.dg/pr121921-1.c: New testcase.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
---
gcc/match.pd | 24 ++++++++++++++++++++++++
gcc/testsuite/gcc.dg/pr121921-1.c | 14 ++++++++++++++
2 files changed, 38 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/pr121921-1.c
Comments
On Sun, Sep 14, 2025 at 8:17 PM Andrew Pinski <andrew.pinski@oss.qualcomm.com> wrote: > > This pattern shows up with some C++ code (std::vector<bool>) where we get: > ``` > _9 = _201 - _36; > _10 = (long unsigned int) _9; > _11 = -_10; > _12 = _201 + _11; > ``` > > In the original code it was `end - (end - begin)` but with inlined functions so it > is not direct fixable. > > This patch adds a new amtch pattern like what was added in > r0-128019-g77574c353464b3 (and then moved to match with r5-4705-ga499aac5dfa5d9). > > Bootstrapped and tested on x86_64-linux-gnu. I wonder, if in general, -(ptr1 - ptr2) can be changed to (ptr2 - ptr1). I think this should be OK? Of course with the unsigned conversion in the way it's (long unsigned int)(ptr2 - ptr2)? Thanks, Richard. > PR tree-optimization/121921 > gcc/ChangeLog: > > * match.pd (`eptr - (eptr - bptr)`): New patterns. > > gcc/testsuite/ChangeLog: > * gcc.dg/pr121921-1.c: New testcase. > > Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com> > --- > gcc/match.pd | 24 ++++++++++++++++++++++++ > gcc/testsuite/gcc.dg/pr121921-1.c | 14 ++++++++++++++ > 2 files changed, 38 insertions(+) > create mode 100644 gcc/testsuite/gcc.dg/pr121921-1.c > > diff --git a/gcc/match.pd b/gcc/match.pd > index dbbb7b51275..5dea74aabe2 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -3047,6 +3047,30 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (if (TYPE_PRECISION (TREE_TYPE (@2)) >= TYPE_PRECISION (TREE_TYPE (@3))) > (convert @1))) > > +/* Likewise but with an additional negate here > + to swap the order of the subtraction. */ > +/* Pattern match > + tem1 = (long) ptr1; > + tem2 = (long) ptr2; > + tem3 = tem1 - tem2; > + tem4 = (unsigned long) tem3; > + tem5 = -tem3; > + tem5 = ptr1 + tem5; > + and produce > + tem5 = ptr2; */ > +(simplify > + (pointer_plus @0 (negate (convert?@2 (minus@3 (convert @0) (convert @1))))) > + /* Conditionally look through a sign-changing conversion. */ > + (if (TYPE_PRECISION (TREE_TYPE (@2)) == TYPE_PRECISION (TREE_TYPE (@3)) > + && ((GIMPLE && useless_type_conversion_p (type, TREE_TYPE (@1))) > + || (GENERIC && type == TREE_TYPE (@1)))) > + @1)) > +/* ptr0 - (ptr0 - ptr1) -> ptr1 */ > +(simplify > + (pointer_plus @0 (negate (convert?@2 (pointer_diff@3 @@0 @1)))) > + (if (TYPE_PRECISION (TREE_TYPE (@2)) >= TYPE_PRECISION (TREE_TYPE (@3))) > + (convert @1))) > + > /* Pattern match > tem = (sizetype) ptr; > tem = tem & algn; > diff --git a/gcc/testsuite/gcc.dg/pr121921-1.c b/gcc/testsuite/gcc.dg/pr121921-1.c > new file mode 100644 > index 00000000000..b11afc819da > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr121921-1.c > @@ -0,0 +1,14 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O -fdump-tree-cddce1" } */ > + > +/* PR tree-optimization/121921 */ > + > +int * > +fx (int *b, int *e) > +{ > + __SIZE_TYPE__ p = b - e; > + /* The first forwprop pass should optimize this to return e; */ > + return b - p; > +} > + > +/* { dg-final { scan-tree-dump "return e" "cddce1" } } */ > -- > 2.43.0 >
On Mon, Sep 15, 2025 at 1:02 AM Richard Biener <richard.guenther@gmail.com> wrote: > > On Sun, Sep 14, 2025 at 8:17 PM Andrew Pinski > <andrew.pinski@oss.qualcomm.com> wrote: > > > > This pattern shows up with some C++ code (std::vector<bool>) where we get: > > ``` > > _9 = _201 - _36; > > _10 = (long unsigned int) _9; > > _11 = -_10; > > _12 = _201 + _11; > > ``` > > > > In the original code it was `end - (end - begin)` but with inlined functions so it > > is not direct fixable. > > > > This patch adds a new amtch pattern like what was added in > > r0-128019-g77574c353464b3 (and then moved to match with r5-4705-ga499aac5dfa5d9). > > > > Bootstrapped and tested on x86_64-linux-gnu. > > I wonder, if in general, -(ptr1 - ptr2) can be changed to (ptr2 - > ptr1). I think > this should be OK? Of course with the unsigned conversion in the way > it's (long unsigned int)(ptr2 - ptr2)? So I see there is already a pattern to do `(negate (pointer_diff @0 @1))` -> `(pointer_diff @1 @0)`. I will be extending it to handle the nop conversion too. Will be submitting a new patch with that change soon. Thanks, Andrew > > Thanks, > Richard. > > > PR tree-optimization/121921 > > gcc/ChangeLog: > > > > * match.pd (`eptr - (eptr - bptr)`): New patterns. > > > > gcc/testsuite/ChangeLog: > > * gcc.dg/pr121921-1.c: New testcase. > > > > Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com> > > --- > > gcc/match.pd | 24 ++++++++++++++++++++++++ > > gcc/testsuite/gcc.dg/pr121921-1.c | 14 ++++++++++++++ > > 2 files changed, 38 insertions(+) > > create mode 100644 gcc/testsuite/gcc.dg/pr121921-1.c > > > > diff --git a/gcc/match.pd b/gcc/match.pd > > index dbbb7b51275..5dea74aabe2 100644 > > --- a/gcc/match.pd > > +++ b/gcc/match.pd > > @@ -3047,6 +3047,30 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > > (if (TYPE_PRECISION (TREE_TYPE (@2)) >= TYPE_PRECISION (TREE_TYPE (@3))) > > (convert @1))) > > > > +/* Likewise but with an additional negate here > > + to swap the order of the subtraction. */ > > +/* Pattern match > > + tem1 = (long) ptr1; > > + tem2 = (long) ptr2; > > + tem3 = tem1 - tem2; > > + tem4 = (unsigned long) tem3; > > + tem5 = -tem3; > > + tem5 = ptr1 + tem5; > > + and produce > > + tem5 = ptr2; */ > > +(simplify > > + (pointer_plus @0 (negate (convert?@2 (minus@3 (convert @0) (convert @1))))) > > + /* Conditionally look through a sign-changing conversion. */ > > + (if (TYPE_PRECISION (TREE_TYPE (@2)) == TYPE_PRECISION (TREE_TYPE (@3)) > > + && ((GIMPLE && useless_type_conversion_p (type, TREE_TYPE (@1))) > > + || (GENERIC && type == TREE_TYPE (@1)))) > > + @1)) > > +/* ptr0 - (ptr0 - ptr1) -> ptr1 */ > > +(simplify > > + (pointer_plus @0 (negate (convert?@2 (pointer_diff@3 @@0 @1)))) > > + (if (TYPE_PRECISION (TREE_TYPE (@2)) >= TYPE_PRECISION (TREE_TYPE (@3))) > > + (convert @1))) > > + > > /* Pattern match > > tem = (sizetype) ptr; > > tem = tem & algn; > > diff --git a/gcc/testsuite/gcc.dg/pr121921-1.c b/gcc/testsuite/gcc.dg/pr121921-1.c > > new file mode 100644 > > index 00000000000..b11afc819da > > --- /dev/null > > +++ b/gcc/testsuite/gcc.dg/pr121921-1.c > > @@ -0,0 +1,14 @@ > > +/* { dg-do compile } */ > > +/* { dg-options "-O -fdump-tree-cddce1" } */ > > + > > +/* PR tree-optimization/121921 */ > > + > > +int * > > +fx (int *b, int *e) > > +{ > > + __SIZE_TYPE__ p = b - e; > > + /* The first forwprop pass should optimize this to return e; */ > > + return b - p; > > +} > > + > > +/* { dg-final { scan-tree-dump "return e" "cddce1" } } */ > > -- > > 2.43.0 > >
diff --git a/gcc/match.pd b/gcc/match.pd index dbbb7b51275..5dea74aabe2 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3047,6 +3047,30 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (TYPE_PRECISION (TREE_TYPE (@2)) >= TYPE_PRECISION (TREE_TYPE (@3))) (convert @1))) +/* Likewise but with an additional negate here + to swap the order of the subtraction. */ +/* Pattern match + tem1 = (long) ptr1; + tem2 = (long) ptr2; + tem3 = tem1 - tem2; + tem4 = (unsigned long) tem3; + tem5 = -tem3; + tem5 = ptr1 + tem5; + and produce + tem5 = ptr2; */ +(simplify + (pointer_plus @0 (negate (convert?@2 (minus@3 (convert @0) (convert @1))))) + /* Conditionally look through a sign-changing conversion. */ + (if (TYPE_PRECISION (TREE_TYPE (@2)) == TYPE_PRECISION (TREE_TYPE (@3)) + && ((GIMPLE && useless_type_conversion_p (type, TREE_TYPE (@1))) + || (GENERIC && type == TREE_TYPE (@1)))) + @1)) +/* ptr0 - (ptr0 - ptr1) -> ptr1 */ +(simplify + (pointer_plus @0 (negate (convert?@2 (pointer_diff@3 @@0 @1)))) + (if (TYPE_PRECISION (TREE_TYPE (@2)) >= TYPE_PRECISION (TREE_TYPE (@3))) + (convert @1))) + /* Pattern match tem = (sizetype) ptr; tem = tem & algn; diff --git a/gcc/testsuite/gcc.dg/pr121921-1.c b/gcc/testsuite/gcc.dg/pr121921-1.c new file mode 100644 index 00000000000..b11afc819da --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr121921-1.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-cddce1" } */ + +/* PR tree-optimization/121921 */ + +int * +fx (int *b, int *e) +{ + __SIZE_TYPE__ p = b - e; + /* The first forwprop pass should optimize this to return e; */ + return b - p; +} + +/* { dg-final { scan-tree-dump "return e" "cddce1" } } */