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 X-Patchwork-Id: 1886306 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=DOTnasrG; 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 4TBlyp0CYMz1yPf for ; Sat, 13 Jan 2024 15:38:23 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 78E413858C66 for ; Sat, 13 Jan 2024 04:38:21 +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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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" } } */