From patchwork Wed Dec 13 08:44:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 82032 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 DFA0D3860768 for ; Wed, 13 Dec 2023 08:44:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 1C3E93858D39 for ; Wed, 13 Dec 2023 08:44:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1C3E93858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1C3E93858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702457056; cv=none; b=tUBtP7+GpUoq4BcMtkfMUGKXFftop3R+eIMgUJGZvKodmb8dfIrlNPL01YX70OWTdFF/PTXlxtxzHkgcE8U4fF+I4/H+O3gWkF1IywWuJFnNhYQZh2AgL/QN3TCkMWbX0aAJGs5IAH236Y6xBhZ9VPuOslq8GcKMf9ykL/17xoE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702457056; c=relaxed/simple; bh=CdTsjf6RF/mkeO0aChT3LTKB5fpyxSO/AFJ/q/VHq+s=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=XEMjO3y+mEUIFPb3NyJNNPu5U+vELjDA02+0P4PB7Qv25raR+WDg3dmN3f27CSZaUTyCF8KSSZUNqwDRn9JCZqyjXHDCvJ1U1ydvcOBYECGFglK55B5syMPGO/MQlBnjdpFviOm8+8Sg8kd/jTDh2mmoK2wxkCV3vYQLWgyGlkc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702457054; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=Jm3dNg1JLlWvdvyzBHj3Wy6WnZ5QHOT9hml4Wq3Y2WQ=; b=Q0aHIB5D2WmL3gZS2I/+Gv9jC9FoO/10Tevf+CpYv93Mb4sq7DV4cjPF+j8N8I7e8nNitg B1AlvG+lviQ6rBe76KCqfyHod68VbVBYW7zkzJfc58IQ37S7027YB6JNlkjcCAYup+TpwS 75zbBT4jXZoVNmx29/m1f4+XaLVkaNI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-224-hTfDnv8vMKS69feIMJ7swQ-1; Wed, 13 Dec 2023 03:44:11 -0500 X-MC-Unique: hTfDnv8vMKS69feIMJ7swQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 111803816B6C; Wed, 13 Dec 2023 08:44:11 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C90F12026D66; Wed, 13 Dec 2023 08:44:10 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3BD8i8ot2489595 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 13 Dec 2023 09:44:08 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3BD8i7vo2489594; Wed, 13 Dec 2023 09:44:07 +0100 Date: Wed, 13 Dec 2023 09:44:07 +0100 From: Jakub Jelinek To: Uros Bizjak , Hongtao Liu Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] i386: Fix ICE on __builtin_ia32_pabsd128 without lhs [PR112962] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Hi! The following patch fixes ICE on the testcase in similar way to how other folded builtins are handled in ix86_gimple_fold_builtin when they don't have a lhs; these builtins are const or pure, so normally DCE would remove them later, but with -O0 that isn't guaranteed to happen, and during expansion if they are marked TREE_SIDE_EFFECTS it might still be attempted to be expanded. This removes them right away during the folding. Initially I wanted to also change all gsi_replace last args in that function to true, but Andrew pointed to PR107209, so I've kept them as is. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-12-13 Jakub Jelinek PR target/112962 * config/i386/i386.cc (ix86_gimple_fold_builtin): For shifts and abs without lhs replace with nop. * gcc.target/i386/pr112962.c: New test. Jakub --- gcc/config/i386/i386.cc.jj 2023-12-12 13:06:05.864509295 +0100 +++ gcc/config/i386/i386.cc 2023-12-13 00:02:28.543600557 +0100 @@ -19377,7 +19377,10 @@ ix86_gimple_fold_builtin (gimple_stmt_it do_shift: gcc_assert (n_args >= 2); if (!gimple_call_lhs (stmt)) - break; + { + gsi_replace (gsi, gimple_build_nop (), false); + return true; + } arg0 = gimple_call_arg (stmt, 0); arg1 = gimple_call_arg (stmt, 1); elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)); @@ -19523,7 +19526,10 @@ ix86_gimple_fold_builtin (gimple_stmt_it case IX86_BUILTIN_PABSD256_MASK: gcc_assert (n_args >= 1); if (!gimple_call_lhs (stmt)) - break; + { + gsi_replace (gsi, gimple_build_nop (), false); + return true; + } arg0 = gimple_call_arg (stmt, 0); elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)); /* For masked ABS, only optimize if the mask is all ones. */ --- gcc/testsuite/gcc.target/i386/pr112962.c.jj 2023-12-12 11:56:56.735917531 +0100 +++ gcc/testsuite/gcc.target/i386/pr112962.c 2023-12-12 11:56:39.406157222 +0100 @@ -0,0 +1,11 @@ +/* PR target/112962 */ +/* { dg-do compile } */ +/* { dg-options "-fexceptions -mssse3" } */ + +typedef int __attribute__((__vector_size__ (16))) V; + +void +foo (void) +{ + __builtin_ia32_pabsd128 ((V) {}); +}