From patchwork Fri Aug 30 10:33:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1978901 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=J+/RIiU7; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=VsRvv5WX; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=J+/RIiU7; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=VsRvv5WX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4WwDzX2xV2z1yfX for ; Fri, 30 Aug 2024 20:34:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 241FC385B503 for ; Fri, 30 Aug 2024 10:34:29 +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 C71D7385DDDD for ; Fri, 30 Aug 2024 10:33:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C71D7385DDDD 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 C71D7385DDDD 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=1725014043; cv=none; b=rlEZ4MUt+ckbFu9UnuswxNGLqAgd61dU6NgvpGVuuCIkAbConZMJFOncBlv1p1Qmtv1cNL7LOTLpsEXR2QaeBIIa2odH2dDjZ1mEoq6eznIE1NmTW2cAmkTloiKFcVMspE/tJ6bR0Z+qquKNBCQEoTcDEHO2eSXCQ4e/C5ziJNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725014043; c=relaxed/simple; bh=+AVT8OuFEWxRuqnkVu4h/qnOZL6ooBtvlKgQUEJa96Y=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version:Message-Id; b=lEcfoEpNxPbdeeNQJ6VupUmKJ9GCaY7hrh6h3lmET22fwB/6NREfc/ECBKngCXXk8uQXf5UIel/g3CDbbBwhV1M30tcl+w26eEcS48Ox1iWrxeDcZlFUJfLBSON0WEAZLYPcRRNmyvMO8xABMNWbzbE8bZAojjDZRW6qfOMyTcI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (unknown [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 CBDA31F7BF for ; Fri, 30 Aug 2024 10:33:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725014038; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=QchjvImP8Jtzozqu+eopZlQWOqzIEvnexrd/ePnv+qA=; b=J+/RIiU7NTKrVi7A6v1Te0pT96Lw0JYzziFwnC5dOM7gmLoBfkwUg5rL0A57+CVp69zrWW WqpQsMLrglvH1NkqEWnaSJ7LS8brU5gvCyImHjdUxvWJuO+7SD5JgfSCCohiVMZBJtqDai vW9dy2J8FoIs3CnFbhFIRqfGgn3c4oY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725014038; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=QchjvImP8Jtzozqu+eopZlQWOqzIEvnexrd/ePnv+qA=; b=VsRvv5WXiEsTluer0XMad8wAuIVcTtXPBDSP4WJcn/aq/IROxwj7TF9V3RQXXuqTeMo/By 4owkJV4n5ayYakCQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725014038; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=QchjvImP8Jtzozqu+eopZlQWOqzIEvnexrd/ePnv+qA=; b=J+/RIiU7NTKrVi7A6v1Te0pT96Lw0JYzziFwnC5dOM7gmLoBfkwUg5rL0A57+CVp69zrWW WqpQsMLrglvH1NkqEWnaSJ7LS8brU5gvCyImHjdUxvWJuO+7SD5JgfSCCohiVMZBJtqDai vW9dy2J8FoIs3CnFbhFIRqfGgn3c4oY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725014038; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=QchjvImP8Jtzozqu+eopZlQWOqzIEvnexrd/ePnv+qA=; b=VsRvv5WXiEsTluer0XMad8wAuIVcTtXPBDSP4WJcn/aq/IROxwj7TF9V3RQXXuqTeMo/By 4owkJV4n5ayYakCQ== 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 B063013A3D for ; Fri, 30 Aug 2024 10:33:58 +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 Vo5pKRag0WZfHwAAD6G6ig (envelope-from ) for ; Fri, 30 Aug 2024 10:33:58 +0000 Date: Fri, 30 Aug 2024 12:33:54 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] RISC-V: Avoid division by zero via constant_multiple_p MIME-Version: 1.0 Message-Id: <20240830103358.B063013A3D@imap1.dmz-prg2.suse.org> X-Spam-Level: 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)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; MIME_TRACE(0.00)[0:+]; MISSING_XM_UA(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; PREVIOUSLY_DELIVERED(0.00)[gcc-patches@gcc.gnu.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[tree-vect-stmts.cc:url, imap1.dmz-prg2.suse.org:helo, imap1.dmz-prg2.suse.org:mid] X-Spam-Score: -4.30 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, 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 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 With recent SLP vectorization patches I see RISC-V divison by zero for gfortran.dg/matmul_10.f90 and others in get_group_load_store_type which does && can_div_trunc_p (group_size * LOOP_VINFO_VECT_FACTOR (loop_vinfo) - gap, nunits, &tem, &remain) && (known_eq (remain, 0u) || (constant_multiple_p (nunits, remain, &num) && (vector_vector_composition_type (vectype, num, &half_vtype) != NULL_TREE)))) overrun_p = false; where for [2, 2] / [0, 2] the condition doesn't reflect what we are trying to test - that, when remain is zero or, when non-zero, nunits is a multiple of remain, we can avoid touching a gap via loading smaller pieces and vector composition. It isn't safe to change the known_eq to maybe_eq so instead require known_ne (remain, 0u) before doing constant_multiple_p. There's the corresponding code in vectorizable_load that's known to have a latent similar issue, so sync that up as well. Bootstrap and regtest running on x86_64-unknown-linux-gnu. * tree-vect-stmts.cc (get_group_load_store_type): Check known_ne (remain, 0u) before doing constant_multiple_p. (vectorizable_load): Likewise. --- gcc/tree-vect-stmts.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index f8bb637342e..d2282c0dc4f 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -2135,7 +2135,8 @@ get_group_load_store_type (vec_info *vinfo, stmt_vec_info stmt_info, * LOOP_VINFO_VECT_FACTOR (loop_vinfo) - gap, nunits, &tem, &remain) && (known_eq (remain, 0u) - || (constant_multiple_p (nunits, remain, &num) + || (known_ne (remain, 0u) + && constant_multiple_p (nunits, remain, &num) && (vector_vector_composition_type (vectype, num, &half_vtype) != NULL_TREE)))) @@ -11586,7 +11587,8 @@ vectorizable_load (vec_info *vinfo, { /* remain should now be > 0 and < nunits. */ unsigned num; - if (constant_multiple_p (nunits, remain, &num)) + if (known_ne (remain, 0u) + && constant_multiple_p (nunits, remain, &num)) { tree ptype; new_vtype