From patchwork Tue Dec 5 07:01:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 173748 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3253392vqy; Mon, 4 Dec 2023 23:01:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEymuT2/8QgD31WV5ao8oDfG8x8xh5sJhd8lbfsBbWRfvmQVe2GmdWsqLaRJ/SkNfKUsvKn X-Received: by 2002:a1f:c502:0:b0:4b2:87d3:4936 with SMTP id v2-20020a1fc502000000b004b287d34936mr3555325vkf.6.1701759699211; Mon, 04 Dec 2023 23:01:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701759699; cv=pass; d=google.com; s=arc-20160816; b=BhRmsopB4VQrtMwo9ZvjgZJ2Migou6KtAbEB2L7DBmBo8kxIKMhl+91yVqrBZB1Wu/ DzSxM3wkIQQmjGGQRgNzY538Xixo9/dLYSjkONzm+nS5Ug++iEIKajoVX8bt3fzwk3Ng KjqPerAfg9gDnRtiECsVTRwa0jCnCgzwZ5dBbshhS/NwN4qZYStwlDE6tbI6ZtqE7+if FSepUXiGz8UtREhzSvPHJtC6D+HLAdZcg7T7VbEUas9PPs9ru7Q0tN2/BYQtR2X5p+Hq 7QFLVfb4l5ny4kqJV7enU9z4Z4lLAfa29BnyPhNubtsku4kzSiAa8XXfMth0bCwPTkoS SmfA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=rdlqozA5IgcWDEQ8C4SG1tN+HybqF77YUElv2PpAgH0=; fh=dJXZiVMspIcJXx0uc9+L7YPq9u8lPiw3EGoQOJFZpWA=; b=XfgvWYxndVmWZffUCMYdvT7+h3dLooI4yBZqgUgyfwVLQUMZIiREMksmRW5h1haKPw cm2zXxzsIi2C+24UvAiOMWMt4wgioO9nxpOBvJv3Y1IWoB2JDl6g+cq8ap8/sBVWUn5B ZzIK7Txj7qeLgp0ldJms5byv2wwpNhu5svaG8owwT48moNbAK+o++pYS5HACM2IMFhww ELOxWyxOF5zVY1P6WJL3gEI79qXXYT93C7gKrtXR4qnWGv07FcgFrbyWXv7RGWs6TL8r RNLofmlZ51BtyQmyIAOWc2ixfx1PS8mK7+pd0G7T926vqx9VtBZzscWbPEUYAZ1s9bOE EXsQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FAxfAis1; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id m7-20020a05620a24c700b0077596c392f6si11352276qkn.630.2023.12.04.23.01.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 23:01:39 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FAxfAis1; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F3926385DC2D for ; Tue, 5 Dec 2023 07:01:38 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 9945D3858408 for ; Tue, 5 Dec 2023 07:01:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9945D3858408 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 9945D3858408 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701759674; cv=none; b=C3cVqtqDWQk+A2MOBFPACygGBO/XFFivnYaUx7IGJ00/NNGjWBkndt80IwbeGyv9WDcVUe+NKNPG44PMuL1PzQJyKoIp54Cf2rdFNoD0w5fofwekMFzATPeBw79IyZIg/DkYhyUEMhnyRQqBuhD/5A53uuOYbBdrH+Ms9XCmPJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701759674; c=relaxed/simple; bh=7CK0doFiUQEM8FIoDUbA0+2/eCbZCZBSn/OckuWgPXY=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=GybnZ+4RVj7GUnXhE9et39MGhIDypKdPmbKo+GTl4Py5/tQ1hD7GSnANqIsCeOeAXLkW4ZLdn6JtVgoacsNQvajcFtfiVYNm+1ZW3vqo8b+nOdQXeDerZdZTgwYwQQI96ms+cuUEShMEoLuBNcbzAUZH1RJPudhrfiUX2jeS/nU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701759672; 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=rdlqozA5IgcWDEQ8C4SG1tN+HybqF77YUElv2PpAgH0=; b=FAxfAis1EX8vsj+46Fk8w56EwaYHWirGtcG/sn4II7FKqAhEjO01N7jfSwWqAZhB+mvwHi rJ9K8fe2j8UzBFVqZBqOcX3nz6aDMa2jA/xyZOhYdaburV9jyjADXu4mHMPAkbsGBNrJLp z8+f/OFT0ZlJaCNQG/YeL7WzLQIvW+k= 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-73-hXSeUIx1O5-UxXHAXvM4HA-1; Tue, 05 Dec 2023 02:01:08 -0500 X-MC-Unique: hXSeUIx1O5-UxXHAXvM4HA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 6682B38130AB; Tue, 5 Dec 2023 07:01:08 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 13BA3C15E75; Tue, 5 Dec 2023 07:01:07 +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 3B5715KQ693810 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 5 Dec 2023 08:01:05 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3B57148N693809; Tue, 5 Dec 2023 08:01:04 +0100 Date: Tue, 5 Dec 2023 08:01:04 +0100 From: Jakub Jelinek To: Uros Bizjak , Hongtao Liu Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] i386: Improve code generation for vector __builtin_signbit (x.x[i]) ? -1 : 0 [PR112816] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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_H4, 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784424378274902697 X-GMAIL-MSGID: 1784424378274902697 Hi! On the testcase I've recently fixed I've noticed bad code generation, we emit pxor %xmm1, %xmm1 psrld $31, %xmm0 pcmpeqd %xmm1, %xmm0 pcmpeqd %xmm1, %xmm0 or vpxor %xmm1, %xmm1, %xmm1 vpsrld $31, %xmm0, %xmm0 vpcmpeqd %xmm1, %xmm0, %xmm0 vpcmpeqd %xmm1, %xmm0, %xmm2 rather than psrad $31, %xmm2 or vpsrad $31, %xmm1, %xmm2 The following patch fixes that using a combiner splitter. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-12-04 Jakub Jelinek PR target/112816 * config/i386/sse.md ((eq (eq (lshiftrt x elt_bits-1) 0) 0)): New splitter to turn psrld $31; pcmpeq; pcmpeq into psrad $31. * gcc.target/i386/pr112816.c: New test. Jakub --- gcc/config/i386/sse.md.jj 2023-12-04 09:00:12.722437462 +0100 +++ gcc/config/i386/sse.md 2023-12-04 13:22:38.565833465 +0100 @@ -16614,6 +16614,18 @@ (define_insn_and_split "*ashrv1ti3_inter DONE; }) +(define_split + [(set (match_operand:VI248_AVX2 0 "register_operand") + (eq:VI248_AVX2 + (eq:VI248_AVX2 + (lshiftrt:VI248_AVX2 + (match_operand:VI248_AVX2 1 "register_operand") + (match_operand:SI 2 "const_int_operand")) + (match_operand:VI248_AVX2 3 "const0_operand")) + (match_operand:VI248_AVX2 4 "const0_operand")))] + "INTVAL (operands[2]) == GET_MODE_PRECISION (mode) - 1" + [(set (match_dup 0) (ashiftrt:VI248_AVX2 (match_dup 1) (match_dup 2)))]) + (define_expand "rotlv1ti3" [(set (match_operand:V1TI 0 "register_operand") (rotate:V1TI --- gcc/testsuite/gcc.target/i386/pr112816.c.jj 2023-12-04 13:31:51.215061445 +0100 +++ gcc/testsuite/gcc.target/i386/pr112816.c 2023-12-04 13:34:14.008053097 +0100 @@ -0,0 +1,27 @@ +/* PR target/112816 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -mno-avx512f -masm=att" } */ +/* { dg-final { scan-assembler-times "psrad\t\\\$31," 2 } } */ +/* { dg-final { scan-assembler-not "pcmpeqd\t" } } */ + +#define N 4 +struct S { float x[N]; }; +struct T { int x[N]; }; + +__attribute__((target ("no-sse3,sse2"))) struct T +foo (struct S x) +{ + struct T res; + for (int i = 0; i < N; ++i) + res.x[i] = __builtin_signbit (x.x[i]) ? -1 : 0; + return res; +} + +__attribute__((target ("avx2"))) struct T +bar (struct S x) +{ + struct T res; + for (int i = 0; i < N; ++i) + res.x[i] = __builtin_signbit (x.x[i]) ? -1 : 0; + return res; +}