From patchwork Mon Apr 4 09:33:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 52610 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 9A1C3385843E for ; Mon, 4 Apr 2022 09:35:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A1C3385843E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1649064908; bh=VGO8hZpyOkEhxy5ZEJ9Tnh9xWKJqAGXNMQBEmhsBXiA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=w+44V+Me4f2G2XugxbjklQYL4M2kE78q8fnZz9HUcNrMA19i+VBKLBc3TVNxxxaOt Bb+Y3ZJugqRSWm/cJLbH6vqzCAhd53w/3Yh1uxV5cQp0BNUiw0CLeNjcLXJWVh3bPf vK1DP8F9cPkdR26F2DntIpjNAs9UBC1tvmhcp/gA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 0D12F3858413 for ; Mon, 4 Apr 2022 09:33:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0D12F3858413 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-out1.suse.de (Postfix) with ESMTPS id E0238210EC for ; Mon, 4 Apr 2022 09:33:51 +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 CDF3413216 for ; Mon, 4 Apr 2022 09:33:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id DdYfMX+7SmIgJgAAMHmgww (envelope-from ) for ; Mon, 04 Apr 2022 09:33:51 +0000 Date: Mon, 4 Apr 2022 11:33:51 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/105140 - fix bogus recursion in fold_convertible_p MIME-Version: 1.0 Message-Id: <20220404093351.CDF3413216@imap2.suse-dmz.suse.de> 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.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" fold_convertible_p expects an operand and a type to convert to but recurses with two vector component types. Fixed by allowing types instead of an operand as well. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 2022-04-04 Richard Biener PR middle-end/105140 * fold-const.cc (fold_convertible_p): Allow a TYPE_P arg. * gcc.dg/pr105140.c: New testcase. --- gcc/fold-const.cc | 5 +++-- gcc/testsuite/gcc.dg/pr105140.c | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr105140.c diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index b647e5305aa..fb08fa1dbc6 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -2379,12 +2379,13 @@ build_zero_vector (tree type) return build_vector_from_val (type, t); } -/* Returns true, if ARG is convertible to TYPE using a NOP_EXPR. */ +/* Returns true, if ARG, an operand or a type, is convertible to TYPE + using a NOP_EXPR. */ bool fold_convertible_p (const_tree type, const_tree arg) { - tree orig = TREE_TYPE (arg); + const_tree orig = TYPE_P (arg) ? arg : TREE_TYPE (arg); if (type == orig) return true; diff --git a/gcc/testsuite/gcc.dg/pr105140.c b/gcc/testsuite/gcc.dg/pr105140.c new file mode 100644 index 00000000000..14bff2f7f9c --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr105140.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-Os -w -Wno-psabi" } */ + +typedef char __attribute__((__vector_size__ (16 * sizeof (char)))) U; +typedef int __attribute__((__vector_size__ (16 * sizeof (int)))) V; + +void bar (); + +bar (int i, int j, int k, V v) +{ +} + +void +foo (void) +{ + bar ((V){}, (V){}, (V){}, (U){}); +}