From patchwork Thu Nov 16 07:01:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 165712 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp3031308vqg; Wed, 15 Nov 2023 23:02:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFIh7h6cB/1uLdPDKJugiAGsKM7feMi7OaJWlDAOMjbplrUHbqIYQtO9rZkrh1Kh/mj+rSA X-Received: by 2002:a05:6870:44f:b0:1f4:d208:ab4e with SMTP id i15-20020a056870044f00b001f4d208ab4emr18165812oak.39.1700118119733; Wed, 15 Nov 2023 23:01:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700118119; cv=pass; d=google.com; s=arc-20160816; b=aEzrkX66OmKRepbrNdkwWknPAPDzhD5SVdaNqGCcpvUDEmTc4HnSV6IHeM/vIE7L+h OWydq1O/hK+MZmB6LjdXax91Ue/k8+VFvxmzjyjTK058cyGhj4ik/HCy/3LUkWJHjMBo LeZn36c7A6bJuJPSCqKu/U9VZEk8LUSo0TLZ6VrExzIZG68oRSb/zOL+Hnux64tmmKeC KCp1RBJlZ25kQcM7fjHigWEVu13zWxHlPZjNaxOefiSLthNKz1g/Hty7Vwnzg95u2Zcg HwtcvMf+dtI8/Bo1ICW4gM3DgIaLzM74ve2/zDk0psQjnGOc540iJHg1CUMnz1RskSR9 v/Eg== 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=Cx91pxEAmgy5IGS9AC6HHeItcOqg/xuPwx/zoCwkm5M=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=HK+IqMywkYmW1wrkg3bwOph3ZgTThZ/vtdgDOSYbKuoYz4OUlqPgdU6of/GRjgCfnS qnMYHVljWkc0q3d2iKFeYRP4MBCoh21cWIpcBo+YoB22iGIDZRZH4+1jtd6Adx978apI QRi19KiD6OZxSNyCfG4wC/eihGdIPR3/Z8I9rbzIK7ITXHan68MX5skCTVo9MeX31Os4 QsMwtXrsQxsnOa88m97oZbjL0isVBysvzjIsyVIqfsBl1/e5oD46+cK4x8wftMhmK9be tZLrEJZuwRlKcJC1ODn0VG7T+hak49uiaRnC2pj+sBjRHmQQ/pDGU/XK7ZAI0kVLPEw2 f+bA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PFhj+Txq; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u28-20020a05622a199c00b00417ae509fa2si10087797qtc.317.2023.11.15.23.01.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 23:01:59 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PFhj+Txq; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 7D8E33858409 for ; Thu, 16 Nov 2023 07:01:59 +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 5AE733858D20 for ; Thu, 16 Nov 2023 07:01:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5AE733858D20 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 5AE733858D20 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=1700118097; cv=none; b=dz8ucVvR7XYh1T7+Q/BmDci7Ki8GAZVLaIl0zQiltQoLfjyTGnDOtdOvkunpO4/gRlXqr+PFJ4iMSMbT1/FJ/5VH6BV+nL83en/jmVp4Vs8RIuOiiBVnIpIDuogVzs/+CkRlJM+rG4psAF/Cwy4mn6XM84jZF72Nj4Dq7hqtB0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700118097; c=relaxed/simple; bh=VoWH5GT7CmXzrAM2BGZ516bNK10j9uABesH4MWCz/oE=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=wusiw7MYZZcCavAoeqvfKUbmA0PDGfrFlGTIB30VjBH/qF3DnsRopMU0CZB3ZbhWZ6J0lAfU2GzOhXWWsW3TiNM1dtZ22Fn7u6qTfCgBhX4v4AGu7VfM52413qYOUaOXUnNkoV21fGSwF/YCIV0m9LcAxW8m8+vlqO+hDcx6C50= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700118095; 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=Cx91pxEAmgy5IGS9AC6HHeItcOqg/xuPwx/zoCwkm5M=; b=PFhj+Txq4C9fqCJQ050nMyEFAcxCFWlFD4kKQ80K9MfH+sje5s22ZbcGO5M7TVBMmx2w6t Fzy2LxlJBP9mFEAVIji9qW6xDKCDY6Nhc7+Zuy2y6zu9H734svnaro4biuW4uGVEzdFvyP u3HBOpzGPFxQdzU5AkGKAcX1mEY8R8c= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-529-tWWIe4viNHuEg53W4nS26A-1; Thu, 16 Nov 2023 02:01:34 -0500 X-MC-Unique: tWWIe4viNHuEg53W4nS26A-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 13F4B811E88; Thu, 16 Nov 2023 07:01:34 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA7FFC15881; Thu, 16 Nov 2023 07:01:33 +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 3AG71Uuq2070254 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 16 Nov 2023 08:01:30 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AG71TDP2070253; Thu, 16 Nov 2023 08:01:29 +0100 Date: Thu, 16 Nov 2023 08:01:29 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] slp: Fix handling of IFN_CLZ/CTZ [PR112536] 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.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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: 1782703057438364868 X-GMAIL-MSGID: 1782703057438364868 Hi! We ICE on the following testcase now that IFN_C[LT]Z calls can have one or two arguments (where 2 mean it is well defined at zero). The following patch makes us create child node only for the first argument and compatible_calls_p ensures the other argument is the same, which at least according to the testcase seems sufficient because of vect patterns. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-11-16 Jakub Jelinek PR tree-optimization/112536 * tree-vect-slp.cc (arg0_map): New variable. (vect_get_operand_map): For IFN_CLZ or IFN_CTZ, return arg0_map. * gcc.dg/pr112536.c: New test. Jakub --- gcc/tree-vect-slp.cc.jj 2023-11-11 08:52:20.896838494 +0100 +++ gcc/tree-vect-slp.cc 2023-11-15 10:30:57.606329777 +0100 @@ -505,6 +505,7 @@ static const int cond_expr_maps[3][5] = { 4, -2, -1, 1, 2 }, { 4, -1, -2, 2, 1 } }; +static const int arg0_map[] = { 1, 0 }; static const int arg1_map[] = { 1, 1 }; static const int arg2_map[] = { 1, 2 }; static const int arg1_arg4_map[] = { 2, 1, 4 }; @@ -580,6 +581,10 @@ vect_get_operand_map (const gimple *stmt return nullptr; } + case IFN_CLZ: + case IFN_CTZ: + return arg0_map; + default: break; } --- gcc/testsuite/gcc.dg/pr112536.c.jj 2023-11-15 10:37:44.316580909 +0100 +++ gcc/testsuite/gcc.dg/pr112536.c 2023-11-15 10:37:19.464932191 +0100 @@ -0,0 +1,58 @@ +/* PR tree-optimization/112536 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-ipa-icf" } */ +/* { dg-additional-options "-mlzcnt -mavx512cd -mavx512vl" { target { i?86-*-* x86_64-*-* } } } */ +/* { dg-final { scan-assembler-times "\tvplzcntd\t" 3 { target { i?86-*-* x86_64-*-* } } } } */ + +unsigned a[12]; + +void +foo (void) +{ + int i = a[0]; + int j = a[1]; + int k = a[2]; + int l = a[3]; + int e = i ? __builtin_clz (i) : __SIZEOF_INT__ * __CHAR_BIT__; + int f = j ? __builtin_clz (j) : __SIZEOF_INT__ * __CHAR_BIT__; + int g = k ? __builtin_clz (k) : __SIZEOF_INT__ * __CHAR_BIT__; + int h = l ? __builtin_clz (l) : __SIZEOF_INT__ * __CHAR_BIT__; + a[0] = e; + a[1] = f; + a[2] = g; + a[3] = h; +} + +void +bar (void) +{ + int i = a[4]; + int j = a[5]; + int k = a[6]; + int l = a[7]; + int e = i ? __builtin_clz (i) : __SIZEOF_INT__ * __CHAR_BIT__; + int f = __builtin_clz (j); + int g = __builtin_clz (k); + int h = l ? __builtin_clz (l) : __SIZEOF_INT__ * __CHAR_BIT__; + a[4] = e; + a[5] = f; + a[6] = g; + a[7] = h; +} + +void +baz (void) +{ + int i = a[8]; + int j = a[9]; + int k = a[10]; + int l = a[11]; + int e = __builtin_clz (i); + int f = j ? __builtin_clz (j) : __SIZEOF_INT__ * __CHAR_BIT__; + int g = __builtin_clz (k); + int h = l ? __builtin_clz (l) : __SIZEOF_INT__ * __CHAR_BIT__; + a[8] = e; + a[9] = f; + a[10] = g; + a[11] = h; +}