From patchwork Wed Aug 30 09:10:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Andre Vieira (lists)" X-Patchwork-Id: 137155 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a7d1:0:b0:3f2:4152:657d with SMTP id p17csp4416842vqm; Wed, 30 Aug 2023 02:11:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHBWkqK313emCfVtEVwadCMLb5qw8xwma3m3tsBnyVc5hkgT5utMKr6wzvNGjGoWRiPRBJN X-Received: by 2002:aa7:c414:0:b0:51e:ed6:df38 with SMTP id j20-20020aa7c414000000b0051e0ed6df38mr1396689edq.13.1693386663496; Wed, 30 Aug 2023 02:11:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693386663; cv=none; d=google.com; s=arc-20160816; b=cCOCFQy7PNO/bXa7+z9CWfg2ec1pv45dhC/axrgulcOnLJoLqezNjCvFGRtBwJEwOc 6e1nI0UX7CHQRx8UZkr8GRwIaimOndaiqcqcpuK7mjqmiPawcTiQ+uhSiQJaoNqrJTxM gF2SpyV/aMM3hpTbR70kGs88AtxSeJ9zr3rv1siPI/Uj397LfbpgiEmPjweS3mHsH8nD kw1bYJtlZ6RpWhtM9+6nS7/fRgiLrQ+0kLYoqQOCM2tyhHbXt8jmJEKgOP6RtTXno8Cv BQ5Sueak29wSNOyFGb+Muvu8Pmp/aGPeTNqxKI6dpDM1Fkxqcyt1dlRNNDN9H+J+kQl9 x0jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:in-reply-to:cc :references:to:content-language:subject:user-agent:mime-version:date :message-id:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=bM4ssMgK8S2KBdw7ymicPyUe/e/bvNa/kAFB8eEJh1Q=; fh=Z+8/kjPbzboGhTQMFYyyjN/U00RNQh1yaEWpyQnXrVg=; b=0Z0qFOpxviSx1aKKcun7LrbuS88LGzz28E8Ef6wlYsEDiyeLMxPAX2dB6auuH8qOXP sRphxKam2w1U5wjdTnn1aNZx2LOpUg3W3oSlQUnz3MpKfnEsmXgdQk7Ijnl60IdgDaaR HH5fkS3/MFc2boARTRBd2XwhEAZTN1hUEHoU56HGw7hWDgGzckskBSQy/JOnW85TlJfx iVRw6RAeqgpXklbjcJysEKHGhllJdk7gOOKqExsKxw13E81FodauUXPhFkRS0mh96TQS RigCDkwjzn/BZguWX6MLC4w7i2xu0Ud78sY2CbFXkjDXCLWk+STLEsvdu7MiEGk6CsPw ZLXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZlssaRGN; 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=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n22-20020a05640206d600b005254cf5c284si7130738edy.526.2023.08.30.02.11.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 02:11:03 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=ZlssaRGN; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2E8293858407 for ; Wed, 30 Aug 2023 09:11:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E8293858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693386662; bh=bM4ssMgK8S2KBdw7ymicPyUe/e/bvNa/kAFB8eEJh1Q=; h=Date:Subject:To:References:Cc:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ZlssaRGNQ3gNrxOHK6PNiYF2MPzuC30h3d6D5NcGMgLKUT4m7DxG68XaDnkN18/CH h1ZKqoM+NWus64/O0U8gHG1uk5oWODrE4ni7qoujNTjLK/i5+qTFTmllAKiOwG/ovo QazYcEJHhyD/pSZRk7CSFcXzx2nPIy+a0jC9m0NY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 0F7773858C30 for ; Wed, 30 Aug 2023 09:10:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0F7773858C30 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DC0AB2F4; Wed, 30 Aug 2023 02:10:56 -0700 (PDT) Received: from [10.57.64.216] (unknown [10.57.64.216]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 966773F64C; Wed, 30 Aug 2023 02:10:16 -0700 (PDT) Message-ID: <6adafeff-e026-aec9-2b1a-8a5f736f813d@arm.com> Date: Wed, 30 Aug 2023 10:10:10 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: [Patch 3/8] vect: Fix vect_get_smallest_scalar_type for simd clones Content-Language: en-US To: gcc-patches@gcc.gnu.org References: <73b53052-c3a4-4028-2836-ade419431eda@arm.com> Cc: Richard Sandiford , Richard Biener , "jakub@redhat.com" In-Reply-To: <73b53052-c3a4-4028-2836-ade419431eda@arm.com> X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_LOTSOFHASH, SPF_HELO_NONE, SPF_NONE, TXREP 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: , X-Patchwork-Original-From: "Andre Vieira \(lists\) via Gcc-patches" From: "Andre Vieira (lists)" Reply-To: "Andre Vieira \(lists\)" Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775644614332575137 X-GMAIL-MSGID: 1775644614332575137 The vect_get_smallest_scalar_type helper function was using any argument to a simd clone call when trying to determine the smallest scalar type that would be vectorized. This included the function pointer type in a MASK_CALL for instance, and would result in the wrong type being selected. Instead this patch special cases simd_clone_call's and uses only scalar types of the original function that get transformed into vector types. gcc/ChangeLog: * tree-vect-data-refs.cci (vect_get_smallest_scalar_type): Special case simd clone calls and only use types that are mapped to vectors. * tree-vect-stmts.cc (simd_clone_call_p): New helper function. * tree-vectorizer.h (simd_clone_call_p): Declare new function. gcc/testsuite/ChangeLog: * gcc.dg/vect/vect-simd-clone-16f.c: Remove unnecessary differentation between targets with different pointer sizes. * gcc.dg/vect/vect-simd-clone-17f.c: Likewise. * gcc.dg/vect/vect-simd-clone-18f.c: Likewise. diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-16f.c b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-16f.c index 574698d3e133ecb8700e698fa42a6b05dd6b8a18..7cd29e894d0502a59fadfe67db2db383133022d3 100644 --- a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-16f.c +++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-16f.c @@ -7,9 +7,8 @@ #include "vect-simd-clone-16.c" /* Ensure the the in-branch simd clones are used on targets that support them. - Some targets use pairs of vectors and do twice the calls. */ -/* { dg-final { scan-tree-dump-times {[\n\r] [^\n]* = foo\.simdclone} 2 "vect" { target { ! { { i?86-*-* x86_64-*-* } && { ! lp64 } } } } } } */ -/* { dg-final { scan-tree-dump-times {[\n\r] [^\n]* = foo\.simdclone} 4 "vect" { target { { i?86*-*-* x86_64-*-* } && { ! lp64 } } } } } */ + */ +/* { dg-final { scan-tree-dump-times {[\n\r] [^\n]* = foo\.simdclone} 2 "vect" } } */ /* The LTO test produces two dump files and we scan the wrong one. */ /* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-17f.c b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-17f.c index 8bb6d19301a67a3eebce522daaf7d54d88f708d7..177521dc44531479fca1f1a1a0f2010f30fa3fb5 100644 --- a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-17f.c +++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-17f.c @@ -7,9 +7,8 @@ #include "vect-simd-clone-17.c" /* Ensure the the in-branch simd clones are used on targets that support them. - Some targets use pairs of vectors and do twice the calls. */ -/* { dg-final { scan-tree-dump-times {[\n\r] [^\n]* = foo\.simdclone} 2 "vect" { target { ! { { i?86-*-* x86_64-*-* } && { ! lp64 } } } } } } */ -/* { dg-final { scan-tree-dump-times {[\n\r] [^\n]* = foo\.simdclone} 4 "vect" { target { { i?86*-*-* x86_64-*-* } && { ! lp64 } } } } } */ + */ +/* { dg-final { scan-tree-dump-times {[\n\r] [^\n]* = foo\.simdclone} 2 "vect" } } */ /* The LTO test produces two dump files and we scan the wrong one. */ /* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-18f.c b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-18f.c index d34f23f4db8e9c237558cc22fe66b7e02b9e6c20..4dd51381d73c0c7c8ec812f24e5054df038059c5 100644 --- a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-18f.c +++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-18f.c @@ -7,9 +7,8 @@ #include "vect-simd-clone-18.c" /* Ensure the the in-branch simd clones are used on targets that support them. - Some targets use pairs of vectors and do twice the calls. */ -/* { dg-final { scan-tree-dump-times {[\n\r] [^\n]* = foo\.simdclone} 2 "vect" { target { ! { { i?86-*-* x86_64-*-* } && { ! lp64 } } } } } } */ -/* { dg-final { scan-tree-dump-times {[\n\r] [^\n]* = foo\.simdclone} 4 "vect" { target { { i?86*-*-* x86_64-*-* } && { ! lp64 } } } } } */ + */ +/* { dg-final { scan-tree-dump-times {[\n\r] [^\n]* = foo\.simdclone} 2 "vect" } } */ /* The LTO test produces two dump files and we scan the wrong one. */ /* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */ diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc index a3570c45b5209281ac18c1220c3b95398487f389..1bdbea232afc6facddac23269ee3da033eb1ed50 100644 --- a/gcc/tree-vect-data-refs.cc +++ b/gcc/tree-vect-data-refs.cc @@ -119,6 +119,7 @@ tree vect_get_smallest_scalar_type (stmt_vec_info stmt_info, tree scalar_type) { HOST_WIDE_INT lhs, rhs; + cgraph_node *node; /* During the analysis phase, this function is called on arbitrary statements that might not have scalar results. */ @@ -145,6 +146,23 @@ vect_get_smallest_scalar_type (stmt_vec_info stmt_info, tree scalar_type) scalar_type = rhs_type; } } + else if (simd_clone_call_p (stmt_info->stmt, &node)) + { + auto clone = node->simd_clones->simdclone; + for (unsigned int i = 0; i < clone->nargs; ++i) + { + if (clone->args[i].arg_type == SIMD_CLONE_ARG_TYPE_VECTOR) + { + tree arg_scalar_type = TREE_TYPE (clone->args[i].vector_type); + rhs = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (arg_scalar_type)); + if (rhs < lhs) + { + scalar_type = arg_scalar_type; + lhs = rhs; + } + } + } + } else if (gcall *call = dyn_cast (stmt_info->stmt)) { unsigned int i = 0; diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index 0fe5d0594abc095d3770b5ce4b9f2bad5205ab2f..35207de7acb410358220dbe8d1af82215b5091bf 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -3965,6 +3965,29 @@ vect_simd_lane_linear (tree op, class loop *loop, } } +bool +simd_clone_call_p (gimple *stmt, cgraph_node **out_node) +{ + gcall *call = dyn_cast (stmt); + if (!call) + return false; + + tree fndecl = NULL_TREE; + if (gimple_call_internal_p (call, IFN_MASK_CALL)) + fndecl = TREE_OPERAND (gimple_call_arg (stmt, 0), 0); + else + fndecl = gimple_call_fndecl (stmt); + + if (fndecl == NULL_TREE) + return false; + + cgraph_node *node = cgraph_node::get (fndecl); + if (out_node) + *out_node = node; + + return node != NULL && node->simd_clones != NULL; +} + /* Function vectorizable_simd_clone_call. Check if STMT_INFO performs a function call that can be vectorized diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h index a65161499ea13f200aa745ca396db663a217b081..69634f7a6032696b394a62fb7ca8986bc78987c8 100644 --- a/gcc/tree-vectorizer.h +++ b/gcc/tree-vectorizer.h @@ -2165,6 +2165,7 @@ extern bool vect_can_advance_ivs_p (loop_vec_info); extern void vect_update_inits_of_drs (loop_vec_info, tree, tree_code); /* In tree-vect-stmts.cc. */ +extern bool simd_clone_call_p (gimple *, struct cgraph_node **node = NULL); extern tree get_related_vectype_for_scalar_type (machine_mode, tree, poly_uint64 = 0); extern tree get_vectype_for_scalar_type (vec_info *, tree, unsigned int = 0);