From patchwork Wed Sep 2 12:07:46 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 2296605 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=quesejoda.com header.i=@quesejoda.com header.a=rsa-sha256 header.s=dreamhost header.b=MnXqW8W3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (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 4hZhNf3Sdvz1xwg for ; Wed, 02 Sep 2026 22:09:22 +1000 (AEST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 56A644BA23EB for ; Wed, 2 Sep 2026 12:09:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56A644BA23EB Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=quesejoda.com header.i=@quesejoda.com header.a=rsa-sha256 header.s=dreamhost header.b=MnXqW8W3 X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from cow.ash.relay.mailchannels.net (cow.ash.relay.mailchannels.net [23.83.222.41]) by sourceware.org (Postfix) with ESMTPS id 8D5FA4BA23EB for ; Wed, 2 Sep 2026 12:08:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8D5FA4BA23EB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=quesejoda.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=quesejoda.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8D5FA4BA23EB Authentication-Results: sourceware.org; arc=none smtp.remote-ip=23.83.222.41 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788350905; cv=none; b=ESJPrmIZ1VSjkrCbukLLJ3BNTuMbBYNyhJkZwnn7hr3SinX77IHuH0rjVS+kqx+IqC0Qm4Y/VIso8Np7QNZp74cpGvvptV0H5KOjvUF2255BIAGpoL16GVXHloDlXuf45QMO+fFeNp09V6VDct7cNIJTP4ybG3Oa11Q/qVXxSgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788350905; c=relaxed/simple; bh=AFjtfKAK/IYo1j25GiCNaD0KJO6ikx2Ek0Asb8zdRjQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=daTBAHj9e5MYKmS+oODcCh06nzqaOo1aiR2SN6TLUkeeA7etPyPdoYBAw/WF+TCwSKZJHSyTS0CaW+pzVUL14zQPa54EZ2hDncxerOv0uwZoO9znewpcneSU20qb6MZn9FLPwtFPms2iWdEIusm/FSejmx6JyhcrcRmlpDLZxbQ= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=quesejoda.com header.i=@quesejoda.com header.a=rsa-sha256 header.s=dreamhost header.b=MnXqW8W3 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D5FA4BA23EB X-Sender-Id: dreamhost|x-authsender|aldy@quesejoda.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 700E73825AB; Wed, 02 Sep 2026 12:08:22 +0000 (UTC) Received: from pdx1-sub0-mail-a210.dreamhost.com (trex-green-3.trex.outbound.svc.cluster.local [100.97.107.227]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id D432C382137; Wed, 02 Sep 2026 12:08:16 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|aldy@quesejoda.com X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|aldy@quesejoda.com X-MailChannels-Auth-Id: dreamhost X-White-Tank: 357a556f4e487d3a_1788350901050_2598973399 X-MC-Loop-Signature: 1788350901050:559681360 X-MC-Ingress-Time: 1788350901050 Received: from pdx1-sub0-mail-a210.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.97.107.227 (trex/8.0.2); Wed, 02 Sep 2026 12:08:21 +0000 Received: from cfarm136.osuosl.org (cfarm136.osuosl.org [140.211.9.184]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: aldy@quesejoda.com) by pdx1-sub0-mail-a210.dreamhost.com (Postfix) with ESMTPSA id 4hZhMN4fR3zTJ; Wed, 2 Sep 2026 05:08:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quesejoda.com; s=dreamhost; t=1788350896; bh=olXwLxl9AwH9d+FTjuNQFOWX1FWbI1IpUeN/VGY/B8k=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=MnXqW8W3sDPzNbf1mmgRo8CNSnIIyxteZurIB0Of3fDbo+o5dEtuNlQcANCuueCJh pjNuka+IgoULBnp3NhJYlsDqQxMdk3y1c/RGfiPpTDLzK+h7UwoDCfakv79a4Oj//+ Qehvks6OkbC7rPTGjglDR8+oTEjpBl9ilwXnLqz+zZwUtTwrt75rGfL3GvBema/ZG3 RxGG71pa3uW7LDREO7JW61gIzoAMPUbgviVUZrCEEILZPMV6mQuYnRmfQepkPMOnNg 4LQk+qfJDJSfkTbD24KZDQCnFrJkCN1Qk2ujI8SUfVbS/I/fmHtPdUJDIWPQZ7Yii2 vs8zAHmQfpGpA== From: Aldy Hernandez To: gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, Aldy Hernandez Subject: [PATCH 1/2] Add testcases for backward threading to never-executed edges [PR106495] Date: Wed, 2 Sep 2026 12:07:46 +0000 Message-ID: <20260902120747.2705241-2-aldy@quesejoda.com> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 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 r13-1924-gb9da686470d1c2 avoided threading to probably never executed edges but landed without a testcase. Add two, retroactively. [This is all AI generated. I used it to to go back in time, create testcases from the original preprocessed source code, further reduce it with cvise, and then distill it further to create a minimal reproducer for the concept, not the warning. This allows us to keep an reduction of the original testcase, plus a conceptual tiny testcase to make sure we don't regress going forward.] Both FAIL before r13-1924 and PASS with it. Assisted-by: Claude Fable 5 (Anthropic) OK? gcc/testsuite/ChangeLog: PR tree-optimization/106495 PR tree-optimization/126906 * gcc.dg/tree-ssa/pr106495-1.c: New test. * gcc.dg/tree-ssa/pr106495-2.c: New test. --- gcc/testsuite/gcc.dg/tree-ssa/pr106495-1.c | 76 ++++++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr106495-2.c | 27 ++++++++ 2 files changed, 103 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr106495-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr106495-2.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr106495-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr106495-1.c new file mode 100644 index 00000000000..1cd6258540c --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr106495-1.c @@ -0,0 +1,76 @@ +/* PR tree-optimization/106495 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Warray-bounds -fdump-tree-threadfull1-details" } */ + +/* Reduced from PR106495 (attachment 53396, comment #6): the i686 bootstrap + broke with -Werror=array-bounds. The calls to the cold noreturn fancy_abort + clobber memory, so m_vec is reloaded for each access; the backward threader + can then resolve the m_vec == NULL path, where vec_length () is 0 and the + index wraps to 4294967294, and isolate it even though it ends in a probably + never executed edge. Nothing real ever executes the path, but the + materialized dead statements drew a bogus -Warray-bounds warning (ilp32 + only; the threadfull1 scan below discriminates on all targets). + + The PR106495 fix)rejects such paths in profitable_path_p: this test FAILs + before that commit and PASSes with it. cvise-reduced from the original .ii + file, and then the AI converted the C++ vec templates to plain C. See + pr106495-2.c for a minimal distillation. */ + +void fancy_abort (const char *, int, const char *) + __attribute__ ((noreturn)) __attribute__ ((cold)); + +typedef int *basic_block; + +unsigned m_num; + +struct vec_embed +{ + int m_pad; + basic_block m_vecdata[]; +}; + +struct vec +{ + struct vec_embed *m_vec; +}; + +static inline unsigned +embed_length (struct vec_embed *v) +{ + return m_num; +} + +static inline basic_block +embed_index (struct vec_embed *v, unsigned ix) +{ + if (!(ix < m_num)) + fancy_abort ("", 9, __FUNCTION__); + return v->m_vecdata[ix]; /* { dg-bogus "above array bounds" } */ +} + +static inline unsigned +vec_length (struct vec *v) +{ + return v->m_vec ? embed_length (v->m_vec) : 0; +} + +static inline basic_block +vec_index (struct vec *v, unsigned ix) +{ + return embed_index (v->m_vec, ix); +} + +void find_edge (basic_block, basic_block); + +struct vec m_path; + +void +profitable_path_p (void) +{ + int len1 = vec_length (&m_path); + unsigned len2 = vec_length (&m_path); + basic_block bb = vec_index (&m_path, len1 - 2); + find_edge (vec_index (&m_path, len2 - 1), bb); +} + +/* { dg-final { scan-tree-dump "path leads to probably never executed edge" "threadfull1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr106495-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr106495-2.c new file mode 100644 index 00000000000..02e7b821de7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr106495-2.c @@ -0,0 +1,27 @@ +/* PR tree-optimization/106495 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdisable-tree-ethread -fdump-tree-threadfull1-details" } */ + +/* Minimal distillation of pr106495-1.c, pinning the never-executed + taken-edge veto (PR105679, PR106495): a resolvable thread whose + taken edge is probably never executed and whose destination holds + real code (a call to abort, not just __builtin_unreachable) must + not be threaded, lest we isolate never-executed paths that the + late diagnostic passes then warn about. Without the r13-1924 veto + the 3->4 path threads straight into the abort block. + -fdisable-tree-ethread keeps the early threader from resolving the + path before profile estimation makes the edge cold. */ + +void abort (void); +int g; + +void +f (int x) +{ + if (x < 0) + g = 1; + if (x < 0) + abort (); +} + +/* { dg-final { scan-tree-dump "path leads to probably never executed edge" "threadfull1" } } */ From patchwork Wed Sep 2 12:07:48 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 2296608 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=quesejoda.com header.i=@quesejoda.com header.a=rsa-sha256 header.s=dreamhost header.b=g28F5Wx1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=38.145.34.32; helo=vm01.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 4hZhR32jh5z1xwZ for ; Wed, 02 Sep 2026 22:11:27 +1000 (AEST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F05424BA23E4 for ; Wed, 2 Sep 2026 12:11:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F05424BA23E4 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=quesejoda.com header.i=@quesejoda.com header.a=rsa-sha256 header.s=dreamhost header.b=g28F5Wx1 X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from slateblue.cherry.relay.mailchannels.net (slateblue.cherry.relay.mailchannels.net [23.83.223.168]) by sourceware.org (Postfix) with ESMTPS id 341C34BA2E20 for ; Wed, 2 Sep 2026 12:08:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 341C34BA2E20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=quesejoda.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=quesejoda.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 341C34BA2E20 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=23.83.223.168 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788350922; cv=none; b=uzwmWu/4ui3/GeX2iqNTifY+d5i0uteWp/s7fUm3C9yobuLlMw0HncEUCYqwSVHxFTxs+H1eS0pwK/iV2HCgdrm7XC6nUCB3HWYs7omTwj7//XqWqJqGmp7GnVGexKZbc4VlF3N30grkefVcmE74GVXwkoIbhYztgwOMvKQWFSI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788350922; c=relaxed/simple; bh=KEunBs2HVo1YzY2pO+6UIVAvEuVq3KF7my2vjXTS9Is=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=uy3a4/MCecujLadhCa5X/OEcM0Cghv91zhue4AfPYeIvIOEUh6/FJOfdG/51l7LuPHLys0OS0yXYN9fV/UOdyse8UHzXkkzIjAWmg5IhuAmQWZjemFdvj81mD/M8wTjDAK3oqY4XEEuJOOE4o/x/DFrPu1HRTvNGhBTnzBTvx+w= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=quesejoda.com header.i=@quesejoda.com header.a=rsa-sha256 header.s=dreamhost header.b=g28F5Wx1 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 341C34BA2E20 X-Sender-Id: dreamhost|x-authsender|aldy@quesejoda.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id A5965162485; Wed, 02 Sep 2026 12:08:35 +0000 (UTC) Received: from pdx1-sub0-mail-a210.dreamhost.com (trex-green-6.trex.outbound.svc.cluster.local [100.97.108.66]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 857611627C2; Wed, 02 Sep 2026 12:08:35 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|aldy@quesejoda.com X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|aldy@quesejoda.com X-MailChannels-Auth-Id: dreamhost X-Left-Continue: 52bed503636cdcb5_1788350915593_3121622253 X-MC-Loop-Signature: 1788350915593:2643718813 X-MC-Ingress-Time: 1788350915592 Received: from pdx1-sub0-mail-a210.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.97.108.66 (trex/8.0.2); Wed, 02 Sep 2026 12:08:35 +0000 Received: from cfarm136.osuosl.org (cfarm136.osuosl.org [140.211.9.184]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: aldy@quesejoda.com) by pdx1-sub0-mail-a210.dreamhost.com (Postfix) with ESMTPSA id 4hZhMl2JxdzNH; Wed, 2 Sep 2026 05:08:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quesejoda.com; s=dreamhost; t=1788350915; bh=Pgghg+0TNEJhH74fMgHPZh5lxxWYpYkn5ktAsGxAw20=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=g28F5Wx1J+j1YrdbEjIOof7f7paQS6HPax5F9EOr1Vaodgm/O1OSXiVzINA0xcQFE 4LoyQW5I7P7RHX+pwHPdjKUF7tfvyS5MAjgoyEdIYp8Cpsy3eeRZRc/iwRI6pToGo6 IRbtawU34H3WNrg5jYoK8dHB/bI86Vq70wG0oVYaaTvYFXGVC22e+hPoN0uoZxJdmy bH83eo7MMLFCOuVtI3T6G0IbCrMvtKFGwwfXn1gVvVwGBFWf6ejgAFfnlrqrVrC8jg tB2+IR/DYZ2LzLjdRD20HUr90wvDXB2ip5gQbgIuvtHdTbCgqcTNXXKfM5Hp/2GUnC n3MpXQ4NyOu9Q== From: Aldy Hernandez To: gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, Aldy Hernandez Subject: [PATCH 2/2] Add testcase for backward threading from never-executed entry edges [PR105679] Date: Wed, 2 Sep 2026 12:07:48 +0000 Message-ID: <20260902120747.2705241-4-aldy@quesejoda.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260902120747.2705241-2-aldy@quesejoda.com> References: <20260902120747.2705241-2-aldy@quesejoda.com> MIME-Version: 1.0 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 r13-1891-g49ba4fdeb648c1 made the backward threader reject paths whose entry edge is probably never executed, but landed without a testcase. Add one retroactively. [Also AI generated.] Assisted-by: Claude Fable 5 (Anthropic) OK? gcc/testsuite/ChangeLog: PR tree-optimization/105679 PR tree-optimization/126906 * gcc.dg/tree-ssa/pr105679.c: New test. --- gcc/testsuite/gcc.dg/tree-ssa/pr105679.c | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr105679.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr105679.c b/gcc/testsuite/gcc.dg/tree-ssa/pr105679.c new file mode 100644 index 00000000000..5f7b6cf0d1d --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr105679.c @@ -0,0 +1,33 @@ +/* PR tree-optimization/105679 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Warray-bounds -fno-strict-overflow -fsanitize=shift -fsanitize-coverage=trace-pc -fdump-tree-threadfull1-details" } */ + +/* Reduced with cvise from attachment 53010: the Linux kernel hit spurious + -Warray-bounds warnings with -fsanitize=shift. The sanitizer's + shift-out-of-bounds check for 1 << irq gives the irq > 31 branch a precise + never-executed count; the backward threader nevertheless used that block as + a thread entry, isolating a never-executed path on which irq > 31 indexes + the 2-element array and drawing the bogus warning. The bare shift statement + only exists to feed the sanitizer. + + r13-1891 (the PR105679 fix) rejects paths whose entry edge is probably never + executed. This test FAILs before that commit and PASSes with it. */ + +struct many_objects +{ + int array[2]; +} instance; + +int entry; + +int +work (unsigned int irq) +{ + 1 << irq; + entry = instance.array[irq]; /* { dg-bogus "above array bounds" } */ + if (irq) + return 0; + return 1; +} + +/* { dg-final { scan-tree-dump "path entry is probably never executed" "threadfull1" } } */