From patchwork Sun Jun 23 12:55:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1951212 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.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=rMo11ev4; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=WrXxZh8f; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=rMo11ev4; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=WrXxZh8f; 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 4W6WL35cjqz20X6 for ; Sun, 23 Jun 2024 22:55:54 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 74437385E839 for ; Sun, 23 Jun 2024 12:55:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id 78C2B385DDF1 for ; Sun, 23 Jun 2024 12:55:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 78C2B385DDF1 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 78C2B385DDF1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719147333; cv=none; b=MsBANJWOYGcJYjh1JQDKKEhnQw8eZ7knQTePxRCLuSeGKA8KRSvLD89/geN415ie3BXEi1KaUVSJV2HMZy16LCKH1uxQMnWlk9iUpiNrHKGcdaQ7BI7wWRxi3H8YpADFDNAg4Yhb7U87u+g8p3tMOiF6w6zODuQh/y1YbUporm4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719147333; c=relaxed/simple; bh=cahjpMiYO7wZeozSer456Z1i2L3fa6JsQXPrnEAT7+Q=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version:Message-Id; b=A0WGk1zU40rf+IMQRt3SwEPjuRnOqhaAV/oZ8Bp0nYR7Lep1wfz3TT49vPm3CnUKBfNIbhHxtWUbG+vk5ZufaYl1TTFMGzICLG9mqhjXHFlEenk11f2p+VYrRCeo1AUzrcmzUpumTMFbiRXP3Shu/ACQTNqXM6FICJZoLQPHhhw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (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 B16441F458 for ; Sun, 23 Jun 2024 12:55:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1719147329; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=2d8Q8sPV87Dc0q2EWEtTbemEJUz2zP3cAu94nMTFynw=; b=rMo11ev4QUjxP2yjNfs+Ccsn8tVKezpKzy0+ZTUbcCLciDFPOljY2BptO2YWxPiXH586is B5r9t1mK7zcPWpOAm/ZhpXwrQtNG0xPDeUOFzerfaYckXVaczBCtgPexcsfZBBk++glcPG 3mh51Z3zjOabSdPeRTwNjDXuIKnbBPQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1719147329; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=2d8Q8sPV87Dc0q2EWEtTbemEJUz2zP3cAu94nMTFynw=; b=WrXxZh8fUJqG/NYh5PYPKMaO1mISwZdpbUPU/0db281DuZePZBDyqLfWbGQzd8SiZ4loM2 wBct/ZpxaaaWLsCg== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=rMo11ev4; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=WrXxZh8f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1719147329; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=2d8Q8sPV87Dc0q2EWEtTbemEJUz2zP3cAu94nMTFynw=; b=rMo11ev4QUjxP2yjNfs+Ccsn8tVKezpKzy0+ZTUbcCLciDFPOljY2BptO2YWxPiXH586is B5r9t1mK7zcPWpOAm/ZhpXwrQtNG0xPDeUOFzerfaYckXVaczBCtgPexcsfZBBk++glcPG 3mh51Z3zjOabSdPeRTwNjDXuIKnbBPQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1719147329; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=2d8Q8sPV87Dc0q2EWEtTbemEJUz2zP3cAu94nMTFynw=; b=WrXxZh8fUJqG/NYh5PYPKMaO1mISwZdpbUPU/0db281DuZePZBDyqLfWbGQzd8SiZ4loM2 wBct/ZpxaaaWLsCg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 959571398F for ; Sun, 23 Jun 2024 12:55:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 12aMIkEbeGZkYAAAD6G6ig (envelope-from ) for ; Sun, 23 Jun 2024 12:55:29 +0000 Date: Sun, 23 Jun 2024 14:55:29 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/115599 - reassoc qsort comparator issue MIME-Version: 1.0 Message-Id: <20240623125529.959571398F@imap1.dmz-prg2.suse.org> X-Spamd-Result: default: False [-6.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; DWL_DNSWL_MED(-2.00)[suse.de:dkim]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_TLS_ALL(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; MISSING_XM_UA(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:106:10:150:64:167:received]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gcc-patches@gcc.gnu.org]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: B16441F458 X-Spam-Score: -6.51 X-Spam-Level: X-Spam-Status: No, score=-11.7 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 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 The compare_repeat_factors comparator fails qsort checking eventually because it uses rf2->rank - rf1->rank to compare unsigned numbers which causes issues for ranks that interpret negative as signed. Fixed by re-writing the obvious way. I've also fixed the count comparison which suffers from truncation as count is 64bit signed while the comparator result is 32bit int (that's a lot less likely to hit in practice though). The testcase from the PR is too large to include. Bootstrap and regtest running on x86_64-unknown-linux-gnu. PR tree-optimization/115599 * tree-ssa-reassoc.cc (compare_repeat_factors): Use explicit compares to avoid truncations. --- gcc/tree-ssa-reassoc.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gcc/tree-ssa-reassoc.cc b/gcc/tree-ssa-reassoc.cc index 4d9f5216d4c..d74352268b5 100644 --- a/gcc/tree-ssa-reassoc.cc +++ b/gcc/tree-ssa-reassoc.cc @@ -6414,10 +6414,17 @@ compare_repeat_factors (const void *x1, const void *x2) const repeat_factor *rf1 = (const repeat_factor *) x1; const repeat_factor *rf2 = (const repeat_factor *) x2; - if (rf1->count != rf2->count) - return rf1->count - rf2->count; + if (rf1->count < rf2->count) + return -1; + else if (rf1->count > rf2->count) + return 1; + + if (rf1->rank < rf2->rank) + return 1; + else if (rf1->rank > rf2->rank) + return -1; - return rf2->rank - rf1->rank; + return 0; } /* Look for repeated operands in OPS in the multiply tree rooted at