From patchwork Sat Jan 13 04:37:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Andrew Pinski (QUIC)" X-Patchwork-Id: 187869 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp594634dyc; Fri, 12 Jan 2024 20:38:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IEl5rqCOGx2k+USlYPN2QGQwBSLEflaZ+Mk9XUcX38QIKVVsKz8anN//WckCjpBqIpWWXgJ X-Received: by 2002:ac8:5c93:0:b0:429:cf75:c5e7 with SMTP id r19-20020ac85c93000000b00429cf75c5e7mr2430466qta.19.1705120720973; Fri, 12 Jan 2024 20:38:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705120720; cv=pass; d=google.com; s=arc-20160816; b=DNjIhihpjUWKT+G2ykL/eqgwr5oXx5mlwvS4Ce9y4ZKl6i+cu67DxOQsjJtjSRm5N7 CHlj1k8cLssjqPEIzw31iqFT+NSzTEn9J9TS8XHNdlbGTxaCqYXP+pM6Mv65IEd+uoik 23ghKLBLVoH66uOBJeqZK/loZlinK+Fvz4Wh2yA90gMURGi1j3/8KWLcizV6GWjgpPpe b1N/Kx9EVRN/LcN4UfjrAuoGUccNXWHxTAH8h4DkJMZXPNE47zh1rGKxZUeDqI4Q2p/S FDVhV+pg9cPSAb8a0AiO8TnMIrpcnxUS+vrwQAfniuCvKoWc753dlEH9U1Q3TEYP1ViW 3fUw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=VG3E3hhITFqMtxCuDY1P/gxGRYxQU3mYrdeLT0c3Zlw=; fh=o3CEdS3yGN/eIa89Zn0Kf01WYLxTE9IjKuSQGVPeOHI=; b=JY7JZklku68qFOK3imHGLaMOFybK5t8Ons5mJd4ljPtP1DTd16Q9vsn6Xm9QDd40O2 A4CI7yvqxLEZKq+vvskx1LjE4QZgSEp4ci0ld4NKz1ZowQX8ZguITgztJhULPKu/VOzB FfbnKkYI5vaPWX368abO+XUUyHq9WuM1CAnWDpoHc5qsCsTzRzR1owHsp8VWWORZ0EzY pi+LUOIpBfJdxA9W+y7TlgBjAENltoQRKePbYWUuPlrWiigXr6h3wndMOCwZ5iUOs24g AaWIldkF3qRdNUUOdR63q9Oge6diSv8CauZ36R7Fb1eh2KPiAIIPgMxXRvY3nVk1x4Ro H3Ag== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=DOTnasrG; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id m15-20020a05622a118f00b00429c963068fsi3549729qtk.627.2024.01.12.20.38.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 20:38:40 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=DOTnasrG; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AEFCB3858403 for ; Sat, 13 Jan 2024 04:38:40 +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 411D53858D20 for ; Sat, 13 Jan 2024 04:38:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 411D53858D20 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 411D53858D20 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=1705120683; cv=none; b=e0jaZ0JqgDF+x70p+x1RKQMdZUICpJnM4tYcAELflpsfAn+ZeRzpWdVO/cPK8R1h4Xh3tbnFxOuLoxsBi5eg220n0QQMKw1HAWlVOtyl1xuzbod0KKDy6SKqLSKCXYkh3GcqwJWyb9psphLI152z/zW8JR3cES7cPk+BH7DHrrI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705120683; c=relaxed/simple; bh=1/NtK3ocQa9apf1VMAn/jMtX8sh6aIa4Z/yOVmE/SwU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XbeJwr58ZlFV1NH9qINMVPjKNSOPGIqdiZGwmuqZPzGhAhfkQ8k2K1RHLJ6pieIUMky+gBJh4Gjr0kYOcswPFwRMx9phTt7VwzGAWxjOBKwSK6lM6FrK33WVwwVdos/+HatzlunmTOCmKheNK+NvOY6pCUiKfzwVsvSfKZ7HbK8= 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.17.1.24/8.17.1.24) with ESMTP id 40D4TZPE002073 for ; Sat, 13 Jan 2024 04:37:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-type; s=qcppdkim1; bh=VG3E3hh ITFqMtxCuDY1P/gxGRYxQU3mYrdeLT0c3Zlw=; b=DOTnasrGlhfidNHhbcEJ+32 l4ndHWs15+oMfu6uFhTsyWI5dJMSQZubjBmubffxDIWeThoZ4EF6qr3gXg2xqTwm Xo6793vibBDQLL8es9pf+L5uaKWq7YMXyFeLwFfzSTp0quQwJA47Dhjd+4e12ojB rJjoaQgzx1ITbufb1P97R7DTg7Rx/2D04keMbv3nLh9pxIeKYjvMvVFO1D/axbY0 6efXnR6GywLXTeNOz1/qmZojudn1/BImGjXIOFZykHSTNQrzk24UY7IMuz84d/to bzQU71JwmSbMFBBetoFPxv7S2I0cbyJQwrSogSDu+nvoQsZpwL/19SNnDR3zgEg= = Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vkjr7028s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 13 Jan 2024 04:37:59 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 40D4bwAH013718 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 13 Jan 2024 04:37:58 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.1118.40; Fri, 12 Jan 2024 20:37:58 -0800 From: Andrew Pinski To: CC: Andrew Pinski Subject: [COMMITTED] Add a few testcases for fix missed optimization regressions Date: Fri, 12 Jan 2024 20:37:06 -0800 Message-ID: <20240113043706.2216775-1-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) 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-ORIG-GUID: p4VGwxRK50f4p5fEXq8dahu1p7AD5-iq X-Proofpoint-GUID: p4VGwxRK50f4p5fEXq8dahu1p7AD5-iq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_01,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 suspectscore=0 spamscore=0 adultscore=0 lowpriorityscore=0 clxscore=1015 phishscore=0 impostorscore=0 priorityscore=1501 mlxscore=0 malwarescore=0 mlxlogscore=848 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401130035 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787948665292558302 X-GMAIL-MSGID: 1787948665292558302 Adds a few new testcases for some missed optimization regressions. The analysis on how each should be optimized is in the testcases themselves (and in the bug report). Committed as obvious after running the testsuite to make sure they pass. PR tree-optimization/107823 PR tree-optimization/110768 PR tree-optimization/110941 PR tree-optimization/110450 PR tree-optimization/110841 gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/ssa-thread-22.c: New test. * gcc.dg/tree-ssa/vrp-loop-1.c: New test. * gcc.dg/tree-ssa/vrp-loop-2.c: New test. * gcc.dg/tree-ssa/vrp-unreachable-1.c: New test. * gcc.dg/tree-ssa/vrp-unreachable-2.c: New test. Signed-off-by: Andrew Pinski --- gcc/testsuite/gcc.dg/tree-ssa/ssa-thread-22.c | 23 +++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-1.c | 34 +++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-2.c | 33 ++++++++++++++++++ .../gcc.dg/tree-ssa/vrp-unreachable-1.c | 26 ++++++++++++++ .../gcc.dg/tree-ssa/vrp-unreachable-2.c | 29 ++++++++++++++++ 5 files changed, 145 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-thread-22.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-2.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vrp-unreachable-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vrp-unreachable-2.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-thread-22.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-thread-22.c new file mode 100644 index 00000000000..f605009d8b5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-thread-22.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-Os -fdump-tree-optimized" } */ +/* PR tree-optimization/107823 */ +/* With jump threading across the loop header, + we should figure out that b is always 0 and remove + the call to foo. */ + +int a; +void bar64_(void); +void foo(); +int main() { + signed char b = a = 6; + for (; a; a = 0) { + bar64_(); + b = 0; + } + if (b <= 0) + ; + else + foo(); +} + +/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-1.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-1.c new file mode 100644 index 00000000000..09de8924308 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-1.c @@ -0,0 +1,34 @@ +/* { dg-do compile } */ +/* { dg-options "-Os -fdump-tree-optimized" } */ +/* PR tree-optimization/110768 */ +/* The call to foo should be able to removed, + The branch to unreachable is unreachable as + VRP (ranger) figure out that c there can only + be -20409 or 0. before r14-5109-ga291237b628f41 + ranger could not figure that out. */ + + +void foo(void); +static int a, b; +int main() { + { + short c = 45127; + signed char d; + b = 0; + for (; b <= 3; b++) { + if (b) continue; + d = 0; + for (; d <= 100; d++) { + if (!(((c) >= -20409) && ((c) <= 1))) { + __builtin_unreachable(); + } + if (~(0 == a) & 1) return b; + c = 0; + for (; c <= 0; c++) a = 3; + } + } + foo(); + } +} + +/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-2.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-2.c new file mode 100644 index 00000000000..7438c55aaef --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-2.c @@ -0,0 +1,33 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-tree-optimized" } */ +/* PR tree-optimization/110941 */ +/* The call to foo should be able to removed, + VRP should figure out `(c >= 2 && c <= 26)` + is always true. */ + +static int a; +void foo(void); +void bar349_(void); +void bar363_(void); +void bar275_(void); +int main() { + { + { + short b = 26; + for (; b >= 1; b = b - 4) { + if (b >= 2 && b <= 26) + bar275_(); + if (a) + bar363_(); + if (a) + bar349_(); + int c = b; + if (!(c >= 2 && c <= 26)) + foo(); + } + } + a = 0; + } +} + +/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-unreachable-1.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp-unreachable-1.c new file mode 100644 index 00000000000..76ef5017577 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-unreachable-1.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* PR tree-optimization/110450 */ +/* the ranger should be able to figure out that based on the + unreachable part of d not being zero, *b is also never 0. +*/ + + +void foo(void); +static int a = 1; +static int *b = &a, *c = &a; +static short d, e; +static signed char f = 11; +static signed char(g)(signed char h, int i) { return h << i; } +int main() { + if (f) *c = g(0 >= a, 3); + e = *c; + d = e % f; + if (d) { + __builtin_unreachable(); + } else if (*b) + foo(); + ; +} + +/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-unreachable-2.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp-unreachable-2.c new file mode 100644 index 00000000000..44b1ba5c687 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-unreachable-2.c @@ -0,0 +1,29 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* PR tree-optimization/110841 */ +/* The call to foo should be able to removed */ + +void foo(void); +static int b, c, d; +static signed char(a)(signed char e, signed char f) { return e - f; } +int main() { + for (; b <= 4; b++) + ; + c = 0; + for (; c >= -16; c = a(c, 4)) + ; + signed char g = b; + for (; d <= 0; d++) { + if (!(((g) >= 5) && ((g) <= 5))) { + __builtin_unreachable(); + } + if (c) return 0; + g = 0; + for (;;) { + foo(); + break; + } + } +} + +/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */