| Message ID | r901qp50-s266-09or-092q-6874qs26pnqq@fhfr.qr |
|---|---|
| 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 vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 60DE44BB3BD5 for <patchwork@sourceware.org>; Thu, 1 Oct 2026 09:10:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 60DE44BB3BD5 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=0ufuSh2U; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=6WV5LWtX; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=NoijqGXn; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=NPl7k7XU X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id E09C74BB3BCE for <gcc-patches@gcc.gnu.org>; Thu, 1 Oct 2026 09:09:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E09C74BB3BCE Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E09C74BB3BCE Authentication-Results: sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790845777; cv=none; b=X5eVnWqhsIBJfgYP6rMcWy5GXNdeMEStGztIWiDlec2ZlEz/h1C/kWZB+5Az11qbpg0bnGRMUnkOt2w6ImHw8AjdePvfi6E2UW/ihSYBXNYSMGw+EDirUz/WBql3TItRuuSS5kCOE9vmJHFY2bTBe3UatELoQ7Zmq6ck5uDOrb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790845777; c=relaxed/simple; bh=WW2rGC7mNhGJZrDrln1vfnQV85i9zxK11/Z24mO0zlE=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:Message-ID:MIME-Version; b=fLL/lNEIq3tBmtnbC/vYcJTCEQDNNeWpMlZ/nKPFfRpkG9rG2ACHE7SYTpgdEgUbRQAxrIkBlS1OKTilK5YX39YhBB8jqcifhxn/geYpvQKxY5K9zDFhdqyiLDWO2wQhzRn1DfrLrsbD4hT9UjPwA9ArmacRCtZ9yEhk0frvaCg= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=0ufuSh2U; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=6WV5LWtX; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=NoijqGXn; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=NPl7k7XU DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E09C74BB3BCE Received: from murzim.nue2.suse.org (unknown [10.168.4.243]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AB93821E66; Thu, 1 Oct 2026 09:09:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1790845771; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=EoMMQ7QzjTmj4m94YTE7ph6iEUBPivi25IDzDnHkVgg=; b=0ufuSh2UYD26WcbgDEp6CgOa637kp6B0ZVWZttxScKhbOmXeSAhME760L+EJRi27ACxS1e VHroD5qH2E6R8SAf2SqxBbpEmX4a32yQALRNPlEccc0ud2W7yiC9E0ThjMHo16ADYSgoLh XK9ZUA0/WhSed+lcczGQOO0GikwuCoM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1790845771; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=EoMMQ7QzjTmj4m94YTE7ph6iEUBPivi25IDzDnHkVgg=; b=6WV5LWtXbCeuf/WlBS7fQP9xpnsXZJzQvvhNMahxZxjKYFb6kFPVPGGPlG09S12DZDeVaw fsN/5uqXYe4hLcCQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1790845767; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=EoMMQ7QzjTmj4m94YTE7ph6iEUBPivi25IDzDnHkVgg=; b=NoijqGXnRPKD2NsxR+eyQjhVyZM1ApjZo9pdk/uiFFi1Pkp3QQygIOXafuV1la6x4x/vxA iBjaHtO4VilRFbqX6cdnM3D34I0S65agbVjRxHRp6czAqOfz1uzU3TTmVUbshM+/L46U4Z GCpomSsfY9EyBKbG435uBtpz3zZD8Vo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1790845767; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=EoMMQ7QzjTmj4m94YTE7ph6iEUBPivi25IDzDnHkVgg=; b=NPl7k7XU3YqA4ChEggYT7mjjc8IwcUEMBDAlpRHFSZ158U4DL+D5QiydC2idYwqdur+HnR NKhU2e2taSNDwICg== Date: Thu, 1 Oct 2026 11:09:22 +0200 (CEST) From: Richard Biener <rguenther@suse.de> To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek <jakub@redhat.com> Subject: [PATCH] Fix missed constant folding of .BITREVERSE Message-ID: <r901qp50-s266-09or-092q-6874qs26pnqq@fhfr.qr> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MISSING_XM_UA(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; ARC_NA(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_SOME(0.00)[] X-Spam-Score: -4.30 X-Spam-Level: X-Spam-Status: No, score=-11.2 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 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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 |
Fix missed constant folding of .BITREVERSE
|
|
Checks
| Context | Check | Description |
|---|---|---|
| linaro-tcwg-bot/tcwg_gcc_build--master-arm | fail | Patch failed to apply |
| linaro-tcwg-bot/tcwg_simplebootstrap_build--master-arm-bootstrap | fail | Patch failed to apply |
Commit Message
Richard Biener
Oct. 1, 2026, 9:09 a.m. UTC
This fixes missed constant folding of .BITREVERSE (or other functions with _BitInt return value) which was caused due to a SCALAR_INT_MODE_P that fails on BLKmode _BitInt types. Replace this with checking the return type rather than its mode which isn't used anyway. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. OK if that passes? I didn't quite understand where you wanted extra checks - given that 'arg' is integer_cst_p its mode will surely be scalar integer if it isn't a BIT_INT_TYPE(?). Thanks, Richard. * fold-const-call.cc (fold_const_call_1): Check the return type rather than the mode for a scalar integral type before dispatching to fold_const_call_ss. * gcc.dg/tree-ssa/ssa-ccp-45.c: New testcase. --- gcc/fold-const-call.cc | 2 +- gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-45.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-45.c
Comments
On Thu, Oct 01, 2026 at 11:09:22AM +0200, Richard Biener wrote: > This fixes missed constant folding of .BITREVERSE (or other functions > with _BitInt return value) which was caused due to a SCALAR_INT_MODE_P > that fails on BLKmode _BitInt types. Replace this with checking > the return type rather than its mode which isn't used anyway. > > Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. > > OK if that passes? LGTM, though I'd change also if (integer_cst_p (arg0) && integer_cst_p (arg1)) { if (SCALAR_INT_MODE_P (mode)) in the fold_const_call_1 (combined_fn fn, tree type, tree arg0, tree arg1) function for consistency. Jakub
On Thu, 1 Oct 2026, Jakub Jelinek wrote: > On Thu, Oct 01, 2026 at 11:09:22AM +0200, Richard Biener wrote: > > This fixes missed constant folding of .BITREVERSE (or other functions > > with _BitInt return value) which was caused due to a SCALAR_INT_MODE_P > > that fails on BLKmode _BitInt types. Replace this with checking > > the return type rather than its mode which isn't used anyway. > > > > Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. > > > > OK if that passes? > > LGTM, though I'd change also > if (integer_cst_p (arg0) && integer_cst_p (arg1)) > { > if (SCALAR_INT_MODE_P (mode)) > in the > fold_const_call_1 (combined_fn fn, tree type, tree arg0, tree arg1) > function for consistency. Done and pushed as follows, bootstrapped/tested on x86_64-unknown-linux-gnu. Richard. From a821925cdf5d3f87a1417231272f8f6fa844a43b Mon Sep 17 00:00:00 2001 From: Richard Biener <rguenther@suse.de> Date: Thu, 1 Oct 2026 09:46:30 +0200 Subject: [PATCH] Fix missed constant folding of .BITREVERSE To: gcc-patches@gcc.gnu.org This fixes missed constant folding of .BITREVERSE (or other functions with _BitInt return value) which was caused due to a SCALAR_INT_MODE_P that fails on BLKmode _BitInt types. Replace this with checking the return type rather than its mode which isn't used anyway. * fold-const-call.cc (fold_const_call_1): Check the return type rather than the mode for a scalar integral type before dispatching to fold_const_call_ss and fold_const_call_sss. * gcc.dg/tree-ssa/ssa-ccp-45.c: New testcase. --- gcc/fold-const-call.cc | 4 ++-- gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-45.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-45.c diff --git a/gcc/fold-const-call.cc b/gcc/fold-const-call.cc index 94841e8fb65..c04e93ce2ee 100644 --- a/gcc/fold-const-call.cc +++ b/gcc/fold-const-call.cc @@ -1311,7 +1311,7 @@ fold_const_call_1 (combined_fn fn, tree type, tree arg) if (integer_cst_p (arg)) { - if (SCALAR_INT_MODE_P (mode)) + if (INTEGRAL_TYPE_P (type)) { wide_int result; if (fold_const_call_ss (&result, fn, wi::to_wide (arg), @@ -1762,7 +1762,7 @@ fold_const_call_1 (combined_fn fn, tree type, tree arg0, tree arg1) if (integer_cst_p (arg0) && integer_cst_p (arg1)) { - if (SCALAR_INT_MODE_P (mode)) + if (INTEGRAL_TYPE_P (type)) { wide_int result; if (fold_const_call_sss (&result, fn, wi::to_wide (arg0), diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-45.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-45.c new file mode 100644 index 00000000000..ea3c73350e7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-45.c @@ -0,0 +1,16 @@ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O -fdump-tree-ccp1" } */ + +#if __BITINT_MAXWIDTH__ >= 129 +typedef unsigned _BitInt(129) T; + +T +foo () +{ + T y = (T) 1; + T x = __builtin_bitreverseg (y); + return x; +} +#endif + +/* { dg-final { scan-tree-dump-not "BITREVERSE" "ccp1" } } */
diff --git a/gcc/fold-const-call.cc b/gcc/fold-const-call.cc index 94841e8fb65..2a8316bf406 100644 --- a/gcc/fold-const-call.cc +++ b/gcc/fold-const-call.cc @@ -1311,7 +1311,7 @@ fold_const_call_1 (combined_fn fn, tree type, tree arg) if (integer_cst_p (arg)) { - if (SCALAR_INT_MODE_P (mode)) + if (INTEGRAL_TYPE_P (type)) { wide_int result; if (fold_const_call_ss (&result, fn, wi::to_wide (arg), diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-45.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-45.c new file mode 100644 index 00000000000..ea3c73350e7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-45.c @@ -0,0 +1,16 @@ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O -fdump-tree-ccp1" } */ + +#if __BITINT_MAXWIDTH__ >= 129 +typedef unsigned _BitInt(129) T; + +T +foo () +{ + T y = (T) 1; + T x = __builtin_bitreverseg (y); + return x; +} +#endif + +/* { dg-final { scan-tree-dump-not "BITREVERSE" "ccp1" } } */