From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 5BABF3885C28 for ; Wed, 19 Jun 2024 18:44:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5BABF3885C28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5BABF3885C28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718822648; cv=none; b=YP4je6m2ughRwu6YN28vJQWOqQIO4pmaOTP2cZDoEBicULrZ6TpQ6ZrWVLeAqIFdvqQqDnLGsy1e2E1/OZO7M2B86YsFj482vb8gdbZahyYmKMyDkmGewZQhfNexOM4ZitVX+KRXCS+l4PFscnW2bvak5+AR+V9pKnyYv4ufnpU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718822648; c=relaxed/simple; bh=cXIpQf8RxBuKL0JCAMFakWSqwA9KXdUc6Pr0RtFaH0A=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=o3D9BhQeI77ndINjhNA8nP2D6Fas3scz1/YVH11wU2RynF8aCeYpQJQIfecY5AVXyi3KxVS+lko7n01KtKR/YmcNSnIK/npvtmETepw6W9WMGdpXPKGT0xv7IR+AxSshu3Eg2D/dVGltO4ZBUqaCpRwDMf6ACRb4NpTTcxNQzMI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718822646; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=JPyboc+z6nNbTfSJx/qETjK5Rx02stq7vQgy5Oe8BVc=; b=Xmqu41QoL0uWF+MCnJ5iBh4Qbjy/UtQplGfcveIE5RK0EWpex9EU+VD4K8rxnwGW4rMNpU Sjtd3NmPl3vgOYu2+t8h9/vNSb1sPkybBwJFzM8FMgwv65jGOljSo05sdtC9atvwgjlpcP 37ftpHfHEc3j1hwF/Z+fj7iikr8LfRo= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-240--Wpj-aiQNpe_0O72jnQR6g-1; Wed, 19 Jun 2024 14:44:04 -0400 X-MC-Unique: -Wpj-aiQNpe_0O72jnQR6g-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9D6E519560B1; Wed, 19 Jun 2024 18:44:02 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.7]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1134A19560AE; Wed, 19 Jun 2024 18:44:01 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 45JIhwgd3160283 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 19 Jun 2024 20:43:59 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 45JIhwwa3160282; Wed, 19 Jun 2024 20:43:58 +0200 Date: Wed, 19 Jun 2024 20:43:58 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] bitint: Fix up lowering of COMPLEX_EXPR [PR115544] Message-ID: Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi! We don't really support _Complex _BitInt(N), the only place we use bitint complex types is for the .{ADD,SUB,MUL}_OVERFLOW internal function results and COMPLEX_EXPR in the usual case should be either not present yet because the ifns weren't folded and will be lowered, or optimized into something simpler, because normally the complex bitint should be used just for extracting the 2 subparts from it. Still, with disabled optimizations it can occassionally happen that it appears in the IL and that is why there is support for lowering those, but it doesn't handle optimizing those too much, so if it uses SSA_NAME, it relies on them having a backing VAR_DECL during the lowering. This is normally achieves through the && ((is_gimple_assign (use_stmt) && (gimple_assign_rhs_code (use_stmt) != COMPLEX_EXPR)) || gimple_code (use_stmt) == GIMPLE_COND) hunk in gimple_lower_bitint, but as the following testcase shows, there is one thing I've missed, the load optimization isn't guarded by the above stuff. So, either we'd need to add support for loads to lower_complexexpr_stmt, or because they should be really rare, this patch just disables the load optimization if at least one load use is a COMPLEX_EXPR (like we do already for PHIs, calls, asm). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-06-19 Jakub Jelinek PR tree-optimization/115544 * gimple-lower-bitint.cc (gimple_lower_bitint): Disable optimizing loads used by COMPLEX_EXPR operands. * gcc.dg/bitint-107.c: New test. --- gcc/gimple-lower-bitint.cc.jj 2024-06-07 12:17:09.811966904 +0200 +++ gcc/gimple-lower-bitint.cc 2024-06-19 15:27:22.378759911 +0200 @@ -6630,7 +6630,10 @@ gimple_lower_bitint (void) continue; if (gimple_code (use_stmt) == GIMPLE_PHI || is_gimple_call (use_stmt) - || gimple_code (use_stmt) == GIMPLE_ASM) + || gimple_code (use_stmt) == GIMPLE_ASM + || (is_gimple_assign (use_stmt) + && (gimple_assign_rhs_code (use_stmt) + == COMPLEX_EXPR))) { optimizable_load = false; break; --- gcc/testsuite/gcc.dg/bitint-107.c.jj 2024-06-19 15:36:32.817747449 +0200 +++ gcc/testsuite/gcc.dg/bitint-107.c 2024-06-19 14:03:31.383805280 +0200 @@ -0,0 +1,16 @@ +/* PR tree-optimization/115544 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O -fno-tree-fre -fno-tree-ccp -fno-tree-forwprop" } */ + +#if __BITINT_MAXWIDTH__ >= 129 +typedef _BitInt(129) B; +#else +typedef _BitInt(63) B; +#endif +B a, b; + +int +foo (void) +{ + return __builtin_mul_overflow (a, 1, &b); +} Jakub