From patchwork Wed May 17 18:29:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 1782911 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=YT8uuzlR; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QM1qQ5TKVz20dX for ; Thu, 18 May 2023 04:29:54 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 987CD385702F for ; Wed, 17 May 2023 18:29:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 987CD385702F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684348192; bh=JY+1r9U5igbtEtzhz0v58d/JHm8bH3QNjxN1d9Xs/ew=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=YT8uuzlRVbX5MKbtXLmYHXbmuDCfr6y9ZQr96mmjePHoXEFNawM2R3j4S4lUBRWRa bl9048IeVGRro/GpKfEEVkhDk4oFpLh2c4MDAoWgQaQv1Ke47bqfyu8oVrsFlM/p6E wCnxYLdhz/28rH64W6x1MxflQaPXh5IKqexx2cTw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [IPv6:2607:f8b0:4864:20::f2a]) by sourceware.org (Postfix) with ESMTPS id 43E543858D1E for ; Wed, 17 May 2023 18:29:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 43E543858D1E Received: by mail-qv1-xf2a.google.com with SMTP id 6a1803df08f44-623836551f5so5300946d6.1 for ; Wed, 17 May 2023 11:29:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684348170; x=1686940170; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=JY+1r9U5igbtEtzhz0v58d/JHm8bH3QNjxN1d9Xs/ew=; b=iqFTn/Ky0rRenHo+DBQe2tpMKlArg3+prVQrRd6nBFfogHSy85VmT0/W0IsXsSWXS7 2uaBE+pB6/eOd9txvfDj5pU2g5SIA+2PnR2Ab5/mbpkAJIbyaQWTUFqDy8EHoGUbnDk+ qsmZzZ8t/8sabawyUG0lm7aA1HdX5qVHG8uFKVjzlrBtx62hOBOCUP1p2hFNM6h7xcNJ +SSGd7azbp7iNl+L5uqSWwqORYRBn8iItw5mATXWijyEq0B4leMP34/5OxnxNW3fstXY a1V2OD7kUNVWv9nZHrp0XohkAKzXcEIE4RPYLy6BDeyGHLQIC0GGu1Yx03RUv+CWD/rv q6vw== X-Gm-Message-State: AC+VfDxfzqCA2rk+71+kjjSULSX2tXsQt3xCHvWyQ3cJ1xl1DXHtG6MC Tp0UgItFqO4xLYQw0XCWToQ7cWIHfXzJGjRcy45r7k77zg4W6A== X-Google-Smtp-Source: ACHHUZ429UYa9QYigycv8HJHotlTwwNUkVilPfjd4cq3N+v86I+wE08NVLg2NVORHSUEknpT7DvuasbF813AyOGe4/w= X-Received: by 2002:a05:6214:e6e:b0:615:29ab:e4a8 with SMTP id jz14-20020a0562140e6e00b0061529abe4a8mr1025103qvb.31.1684348170296; Wed, 17 May 2023 11:29:30 -0700 (PDT) MIME-Version: 1.0 Date: Wed, 17 May 2023 20:29:19 +0200 Message-ID: Subject: [COMMITTED] i386: Adjust emulated integer vector mode multiplication costs To: "gcc-patches@gcc.gnu.org" X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Uros Bizjak via Gcc-patches From: Uros Bizjak Reply-To: Uros Bizjak Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Returned integer vector mode costs of emulated modes in ix86_multiplication_cost are wrong and do not reflect generated instruction sequences. Rewrite handling of different integer vector modes and different target ABIs to return real instruction counts in order to calculate better costs of various emulated modes. gcc/ChangeLog: * config/i386/i386.cc (ix86_multiplication_cost): Correct calculation of integer vector mode costs to reflect generated instruction sequences of different integer vector modes and different target ABIs. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Uros. diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 498fac468b5..9ab24242b59 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -20463,36 +20463,52 @@ ix86_multiplication_cost (const struct processor_costs *cost, return ix86_vec_cost (mode, inner_mode == DFmode ? cost->mulsd : cost->mulss); else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT) - { - /* vpmullq is used in this case. No emulation is needed. */ - if (TARGET_AVX512DQ) - return ix86_vec_cost (mode, cost->mulss); + switch (mode) + { + case V16QImode: + /* V*QImode is emulated with 4-11 insns. */ + if (TARGET_AVX512BW && TARGET_AVX512VL) + return ix86_vec_cost (mode, cost->mulss + cost->sse_op * 3); + else if (TARGET_XOP) + return ix86_vec_cost (mode, cost->mulss * 2 + cost->sse_op * 5); + /* FALLTHRU */ + case V32QImode: + if (TARGET_AVX512BW && mode == V32QImode) + return ix86_vec_cost (mode, cost->mulss + cost->sse_op * 3); + else + return ix86_vec_cost (mode, cost->mulss * 2 + cost->sse_op * 7); - /* V*QImode is emulated with 7-13 insns. */ - if (mode == V16QImode || mode == V32QImode) - { - int extra = 11; - if (TARGET_XOP && mode == V16QImode) - extra = 5; - else if (TARGET_SSSE3) - extra = 6; - return ix86_vec_cost (mode, cost->mulss * 2 + cost->sse_op * extra); - } - /* V*DImode is emulated with 5-8 insns. */ - else if (mode == V2DImode || mode == V4DImode) - { - if (TARGET_XOP && mode == V2DImode) - return ix86_vec_cost (mode, cost->mulss * 2 + cost->sse_op * 3); - else - return ix86_vec_cost (mode, cost->mulss * 3 + cost->sse_op * 5); - } - /* Without sse4.1, we don't have PMULLD; it's emulated with 7 - insns, including two PMULUDQ. */ - else if (mode == V4SImode && !(TARGET_SSE4_1 || TARGET_AVX)) - return ix86_vec_cost (mode, cost->mulss * 2 + cost->sse_op * 5); - else + case V64QImode: + return ix86_vec_cost (mode, cost->mulss * 2 + cost->sse_op * 9); + + case V4SImode: + /* pmulld is used in this case. No emulation is needed. */ + if (TARGET_SSE4_1) + goto do_native; + /* V4SImode is emulated with 7 insns. */ + else + return ix86_vec_cost (mode, cost->mulss * 2 + cost->sse_op * 5); + + case V2DImode: + case V4DImode: + /* vpmullq is used in this case. No emulation is needed. */ + if (TARGET_AVX512DQ && TARGET_AVX512VL) + goto do_native; + /* V*DImode is emulated with 6-8 insns. */ + else if (TARGET_XOP && mode == V2DImode) + return ix86_vec_cost (mode, cost->mulss * 2 + cost->sse_op * 4); + /* FALLTHRU */ + case V8DImode: + /* vpmullq is used in this case. No emulation is needed. */ + if (TARGET_AVX512DQ && mode == V8DImode) + goto do_native; + else + return ix86_vec_cost (mode, cost->mulss * 3 + cost->sse_op * 5); + + default: + do_native: return ix86_vec_cost (mode, cost->mulss); - } + } else return (cost->mult_init[MODE_INDEX (mode)] + cost->mult_bit * 7); }