From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 08A75385828E for ; Wed, 17 Jan 2024 13:28:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 08A75385828E 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 08A75385828E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705498087; cv=none; b=btMUyTbfnThJBKd2YN0zReXOWP3RMGHVUtbCzQQWne+xx/+YR7zkDFk6t6YbrqEcZhwFGcrFSgWxgLF2OW25utQcog8EccWFJnMSnUIywN2OPGTY094h8UQQPfM8jznpLtF6tZsvc7xZi1LA4nVem2KoQmO+8piirIowxAEBx68= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705498087; c=relaxed/simple; bh=akkrClnJHqeZkc6UOAFlmG7dScrjneDEw+in7DWsiUw=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:Message-ID:MIME-Version; b=tSoCl7aFTbpfngl9gVEfVKO8TUQBqkHAyAwnbSy/3mUJrNKoEmcCcT4b7czon4xYy2+QEMh0FB0Y801cUwbHAuiIWJItqCjB/hQHtRJsM6asIAoQj8t+mVbqIT2nJP+cRO4KicyxJEyDtSUB4a2bNSVgCCgUvlZ9IjP1Svev9Jo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.4.150] (unknown [10.168.4.150]) (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-out2.suse.de (Postfix) with ESMTPS id DBDF21FC23; Wed, 17 Jan 2024 13:28:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1705498083; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AVQWntrZ4KYy+9empRGoR4cmVwf1YERlXv6MFaRhQ0o=; b=RFLcwkgGvMt5irZ5Y5p93stBrvjGcdWI/lMG6s035RKxTal7qgvl+XJXACguu0QNgT+aP7 Lc4McUDPE1z2NpK6Ss3BxfqKo9m+YY5TAtME6NBDEP069FD7DnPCBl5g8kMbOvsZoQ0lRE EVbT3VCEewzMJWl1BAgSvFNMmRgEhGw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1705498083; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AVQWntrZ4KYy+9empRGoR4cmVwf1YERlXv6MFaRhQ0o=; b=v2RE/GN3UByhwaovzRxJFhDN6Xy18HdqgOWEWipOyt8dr7pvFHHwG1CMddWC/8tH3hpiB4 uiGoTJW0+M2lCVAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1705498082; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AVQWntrZ4KYy+9empRGoR4cmVwf1YERlXv6MFaRhQ0o=; b=t2BiY45NYEyMHsz4WIu1GTTd/inLfQPbLJV3vL9Ub8lPBASEF2fO8U2wJHiAo2O4ndaBGo NFqZKeIda0cvXgEKEXtNVvumeH6kZKhPDgUwz1jyz/O1dlQ0rUQzWgLfNWaIIyoKU6XLDX HdbC7PELCAXpCZ6zlDnf9uC9hrLWb1Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1705498082; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AVQWntrZ4KYy+9empRGoR4cmVwf1YERlXv6MFaRhQ0o=; b=0znmrbHLMCDj0/EWDijWK7k4LX/lX8lz+F/q3TqPyar7+i6TjejX8lD1U/NUyq0YSWpu7p yTygW3daFsCk75CA== Date: Wed, 17 Jan 2024 14:22:55 +0100 (CET) From: Richard Biener To: Jakub Jelinek cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] lower-bitint: Avoid overlap between destinations and sources in libgcc calls [PR113421] In-Reply-To: Message-ID: <1n613no4-6655-p625-q953-2422so65n4n1@fhfr.qr> References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [-3.10 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%] X-Spam-Level: X-Spam-Score: -3.10 X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 List-Id: On Wed, 17 Jan 2024, Jakub Jelinek wrote: > Hi! > > The following testcase is miscompiled because the bitint lowering emits a > .MULBITINT (&a, 1024, &a, 1024, &x, 1024); > call. The bug is in the overlap between the destination and source, that is > something the libgcc routines don't handle, they use the source arrays > during the entire algorithms which computes the destination array(s). > For the mapping of SSA_NAMEs to VAR_DECLs the code already supports that > correctly, but the checking whether a load from memory can be used directly > without a temporary even when earlier we decided to merge the > multiplication/division/modulo etc. with a store didn't. > > The following patch implements that. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? OK. > 2024-01-17 Jakub Jelinek > > PR tree-optimization/113421 > * gimple-lower-bitint.cc (stmt_needs_operand_addr): Adjust function > comment. > (bitint_dom_walker::before_dom_children): Add g temporary to simplify > formatting. Start at vop rather than cvop even if stmt is a store > and needs_operand_addr. > > * gcc.dg/torture/bitint-50.c: New test. > > --- gcc/gimple-lower-bitint.cc.jj 2024-01-16 12:32:56.617721208 +0100 > +++ gcc/gimple-lower-bitint.cc 2024-01-16 17:33:04.046476302 +0100 > @@ -5455,7 +5455,8 @@ vuse_eq (ao_ref *, tree vuse1, void *dat > > /* Return true if STMT uses a library function and needs to take > address of its inputs. We need to avoid bit-fields in those > - cases. */ > + cases. Similarly, we need to avoid overlap between destination > + and source limb arrays. */ > > bool > stmt_needs_operand_addr (gimple *stmt) > @@ -5574,7 +5575,8 @@ bitint_dom_walker::before_dom_children ( > else if (!bitmap_bit_p (m_loads, SSA_NAME_VERSION (s))) > continue; > > - tree rhs1 = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (s)); > + gimple *g = SSA_NAME_DEF_STMT (s); > + tree rhs1 = gimple_assign_rhs1 (g); > if (needs_operand_addr > && TREE_CODE (rhs1) == COMPONENT_REF > && DECL_BIT_FIELD_TYPE (TREE_OPERAND (rhs1, 1))) > @@ -5596,15 +5598,14 @@ bitint_dom_walker::before_dom_children ( > > ao_ref ref; > ao_ref_init (&ref, rhs1); > - tree lvop = gimple_vuse (SSA_NAME_DEF_STMT (s)); > + tree lvop = gimple_vuse (g); > unsigned limit = 64; > tree vuse = cvop; > if (vop != cvop > && is_gimple_assign (stmt) > && gimple_store_p (stmt) > - && !operand_equal_p (lhs, > - gimple_assign_rhs1 (SSA_NAME_DEF_STMT (s)), > - 0)) > + && (needs_operand_addr > + || !operand_equal_p (lhs, gimple_assign_rhs1 (g), 0))) > vuse = vop; > if (vuse != lvop > && walk_non_aliased_vuses (&ref, vuse, false, vuse_eq, > --- gcc/testsuite/gcc.dg/torture/bitint-50.c.jj 2024-01-16 17:35:16.084622119 +0100 > +++ gcc/testsuite/gcc.dg/torture/bitint-50.c 2024-01-16 17:35:06.701753879 +0100 > @@ -0,0 +1,31 @@ > +/* PR tree-optimization/113421 */ > +/* { dg-do run { target bitint } } */ > +/* { dg-options "-std=c23 -pedantic-errors" } */ > +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ > +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ > + > +#if __BITINT_MAXWIDTH__ >= 1024 > +unsigned _BitInt(1024) a = -5wb; > + > +__attribute__((noipa)) void > +foo (unsigned _BitInt(1024) x) > +{ > + a *= x; > +} > +#else > +int a = 30; > + > +void > +foo (int) > +{ > +} > +#endif > + > +int > +main () > +{ > + foo (-6wb); > + if (a != 30wb) > + __builtin_abort (); > + return 0; > +} > > Jakub > > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)