From patchwork Tue Nov 30 14:01:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 48284 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9027C385AC20 for ; Tue, 30 Nov 2021 14:01:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9027C385AC20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638280903; bh=+Eluk6sxfxitYFXfGT74rfNXwW4E8/dOtWcjDjRzBkM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Sy4NlT+gHp6qX1QBfXIh+qExLYEYGql/U0HuOjev7hLHvl1czPCci+dkna7VyNwfw ULe8Cr2qoEPOOn+p0ju4E1jh1PGe4BfaPOZL46ulqsP/eyF0ng9dlLJZiPtyTCbEQG +wkhTFNVolMBIaEHaczhGyw8JwNlIMGigqNPQ4fI= 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 [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id A10A93858D28 for ; Tue, 30 Nov 2021 14:01:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A10A93858D28 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B914E1FD58 for ; Tue, 30 Nov 2021 14:01:12 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A538713D4E for ; Tue, 30 Nov 2021 14:01:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id L9AHJ6gupmE3KQAAMHmgww (envelope-from ) for ; Tue, 30 Nov 2021 14:01:12 +0000 Date: Tue, 30 Nov 2021 15:01:12 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/103489 - fix ICE when bool pattern recog fails Message-ID: <8124n467-s053-qr86-oqnr-957s6012s3p6@fhfr.qr> MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" bool pattern recog currently does not handle cycles correctly and when it fails we can ICE later vectorizing PHIs with mismatched bool and non-bool vector types. The following avoids blindly trusting bool pattern recog here and verifies things more thoroughly in vectorizable_phi. A bool pattern recog fix is for GCC 13. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 2021-11-30 Richard Biener PR tree-optimization/103489 * tree-vect-loop.c (vectorizable_phi): Verify argument vector type compatibility to mitigate bool pattern recog bug. * gcc.dg/torture/pr103489.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr103489.c | 12 ++++++++++++ gcc/tree-vect-loop.c | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr103489.c diff --git a/gcc/testsuite/gcc.dg/torture/pr103489.c b/gcc/testsuite/gcc.dg/torture/pr103489.c new file mode 100644 index 00000000000..cd62623ece2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr103489.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-ftree-vectorize" } */ + +_Bool a[80]; +short b, f; +void g(short h[][8][16]) +{ + for (_Bool c = 0; c < b;) + for (_Bool d = 0; d < (_Bool)f; d = 1) + for (short e = 0; e < 16; e++) + a[e] = h[b][1][e]; +} diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index 841da78f1fd..7f544ba1fd5 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -7846,6 +7846,24 @@ vectorizable_phi (vec_info *, "incompatible vector types for invariants\n"); return false; } + else if (SLP_TREE_DEF_TYPE (child) == vect_internal_def + && !useless_type_conversion_p (vectype, + SLP_TREE_VECTYPE (child))) + { + /* With bools we can have mask and non-mask precision vectors, + while pattern recog is supposed to guarantee consistency here + bugs in it can cause mismatches (PR103489 for example). + Deal with them here instead of ICEing later. */ + if (dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "incompatible vector type setup from " + "bool pattern detection\n"); + gcc_checking_assert + (VECTOR_BOOLEAN_TYPE_P (SLP_TREE_VECTYPE (child)) + != VECTOR_BOOLEAN_TYPE_P (vectype)); + return false; + } + /* For single-argument PHIs assume coalescing which means zero cost for the scalar and the vector PHIs. This avoids artificially favoring the vector path (but may pessimize it in some cases). */