From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by sourceware.org (Postfix) with ESMTPS id A2A16398B166 for ; Tue, 27 Apr 2021 13:05:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A2A16398B166 Received: by mail-ed1-x534.google.com with SMTP id i3so44159192edt.1 for ; Tue, 27 Apr 2021 06:05: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:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=w5ROsDahIGvgY7VPx1uGiEtf49wnb7tGaP55BFkxE1I=; b=l8/hZIV9z/C7+3T7x8FROek36F1hvD4QCUYmHRiDn2ZLSJuQYvsT3PpQngndfjZuSS OFXKpVIY4m6k1E9CkCLtZ2d9dC4hQKIa0MmE/4CYvko4H7gQbYmCmdc/TrqVi3L4K1j9 7Rg54CGb1DfdOJRXFIMj+f1Eu4BQojDAvCdaSuwSlLxbR6OmbCvvfw8AJ8gYOqWXIgXf 00P63pf3As9JulovJ13LmEEMKamCy/H8cPh94597criDZmTnlCYbJDTGe1CNeKNUYxwj qTITS+NDLamESgphcm9Da77T75qxpz/cIhfHw5sGcyoDUqDwZxiiomVAmmpn4MHXNyt4 HCSg== X-Gm-Message-State: AOAM533gJSlwaOav8lRnyFxBQFYJ41JnwSC+yJL2FPWDz0cJ6Yydn+yE USu37a9DgYgQ4XBituFiIP67UkCK9ishqrjmPOg= X-Google-Smtp-Source: ABdhPJx8/lqxJ5yne01Z75YbQf+G/GDxXrdUe3wK78MsFIkrFQhglHzwvFaoOUHZZmBWDqcXi4xOexKQP4Oc4EknJHI= X-Received: by 2002:a05:6402:2d6:: with SMTP id b22mr4216954edx.274.1619528756696; Tue, 27 Apr 2021 06:05:56 -0700 (PDT) MIME-Version: 1.0 References: <20210427011426.479089-1-hjl.tools@gmail.com> <20210427011426.479089-2-hjl.tools@gmail.com> In-Reply-To: <20210427011426.479089-2-hjl.tools@gmail.com> From: Richard Biener Date: Tue, 27 Apr 2021 15:05:45 +0200 Message-ID: Subject: Re: [PATCH v3 1/2] op_by_pieces_d::run: Change a while loop to a do-while loop To: "H.J. Lu" Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.9 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 autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Tue, 27 Apr 2021 13:05:59 -0000 On Tue, Apr 27, 2021 at 3:14 AM H.J. Lu wrote: > > Change a while loop in op_by_pieces_d::run to a do-while loop to prepare > for offset adjusted operation for the remaining bytes on the last piece > operation of a memory region. OK. Thanks, Richard. > PR middl-end/90773 > * expr.c (op_by_pieces_d::get_usable_mode): New member function. > (op_by_pieces_d::run): Cange a while loop to a do-while loop. > --- > gcc/expr.c | 76 +++++++++++++++++++++++++++++++++++++----------------- > 1 file changed, 53 insertions(+), 23 deletions(-) > > diff --git a/gcc/expr.c b/gcc/expr.c > index a0e19465965..07cb64427c9 100644 > --- a/gcc/expr.c > +++ b/gcc/expr.c > @@ -1041,6 +1041,9 @@ pieces_addr::maybe_postinc (HOST_WIDE_INT size) > > class op_by_pieces_d > { > + private: > + scalar_int_mode get_usable_mode (scalar_int_mode mode, unsigned int); > + > protected: > pieces_addr m_to, m_from; > unsigned HOST_WIDE_INT m_len; > @@ -1108,6 +1111,25 @@ op_by_pieces_d::op_by_pieces_d (rtx to, bool to_load, > m_align = align; > } > > +/* This function returns the largest usable integer mode for LEN bytes > + whose size is no bigger than size of MODE. */ > + > +scalar_int_mode > +op_by_pieces_d::get_usable_mode (scalar_int_mode mode, unsigned int len) > +{ > + unsigned int size; > + do > + { > + size = GET_MODE_SIZE (mode); > + if (len >= size && prepare_mode (mode, m_align)) > + break; > + /* NB: widest_int_mode_for_size checks SIZE > 1. */ > + mode = widest_int_mode_for_size (size); > + } > + while (1); > + return mode; > +} > + > /* This function contains the main loop used for expanding a block > operation. First move what we can in the largest integer mode, > then go to successively smaller modes. For every access, call > @@ -1116,42 +1138,50 @@ op_by_pieces_d::op_by_pieces_d (rtx to, bool to_load, > void > op_by_pieces_d::run () > { > - while (m_max_size > 1 && m_len > 0) > + if (m_len == 0) > + return; > + > + /* NB: widest_int_mode_for_size checks M_MAX_SIZE > 1. */ > + scalar_int_mode mode = widest_int_mode_for_size (m_max_size); > + mode = get_usable_mode (mode, m_len); > + > + do > { > - scalar_int_mode mode = widest_int_mode_for_size (m_max_size); > + unsigned int size = GET_MODE_SIZE (mode); > + rtx to1 = NULL_RTX, from1; > > - if (prepare_mode (mode, m_align)) > + while (m_len >= size) > { > - unsigned int size = GET_MODE_SIZE (mode); > - rtx to1 = NULL_RTX, from1; > + if (m_reverse) > + m_offset -= size; > > - while (m_len >= size) > - { > - if (m_reverse) > - m_offset -= size; > + to1 = m_to.adjust (mode, m_offset); > + from1 = m_from.adjust (mode, m_offset); > > - to1 = m_to.adjust (mode, m_offset); > - from1 = m_from.adjust (mode, m_offset); > + m_to.maybe_predec (-(HOST_WIDE_INT)size); > + m_from.maybe_predec (-(HOST_WIDE_INT)size); > > - m_to.maybe_predec (-(HOST_WIDE_INT)size); > - m_from.maybe_predec (-(HOST_WIDE_INT)size); > + generate (to1, from1, mode); > > - generate (to1, from1, mode); > + m_to.maybe_postinc (size); > + m_from.maybe_postinc (size); > > - m_to.maybe_postinc (size); > - m_from.maybe_postinc (size); > + if (!m_reverse) > + m_offset += size; > > - if (!m_reverse) > - m_offset += size; > + m_len -= size; > + } > > - m_len -= size; > - } > + finish_mode (mode); > > - finish_mode (mode); > - } > + if (m_len == 0) > + return; > > - m_max_size = GET_MODE_SIZE (mode); > + /* NB: widest_int_mode_for_size checks SIZE > 1. */ > + mode = widest_int_mode_for_size (size); > + mode = get_usable_mode (mode, m_len); > } > + while (1); > > /* The code above should have handled everything. */ > gcc_assert (!m_len); > -- > 2.31.1 >