From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7921) id 56D4F3857714; Fri, 21 Apr 2023 16:14:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56D4F3857714 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682093682; bh=RBPLeWSeHA3lE8x/BjHMKvgi/ugM89K/J3JW8i690+Q=; h=From:To:Subject:Date:From; b=IWRzBVsFAXGFrFaDetkrSKTOxGQ5zBS81r1DSQksLijgzbbWa7cAwK0TMYFqPP+df dv2pbzqRHncm8epiE8EvxWtD/MSLYuAyY1OiDUC9lG53d8wBl2FRqQjLDXm25Xmqf4 mJR4zkfDvil/8oCkPKvngeQrjGE+J1bWxO4IjzTE= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Vineet Gupta To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-149] expansion: make layout of x_shift*cost[][][] more efficient X-Act-Checkin: gcc X-Git-Author: Vineet Gupta X-Git-Refname: refs/heads/master X-Git-Oldrev: e6f689d090011eaa4050357b3dd2d7b9109b83ec X-Git-Newrev: 1fe9bef9f5536e46b901139631863b3b86b97898 Message-Id: <20230421161442.56D4F3857714@sourceware.org> Date: Fri, 21 Apr 2023 16:14:42 +0000 (GMT) List-Id: https://gcc.gnu.org/g:1fe9bef9f5536e46b901139631863b3b86b97898 commit r14-149-g1fe9bef9f5536e46b901139631863b3b86b97898 Author: Vineet Gupta Date: Tue Feb 28 19:27:26 2023 -0800 expansion: make layout of x_shift*cost[][][] more efficient 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 Diff: --- gcc/expmed.h | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/gcc/expmed.h b/gcc/expmed.h index c747a0da163..22ae1d2d074 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][midx][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][midx][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][midx][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][midx][bits]; } /* Set the COST of subtracting a shift in MODE by BITS from a value when