From patchwork Tue Jan 18 09:27:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 50142 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 427203858015 for ; Tue, 18 Jan 2022 09:28:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 427203858015 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1642498118; bh=dplPEn2mtMn9f7+UqLirNVHBBW812plLF4kIVD8jjPg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=l+aXKjjP8bM/LKQXrdPiVIRAeTPL4sMphgPf83c8ZEi5LiPLXv6EzVgFt42GaLp1h RdHUHsYJTtWWaXXVLHCC4LHhNEV+ZLo/Qv7axUffD4y38CbdLgIs70m6Q/sKsYMJ5p 3wCoC1fnpucmz6bEnhRkzMaNtiOj4WthuHufyqf0= 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 8D8B03858034 for ; Tue, 18 Jan 2022 09:27:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8D8B03858034 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 7E44D1F3A1 for ; Tue, 18 Jan 2022 09:27:50 +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 6BC0E13B26 for ; Tue, 18 Jan 2022 09:27:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aX9LGRaI5mHIBwAAMHmgww (envelope-from ) for ; Tue, 18 Jan 2022 09:27:50 +0000 Date: Tue, 18 Jan 2022 10:27:50 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/104064 - UBSAN issue in vect dataref analysis Message-ID: <15o54s31-q19s-sr40-65q-97nn176ro3q5@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" Since we order DRs after DR_INIT we know the difference will be positive and thus can avoid signed overflow issues by using unsigned arithmetic to produce the known unsigned result. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 2022-01-18 Richard Biener PR tree-optimization/104064 * tree-vect-data-refs.cc (vect_analyze_data_ref_accesses): Check DR_INIT fits in a signed HWI, represent the difference from the first DR in unsigned. --- gcc/tree-vect-data-refs.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc index dd20ed974af..09223baf718 100644 --- a/gcc/tree-vect-data-refs.cc +++ b/gcc/tree-vect-data-refs.cc @@ -3172,8 +3172,8 @@ vect_analyze_data_ref_accesses (vec_info *vinfo, break; /* Check that the DR_INITs are compile-time constants. */ - if (TREE_CODE (DR_INIT (dra)) != INTEGER_CST - || TREE_CODE (DR_INIT (drb)) != INTEGER_CST) + if (!tree_fits_shwi_p (DR_INIT (dra)) + || !tree_fits_shwi_p (DR_INIT (drb))) break; /* Different .GOMP_SIMD_LANE calls still give the same lane, @@ -3203,15 +3203,18 @@ vect_analyze_data_ref_accesses (vec_info *vinfo, { /* If init_b == init_a + the size of the type * k, we have an interleaving, and DRA is accessed before DRB. */ - HOST_WIDE_INT type_size_a = tree_to_uhwi (sza); + unsigned HOST_WIDE_INT type_size_a = tree_to_uhwi (sza); if (type_size_a == 0 - || (init_b - init_a) % type_size_a != 0) + || (((unsigned HOST_WIDE_INT)init_b - init_a) + % type_size_a != 0)) break; /* If we have a store, the accesses are adjacent. This splits groups into chunks we support (we don't support vectorization of stores with gaps). */ - if (!DR_IS_READ (dra) && init_b - init_prev != type_size_a) + if (!DR_IS_READ (dra) + && (((unsigned HOST_WIDE_INT)init_b - init_prev) + != type_size_a)) break; /* If the step (if not zero or non-constant) is smaller than the @@ -3222,7 +3225,7 @@ vect_analyze_data_ref_accesses (vec_info *vinfo, unsigned HOST_WIDE_INT step = absu_hwi (tree_to_shwi (DR_STEP (dra))); if (step != 0 - && step <= (unsigned HOST_WIDE_INT)(init_b - init_a)) + && step <= ((unsigned HOST_WIDE_INT)init_b - init_a)) break; } }