From patchwork Mon Oct 23 11:30:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 116710 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4534813qgn; Mon, 23 Oct 2017 04:31:15 -0700 (PDT) X-Received: by 10.159.207.143 with SMTP id z15mr9850228plo.159.1508758275770; Mon, 23 Oct 2017 04:31:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508758275; cv=none; d=google.com; s=arc-20160816; b=vxXVeBDpLfvZC/bsjb5LE4K3IqVGNjSrgYCnyB1nLjGDvDFuEcnJls6VYEbetweY1l GIxkDApZ4ZG3JQQXTDL31XV6Fm9fxn7aheZj56FTSioVKrDjcLZ+4KV5huA6i3ag6UJ6 YAiejAD8KbETq+0KpXHWh2Si/bloIU9nQBlKUyU8R7X2199H3MIhlrTrb9lBRIjOujBQ HV5i7Kh+IuwoRYDFBF7Kv3qOV//LYMXs8LVFzPeHLEe19QbpCuncThq9nwaLZ1JSvgyW DhU8yYCzO0jVpyWeV/BmFlM9OYcDzpQxX+CH6bZ/8Oem1lQNDv2LN7wa4ewFoQLb+hXA BWTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:mail-followup-to:to:from:delivered-to:sender:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=kCyFjghSHOTXz2WYUlaEP9R2fh47mqabi8xwuvGHVgI=; b=kVoSEWlOUF7Djv+NibOBOLJiD+RZjB/jbxVKLL9fupVSO14BSRFNepSHrxxvNja3gJ W398pcaoZAVoQYvdks3BtrOeGATkh6oRVhVmXLnwJAs4yJPC0WLCRIOgqu+kcDkPJA3q jRqVJv3ok/ZtEx5tS/1qZ42OhuvS+4Jiu/UeTyaf9ejQfaOAhTgrgv1ZawiSsvUC+aut P0pYi7dn3rZFtRFgpfx5NE2ivjJXMqC8mfO9NIcFtmT6p1Zgj2J/VcpbgTOIO6ZcoikP TCAvhwka4l9UzSV/T2E1smgeuCayHimWqCO7S0dc1+ie+eGqypApsM3K1h0bXprDdmLZ c0Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BOdENOgX; spf=pass (google.com: domain of gcc-patches-return-464750-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464750-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id x1si4755527pgp.479.2017.10.23.04.31.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 04:31:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-464750-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BOdENOgX; spf=pass (google.com: domain of gcc-patches-return-464750-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464750-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=default; b=yOxnmMpQN9c9dnkvMUCs+uxjrNDey OJsElz7/iRAPOdS3Q3jIOwCqhXUTtL1bWBbJSyT4yfa2BQDxcC48lMjJx0ZbdTKL KYz2QtN1OkSsckXxXTTtw+bEw+OxoG6hEaJKfUsIZcM3/wPg/5hM39PP6RWo04+B xiddQLUQrJ41TM= 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:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; s=default; bh=/WHlx0wtwvpPN97nN8raQ5wqTXo=; b=BOd ENOgXnxpM+WAIjm0jIn0eFVGDrzGjbiOifhNy4kYzq2nMg9VxQCUSOzHqyGkD+b6 GH8+6JieIhJ8LJhwHwNbd+hVWvzULH/lqdmSLeqKz8dvurm+JPOQm2y6bLDCTJ/Y 0Khek0v11qBWcH42Ll5Ixue0M2BP5NSj9u8WIJL8= Received: (qmail 98360 invoked by alias); 23 Oct 2017 11:31:02 -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 98336 invoked by uid 89); 23 Oct 2017 11:31:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-15.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=12289, 121210 X-HELO: mail-wr0-f172.google.com Received: from mail-wr0-f172.google.com (HELO mail-wr0-f172.google.com) (209.85.128.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Oct 2017 11:30:58 +0000 Received: by mail-wr0-f172.google.com with SMTP id p96so3117563wrb.7 for ; Mon, 23 Oct 2017 04:30:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=kCyFjghSHOTXz2WYUlaEP9R2fh47mqabi8xwuvGHVgI=; b=au001LiqkGB+t/u7qM2wZqG8dCqquKgWGkMDOfdkQ6qcxWxeAFkS3eoW088DXPX4WD 3j9U/vq63OvNaWjQTmnLqTHOYw4IOKhsnKORXxBPzfrldL8tf9P5duHrB8uZ1fHxtkBO MZ9TqfPZkLrLUQsPz+mm2qHqy71TnoJjR+hX8ZS2kdacE7dYWMRb4OdjAcTFy0L+Oc0q rDMCoLH+Fpx1l5W7JhKjFMexzbHpO6epOv1Q5e3XvdorTNq6k1mlXwX/W22qZ7yfSiJd BmRm0HyrvXXFQb5Sx1rcp0vVqvv5E7/Dbwj4sf83+sJB5pwq+wvSYNlUD6tbdXwBj1aU btWQ== X-Gm-Message-State: AMCzsaXiWjqjftTG+HZzsGrnyLGbcRluqsKuRrmlSW9lom9/fPfgcshZ Pdk8hxgrj8lFwKdQ/9IGzfLNuwqAUIE= X-Google-Smtp-Source: ABhQp+SSggDtwmzLmm2bohlOwZX5XayPy/gSZNYIJUlhC0aMBFK1jSg4dwX70Au7IRahQuHKYbS2Mg== X-Received: by 10.223.179.1 with SMTP id j1mr1135240wrd.105.1508758255860; Mon, 23 Oct 2017 04:30:55 -0700 (PDT) Received: from localhost ([2.26.27.199]) by smtp.gmail.com with ESMTPSA id l130sm658939wmd.47.2017.10.23.04.30.54 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Oct 2017 04:30:54 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [22/nn] Make dse.c use offset/width instead of start/end References: <87wp3mxgir.fsf@linaro.org> Date: Mon, 23 Oct 2017 12:30:52 +0100 In-Reply-To: <87wp3mxgir.fsf@linaro.org> (Richard Sandiford's message of "Mon, 23 Oct 2017 12:14:36 +0100") Message-ID: <87a80iummr.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 store_info and read_info_type in dse.c represented the ranges as start/end, but a lot of the internal code used offset/width instead. Using offset/width throughout fits better with the poly_int.h range-checking functions. 2017-10-23 Richard Sandiford Alan Hayward David Sherwood gcc/ * dse.c (store_info, read_info_type): Replace begin and end with offset and width. (print_range): New function. (set_all_positions_unneeded, any_positions_needed_p) (check_mem_read_rtx, scan_stores, scan_reads, dse_step5): Update accordingly. (record_store): Likewise. Optimize the case in which all positions are unneeded. (get_stored_val): Replace read_begin and read_end with read_offset and read_width. (replace_read): Update call accordingly. Index: gcc/dse.c =================================================================== --- gcc/dse.c 2017-10-23 11:47:11.273428262 +0100 +++ gcc/dse.c 2017-10-23 11:47:48.294155952 +0100 @@ -243,9 +243,12 @@ struct store_info /* Canonized MEM address for use by canon_true_dependence. */ rtx mem_addr; - /* The offset of the first and byte before the last byte associated - with the operation. */ - HOST_WIDE_INT begin, end; + /* The offset of the first byte associated with the operation. */ + HOST_WIDE_INT offset; + + /* The number of bytes covered by the operation. This is always exact + and known (rather than -1). */ + HOST_WIDE_INT width; union { @@ -261,7 +264,7 @@ struct store_info bitmap bmap; /* Number of set bits (i.e. unneeded bytes) in BITMAP. If it is - equal to END - BEGIN, the whole store is unused. */ + equal to WIDTH, the whole store is unused. */ int count; } large; } positions_needed; @@ -304,10 +307,11 @@ struct read_info_type /* The id of the mem group of the base address. */ int group_id; - /* The offset of the first and byte after the last byte associated - with the operation. If begin == end == 0, the read did not have - a constant offset. */ - int begin, end; + /* The offset of the first byte associated with the operation. */ + HOST_WIDE_INT offset; + + /* The number of bytes covered by the operation, or -1 if not known. */ + HOST_WIDE_INT width; /* The mem being read. */ rtx mem; @@ -586,6 +590,18 @@ static deferred_change *deferred_change_ /* The number of bits used in the global bitmaps. */ static unsigned int current_position; + +/* Print offset range [OFFSET, OFFSET + WIDTH) to FILE. */ + +static void +print_range (FILE *file, poly_int64 offset, poly_int64 width) +{ + fprintf (file, "["); + print_dec (offset, file, SIGNED); + fprintf (file, ".."); + print_dec (offset + width, file, SIGNED); + fprintf (file, ")"); +} /*---------------------------------------------------------------------------- Zeroth step. @@ -1212,10 +1228,9 @@ set_all_positions_unneeded (store_info * { if (__builtin_expect (s_info->is_large, false)) { - int pos, end = s_info->end - s_info->begin; - for (pos = 0; pos < end; pos++) - bitmap_set_bit (s_info->positions_needed.large.bmap, pos); - s_info->positions_needed.large.count = end; + bitmap_set_range (s_info->positions_needed.large.bmap, + 0, s_info->width); + s_info->positions_needed.large.count = s_info->width; } else s_info->positions_needed.small_bitmask = HOST_WIDE_INT_0U; @@ -1227,8 +1242,7 @@ set_all_positions_unneeded (store_info * any_positions_needed_p (store_info *s_info) { if (__builtin_expect (s_info->is_large, false)) - return (s_info->positions_needed.large.count - < s_info->end - s_info->begin); + return s_info->positions_needed.large.count < s_info->width; else return (s_info->positions_needed.small_bitmask != HOST_WIDE_INT_0U); } @@ -1355,8 +1369,12 @@ record_store (rtx body, bb_info_t bb_inf set_usage_bits (group, offset, width, expr); if (dump_file && (dump_flags & TDF_DETAILS)) - fprintf (dump_file, " processing const base store gid=%d[%d..%d)\n", - group_id, (int)offset, (int)(offset+width)); + { + fprintf (dump_file, " processing const base store gid=%d", + group_id); + print_range (dump_file, offset, width); + fprintf (dump_file, "\n"); + } } else { @@ -1368,8 +1386,11 @@ record_store (rtx body, bb_info_t bb_inf group_id = -1; if (dump_file && (dump_flags & TDF_DETAILS)) - fprintf (dump_file, " processing cselib store [%d..%d)\n", - (int)offset, (int)(offset+width)); + { + fprintf (dump_file, " processing cselib store "); + print_range (dump_file, offset, width); + fprintf (dump_file, "\n"); + } } const_rhs = rhs = NULL_RTX; @@ -1435,18 +1456,21 @@ record_store (rtx body, bb_info_t bb_inf { HOST_WIDE_INT i; if (dump_file && (dump_flags & TDF_DETAILS)) - fprintf (dump_file, " trying store in insn=%d gid=%d[%d..%d)\n", - INSN_UID (ptr->insn), s_info->group_id, - (int)s_info->begin, (int)s_info->end); + { + fprintf (dump_file, " trying store in insn=%d gid=%d", + INSN_UID (ptr->insn), s_info->group_id); + print_range (dump_file, s_info->offset, s_info->width); + fprintf (dump_file, "\n"); + } /* Even if PTR won't be eliminated as unneeded, if both PTR and this insn store the same constant value, we might eliminate this insn instead. */ if (s_info->const_rhs && const_rhs - && offset >= s_info->begin - && offset + width <= s_info->end - && all_positions_needed_p (s_info, offset - s_info->begin, + && known_subrange_p (offset, width, + s_info->offset, s_info->width) + && all_positions_needed_p (s_info, offset - s_info->offset, width)) { if (GET_MODE (mem) == BLKmode) @@ -1462,8 +1486,7 @@ record_store (rtx body, bb_info_t bb_inf { rtx val; start_sequence (); - val = get_stored_val (s_info, GET_MODE (mem), - offset, offset + width, + val = get_stored_val (s_info, GET_MODE (mem), offset, width, BLOCK_FOR_INSN (insn_info->insn), true); if (get_insns () != NULL) @@ -1474,10 +1497,18 @@ record_store (rtx body, bb_info_t bb_inf } } - for (i = MAX (offset, s_info->begin); - i < offset + width && i < s_info->end; - i++) - set_position_unneeded (s_info, i - s_info->begin); + if (known_subrange_p (s_info->offset, s_info->width, offset, width)) + /* The new store touches every byte that S_INFO does. */ + set_all_positions_unneeded (s_info); + else + { + HOST_WIDE_INT begin_unneeded = offset - s_info->offset; + HOST_WIDE_INT end_unneeded = begin_unneeded + width; + begin_unneeded = MAX (begin_unneeded, 0); + end_unneeded = MIN (end_unneeded, s_info->width); + for (i = begin_unneeded; i < end_unneeded; ++i) + set_position_unneeded (s_info, i); + } } else if (s_info->rhs) /* Need to see if it is possible for this store to overwrite @@ -1535,8 +1566,8 @@ record_store (rtx body, bb_info_t bb_inf store_info->positions_needed.small_bitmask = lowpart_bitmask (width); } store_info->group_id = group_id; - store_info->begin = offset; - store_info->end = offset + width; + store_info->offset = offset; + store_info->width = width; store_info->is_set = GET_CODE (body) == SET; store_info->rhs = rhs; store_info->const_rhs = const_rhs; @@ -1700,39 +1731,38 @@ look_for_hardregs (rtx x, const_rtx pat } /* Helper function for replace_read and record_store. - Attempt to return a value stored in STORE_INFO, from READ_BEGIN - to one before READ_END bytes read in READ_MODE. Return NULL + Attempt to return a value of mode READ_MODE stored in STORE_INFO, + consisting of READ_WIDTH bytes starting from READ_OFFSET. Return NULL if not successful. If REQUIRE_CST is true, return always constant. */ static rtx get_stored_val (store_info *store_info, machine_mode read_mode, - HOST_WIDE_INT read_begin, HOST_WIDE_INT read_end, + HOST_WIDE_INT read_offset, HOST_WIDE_INT read_width, basic_block bb, bool require_cst) { machine_mode store_mode = GET_MODE (store_info->mem); - int shift; - int access_size; /* In bytes. */ + HOST_WIDE_INT gap; rtx read_reg; /* To get here the read is within the boundaries of the write so shift will never be negative. Start out with the shift being in bytes. */ if (store_mode == BLKmode) - shift = 0; + gap = 0; else if (BYTES_BIG_ENDIAN) - shift = store_info->end - read_end; + gap = ((store_info->offset + store_info->width) + - (read_offset + read_width)); else - shift = read_begin - store_info->begin; - - access_size = shift + GET_MODE_SIZE (read_mode); - - /* From now on it is bits. */ - shift *= BITS_PER_UNIT; + gap = read_offset - store_info->offset; - if (shift) - read_reg = find_shift_sequence (access_size, store_info, read_mode, shift, - optimize_bb_for_speed_p (bb), - require_cst); + if (gap != 0) + { + HOST_WIDE_INT shift = gap * BITS_PER_UNIT; + HOST_WIDE_INT access_size = GET_MODE_SIZE (read_mode) + gap; + read_reg = find_shift_sequence (access_size, store_info, read_mode, + shift, optimize_bb_for_speed_p (bb), + require_cst); + } else if (store_mode == BLKmode) { /* The store is a memset (addr, const_val, const_size). */ @@ -1835,7 +1865,7 @@ replace_read (store_info *store_info, in start_sequence (); bb = BLOCK_FOR_INSN (read_insn->insn); read_reg = get_stored_val (store_info, - read_mode, read_info->begin, read_info->end, + read_mode, read_info->offset, read_info->width, bb, false); if (read_reg == NULL_RTX) { @@ -1986,8 +2016,8 @@ check_mem_read_rtx (rtx *loc, bb_info_t read_info = read_info_type_pool.allocate (); read_info->group_id = group_id; read_info->mem = mem; - read_info->begin = offset; - read_info->end = offset + width; + read_info->offset = offset; + read_info->width = width; read_info->next = insn_info->read_rec; insn_info->read_rec = read_info; if (group_id < 0) @@ -2013,8 +2043,11 @@ check_mem_read_rtx (rtx *loc, bb_info_t fprintf (dump_file, " processing const load gid=%d[BLK]\n", group_id); else - fprintf (dump_file, " processing const load gid=%d[%d..%d)\n", - group_id, (int)offset, (int)(offset+width)); + { + fprintf (dump_file, " processing const load gid=%d", group_id); + print_range (dump_file, offset, width); + fprintf (dump_file, "\n"); + } } while (i_ptr) @@ -2052,19 +2085,19 @@ check_mem_read_rtx (rtx *loc, bb_info_t else { if (store_info->rhs - && offset >= store_info->begin - && offset + width <= store_info->end + && known_subrange_p (offset, width, store_info->offset, + store_info->width) && all_positions_needed_p (store_info, - offset - store_info->begin, + offset - store_info->offset, width) && replace_read (store_info, i_ptr, read_info, insn_info, loc, bb_info->regs_live)) return; /* The bases are the same, just see if the offsets - overlap. */ - if ((offset < store_info->end) - && (offset + width > store_info->begin)) + could overlap. */ + if (ranges_may_overlap_p (offset, width, store_info->offset, + store_info->width)) remove = true; } } @@ -2119,11 +2152,10 @@ check_mem_read_rtx (rtx *loc, bb_info_t if (store_info->rhs && store_info->group_id == -1 && store_info->cse_base == base - && width != -1 - && offset >= store_info->begin - && offset + width <= store_info->end + && known_subrange_p (offset, width, store_info->offset, + store_info->width) && all_positions_needed_p (store_info, - offset - store_info->begin, width) + offset - store_info->offset, width) && replace_read (store_info, i_ptr, read_info, insn_info, loc, bb_info->regs_live)) return; @@ -2775,16 +2807,19 @@ scan_stores (store_info *store_info, bit group_info *group_info = rtx_group_vec[store_info->group_id]; if (group_info->process_globally) - for (i = store_info->begin; i < store_info->end; i++) - { - int index = get_bitmap_index (group_info, i); - if (index != 0) - { - bitmap_set_bit (gen, index); - if (kill) - bitmap_clear_bit (kill, index); - } - } + { + HOST_WIDE_INT end = store_info->offset + store_info->width; + for (i = store_info->offset; i < end; i++) + { + int index = get_bitmap_index (group_info, i); + if (index != 0) + { + bitmap_set_bit (gen, index); + if (kill) + bitmap_clear_bit (kill, index); + } + } + } store_info = store_info->next; } } @@ -2834,9 +2869,9 @@ scan_reads (insn_info_t insn_info, bitma { if (i == read_info->group_id) { - if (read_info->begin > read_info->end) + if (!known_size_p (read_info->width)) { - /* Begin > end for block mode reads. */ + /* Handle block mode reads. */ if (kill) bitmap_ior_into (kill, group->group_kill); bitmap_and_compl_into (gen, group->group_kill); @@ -2846,7 +2881,8 @@ scan_reads (insn_info_t insn_info, bitma /* The groups are the same, just process the offsets. */ HOST_WIDE_INT j; - for (j = read_info->begin; j < read_info->end; j++) + HOST_WIDE_INT end = read_info->offset + read_info->width; + for (j = read_info->offset; j < end; j++) { int index = get_bitmap_index (group, j); if (index != 0) @@ -3265,7 +3301,8 @@ dse_step5 (void) HOST_WIDE_INT i; group_info *group_info = rtx_group_vec[store_info->group_id]; - for (i = store_info->begin; i < store_info->end; i++) + HOST_WIDE_INT end = store_info->offset + store_info->width; + for (i = store_info->offset; i < end; i++) { int index = get_bitmap_index (group_info, i);