From patchwork Tue Apr 18 18:17:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 1770418 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20221208.gappssmtp.com header.i=@rivosinc-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=sbhzZKU9; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 4Q1BxF4j1Nz1yZy for ; Wed, 19 Apr 2023 04:18:08 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1FCE7385841E for ; Tue, 18 Apr 2023 18:18:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by sourceware.org (Postfix) with ESMTPS id 17EE43858D1E for ; Tue, 18 Apr 2023 18:17:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 17EE43858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-51b4ef5378bso670765a12.1 for ; Tue, 18 Apr 2023 11:17:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681841870; x=1684433870; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=dTdvfE+BMEB2p+3B8wbAZ4lIryBv2W0GnUlaaiBh3hs=; b=sbhzZKU9NfpQM3YE4bz+TjBtoHqZo8+lsRy0aR7sInVbjeeKdPsRZVsgd15ft4DULL 1YL7wQBmE4y2JFofMpPGO5ft/5ytZ3aCuYMBiGxmZgf7SpHBkvR6juoA6ru/t3TWR6Y2 NPXEDhN2oLkxoGkPfm37VjgKl1UyNwLqcHVdKf/ykASL3HEaF0fXkinanidSNFY3S5PM Cbab1wea6rR8UjPstxvrXiGtBU7owURHHKtQ8XAapA+s1f+awBdt9xbuDz0D3oAyYsms +HUImklyi4+o90BeXXLDQUU5vJ+WNRTgKn8HfpLBz6OH/huZqzx6amPsYI8jiu8re5bx O9vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681841870; x=1684433870; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dTdvfE+BMEB2p+3B8wbAZ4lIryBv2W0GnUlaaiBh3hs=; b=cgrohhpzqkBU0uwlkQ7HrxBSaH3UYE0AmSJcFiRn5xWEv1SjnYCdxUFAto1g+MOQ5I n+BejQdzZZGzukxhqIjRUe7VtYQ9VVj4kjXiJ/tSidB9mMWY3u5+0E4OY4JlUYlgUqGZ mLMyBL2aVCo3ugVGvtpX3RIaNkzEIlQGyWP1jOFcf6JV6z5KinzP+U/dJ/YIPPlCLUH7 /69Thpmf8XGV5ZjQY1DSpXdBPvvxXKIfVZO4ci1Yb/xGcsPnH/iclXpSgq+8qCkwNT/W pV223rbUV4ElimXjz3TnBx21tjtWz7Smhyi9EmTZPS8J4DOs5kX/dHAW7OCXJh9IIDDp r9WQ== X-Gm-Message-State: AAQBX9dv1khF4v86Cm2K0W1KT83VEutL3cUHn2hsNvyP4zBp/dvKcCLE QbWXMV1wOtN4yQLK5GItUpqiLTroN06/feMqSRZv/w== X-Google-Smtp-Source: AKy350Y7PujcxX7fcEhSSG1KrS6JmoLwXaGlbyZYeLWGnOFfO1H6gLt6Ow1G//aeoPWCpfU8jHnM4A== X-Received: by 2002:a17:903:404c:b0:19f:188c:3e34 with SMTP id n12-20020a170903404c00b0019f188c3e34mr2214339pla.53.1681841869653; Tue, 18 Apr 2023 11:17:49 -0700 (PDT) Received: from vineet-framework.ba.rivosinc.com ([71.202.114.183]) by smtp.gmail.com with ESMTPSA id 12-20020a170902c10c00b0019b0afc24e8sm5588758pli.250.2023.04.18.11.17.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 11:17:49 -0700 (PDT) From: Vineet Gupta To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, Jeff Law , Palmer Dabbelt , Philipp Tomsich , Christoph Mullner , gnu-toolchain@rivosinc.co, Vineet Gupta Subject: [PATCH] expansion: make layout of x_shift*cost[][][] more efficient Date: Tue, 18 Apr 2023 11:17:45 -0700 Message-Id: <20230418181745.987867-1-vineetg@rivosinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" when debugging expmed.[ch] for PR/108987 saw that some of the cost arrays have less than ideal layout as follows: x_shift*cost[0..63][speed][modes] We would want speed to be first index since a typical compile will have that fixed, followed by mode and then the shift values. It should be non-functional from compiler semantics pov, except executing slightly faster due to better locality of shift values for given speed and mode. And also a bit more intutive when debugging. gcc/Changelog: * expmed.h (x_shift*_cost): convert to int [speed][mode][shift]. (shift*_cost_ptr ()): Access x_shift*_cost array directly. Signed-off-by: Vineet Gupta --- gcc/expmed.h | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/gcc/expmed.h b/gcc/expmed.h index c747a0da1637..d032beaef550 100644 --- a/gcc/expmed.h +++ b/gcc/expmed.h @@ -161,15 +161,14 @@ struct target_expmed { struct expmed_op_cheap x_sdiv_pow2_cheap; struct expmed_op_cheap x_smod_pow2_cheap; - /* Cost of various pieces of RTL. Note that some of these are indexed by - shift count and some by mode. */ + /* Cost of various pieces of RTL. */ int x_zero_cost[2]; struct expmed_op_costs x_add_cost; struct expmed_op_costs x_neg_cost; - struct expmed_op_costs x_shift_cost[MAX_BITS_PER_WORD]; - struct expmed_op_costs x_shiftadd_cost[MAX_BITS_PER_WORD]; - struct expmed_op_costs x_shiftsub0_cost[MAX_BITS_PER_WORD]; - struct expmed_op_costs x_shiftsub1_cost[MAX_BITS_PER_WORD]; + int x_shift_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD]; + int x_shiftadd_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD]; + int x_shiftsub0_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD]; + int x_shiftsub1_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD]; struct expmed_op_costs x_mul_cost; struct expmed_op_costs x_sdiv_cost; struct expmed_op_costs x_udiv_cost; @@ -395,8 +394,8 @@ neg_cost (bool speed, machine_mode mode) inline int * shift_cost_ptr (bool speed, machine_mode mode, int bits) { - return expmed_op_cost_ptr (&this_target_expmed->x_shift_cost[bits], - speed, mode); + int midx = expmed_mode_index (mode); + return &this_target_expmed->x_shift_cost[speed][midex][bits]; } /* Set the COST of doing a shift in MODE by BITS when optimizing for SPEED. */ @@ -421,8 +420,8 @@ shift_cost (bool speed, machine_mode mode, int bits) inline int * shiftadd_cost_ptr (bool speed, machine_mode mode, int bits) { - return expmed_op_cost_ptr (&this_target_expmed->x_shiftadd_cost[bits], - speed, mode); + int midx = expmed_mode_index (mode); + return &this_target_expmed->x_shiftadd_cost[speed][midex][bits]; } /* Set the COST of doing a shift in MODE by BITS followed by an add when @@ -448,8 +447,8 @@ shiftadd_cost (bool speed, machine_mode mode, int bits) inline int * shiftsub0_cost_ptr (bool speed, machine_mode mode, int bits) { - return expmed_op_cost_ptr (&this_target_expmed->x_shiftsub0_cost[bits], - speed, mode); + int midx = expmed_mode_index (mode); + return &this_target_expmed->x_shiftsub0_cost[speed][midex][bits]; } /* Set the COST of doing a shift in MODE by BITS and then subtracting a @@ -475,8 +474,8 @@ shiftsub0_cost (bool speed, machine_mode mode, int bits) inline int * shiftsub1_cost_ptr (bool speed, machine_mode mode, int bits) { - return expmed_op_cost_ptr (&this_target_expmed->x_shiftsub1_cost[bits], - speed, mode); + int midx = expmed_mode_index (mode); + return &this_target_expmed->x_shiftsub1_cost[speed][midex][bits]; } /* Set the COST of subtracting a shift in MODE by BITS from a value when