From patchwork Sun May 19 16:39:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 1101588 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-501109-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=inria.fr Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Jge5qyN1"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 456SS33JXBz9sBK for ; Mon, 20 May 2019 02:39:58 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=rhgbKGdXxk3/awnpDaX/2Sivs+px43RFxUhlw5RZn4JdFnKiAlo+D jIftVd1vXkcnMCdcj440/MNwxcDOtzydIIZ9sKJWYwiqDdU/OVhRsDoAMaBj1G1A B5z5/n+jp7AwubbHXNuAnOXuBzk51Ydh9Ba4BwrQ8lyntcILrhbluk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=AHtfOr/DxFWdxyjMaJx78/pHuwk=; b=Jge5qyN1e4u18r7wU10F jice1bEbKcvVjEmFbs3JpYtTZ3xXduHIr1brf2zOWJrki04xRV5TzXKDePVtwfl1 vnLbnchxQePKYsaJESBJHCRfLFyUfooueehnTq6ro1GisahVcwnHTsDMV/FMRYRS hfYbprNoWE4WlNaFT70oqHY= Received: (qmail 32924 invoked by alias); 19 May 2019 16:39:51 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 32916 invoked by uid 89); 19 May 2019 16:39:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=sk:tree_ve, coverage, regtest, arg0 X-HELO: mail3-relais-sop.national.inria.fr Received: from mail3-relais-sop.national.inria.fr (HELO mail3-relais-sop.national.inria.fr) (192.134.164.104) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 19 May 2019 16:39:49 +0000 Received: from grove.saclay.inria.fr ([193.55.177.244]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 19 May 2019 18:39:47 +0200 Date: Sun, 19 May 2019 18:39:40 +0200 (CEST) From: Marc Glisse To: gcc-patches@gcc.gnu.org Subject: [i386] Fold __builtin_ia32_shufpd to VEC_PERM_EXPR Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Hello, dropping the builtin as early as possible seems like it can only help us optimize the code. Jakub suggested in the PR that he liked this approach better than using __builtin_shuffle in the header. There is already some coverage in the testsuite (as I noticed when I tried to restrict the argument to [0, 3]...). If this one is ok, I may add a few more (say shufps to begin with) later. Bootstrap+regtest on x86_64-pc-linux-gnu. 2019-05-20 Marc Glisse PR rtl-optimization/43147 * config/i386/i386.c (ix86_gimple_fold_builtin): Handle IX86_BUILTIN_SHUFPD. Index: gcc/config/i386/i386.c =================================================================== --- gcc/config/i386/i386.c (revision 271376) +++ gcc/config/i386/i386.c (working copy) @@ -17290,21 +17290,21 @@ ix86_fold_builtin (tree fndecl, int n_ar bool ix86_gimple_fold_builtin (gimple_stmt_iterator *gsi) { gimple *stmt = gsi_stmt (*gsi); tree fndecl = gimple_call_fndecl (stmt); gcc_checking_assert (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_MD)); int n_args = gimple_call_num_args (stmt); enum ix86_builtins fn_code = (enum ix86_builtins) DECL_FUNCTION_CODE (fndecl); tree decl = NULL_TREE; - tree arg0, arg1; + tree arg0, arg1, arg2; enum rtx_code rcode; unsigned HOST_WIDE_INT count; bool is_vshift; switch (fn_code) { case IX86_BUILTIN_TZCNT32: decl = builtin_decl_implicit (BUILT_IN_CTZ); goto fold_tzcnt_lzcnt; @@ -17594,20 +17594,46 @@ ix86_gimple_fold_builtin (gimple_stmt_it arithmetic right shift the result is zero. */ location_t loc = gimple_location (stmt); gimple *g = gimple_build_assign (gimple_call_lhs (stmt), build_zero_cst (TREE_TYPE (arg0))); gimple_set_location (g, loc); gsi_replace (gsi, g, false); return true; } break; + case IX86_BUILTIN_SHUFPD: + arg2 = gimple_call_arg (stmt, 2); + if (TREE_CODE (arg2) == INTEGER_CST) + { + location_t loc = gimple_location (stmt); + unsigned HOST_WIDE_INT imask = TREE_INT_CST_LOW (arg2); + arg0 = gimple_call_arg (stmt, 0); + arg1 = gimple_call_arg (stmt, 1); + tree itype = long_long_integer_type_node; + tree vtype = build_vector_type (itype, 2); /* V2DI */ + tree_vector_builder elts (vtype, 2, 1); + /* Ignore bits other than the lowest 2. */ + elts.quick_push (build_int_cst (itype, imask & 1)); + imask >>= 1; + elts.quick_push (build_int_cst (itype, 2 + (imask & 1))); + tree omask = elts.build (); + gimple *g = gimple_build_assign (gimple_call_lhs (stmt), + VEC_PERM_EXPR, + arg0, arg1, omask); + gimple_set_location (g, loc); + gsi_replace (gsi, g, false); + return true; + } + // Do not error yet, the constant could be propagated later? + break; + default: break; } return false; } /* Handler for an SVML-style interface to a library with vectorized intrinsics. */