public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [RFC/RFA] [PATCH 08/12] Add a new pass for naive CRC loops detection
@ 2024-06-04 13:41 Mariam Arutunian
  2024-06-08 21:47 ` Jeff Law
  0 siblings, 1 reply; 12+ messages in thread
From: Mariam Arutunian @ 2024-06-04 13:41 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches, Jeff Law

[-- Attachment #1: Type: text/plain, Size: 4958 bytes --]

Sorry for the late response; somehow, I didn't receive the last few messages.

>>* Am 30.05.2024 um 00:31 schrieb Jeff Law <jeffreyalaw@gmail.com <jeffreyalaw@gmail.com>>:
*>> >>* 
*>> >>>* On 5/28/24 1:01 AM, Richard Biener wrote:
*>>>>* On Fri, May 24, 2024 at 10:46 AM Mariam Arutunian
*>>>>* <mariamarutunian@gmail.com <mariamarutunian@gmail.com>> wrote:
*>>>> >>>>* This patch adds a new compiler pass aimed at identifying
naive CRC implementations,
*>>>>* characterized by the presence of a loop calculating a CRC
(polynomial long division).
*>>>>* Upon detection of a potential CRC, the pass prints an
informational message.
*>>>> >>>>* Performs CRC optimization if optimization level is >= 2,
*>>>>* besides optimizations for size and if fno_gimple_crc_optimization given.
*>>>> >>>>* This pass is added for the detection and optimization of
naive CRC implementations,
*>>>>* improving the efficiency of CRC-related computations.
*>>>> >>>>* This patch includes only initial fast checks for filtering
out non-CRCs,
*>>>>* detected possible CRCs verification and optimization parts will
be provided in subsequent patches.
*>>>* Just a few quick questions - I'm waiting for a revision with
Jeffs comments cleared before having a closer look.  The patch does
*>>>* nothing but analyze right now, correct?  I assume a later patch will
*>>>* fill in stuff in ::execute and use the return value of
*>>>* loop_may_calculate_crc (it's a bit odd to review such a "split"
*>>>* thing).
*>>* We split it up on functional chunks.  I think if it gets approved
it probably should go in atomically since it makes no sense to commit
the first pass recognition filter without the validation step or the
validation step without the codegen step.
*>> >>* So consider the break down strictly for review convenience.
*>> >> >>>* I think what this does fits final value replacement which
lives in tree-scalar-evolution.cc and works from the loop-closed PHIs,
trying
*>>>* to replace those.  I'm not sure we want to have a separate pass for
*>>>* this.  Consider a loop calculating two or four CRCs in parallel,
replacing LC PHIs one-by-one should be able to handle this.
*>>* I suspect that'll be quite hard for both the "does this generally
look like a CRC loop" code as well as the "validate this is a CRC
loop" code.
*>> >>* Mariam, your thoughts on whether or not those two phases could
handle a loop with two CRC calculations inside, essentially creating
two calls to our new builtins?
*


It is feasible, but it would likely demand considerable effort and
additional work to implement effectively.

>The key would be to only simulate the use-def cycle from the loop-closed PHI (plus the loop control of course, but miter/SCEV should be enough there) and just replace that LC PHI, leaving loop DCE to DCE.

Thank you, this is a good idea to just replace the PHI and leave the
loop to DCE to remove only single CRC parts.
However, if you mean using the symbolic executor to only simulate the
use-def cycle and loop control, instead of the whole control flow of
the loop, it won't be sufficient.
Some calculations may occur under certain conditions, which must also
be taken into account.

This situation is solvable, but it requires more complex work to
create a graph of the statements that must be executed.
We can consider this as a potential improvement for later.

The current pass only verifies cases where a single CRC calculation is
performed within the loop. During the verification phase,
I ensure that there are no other calculations aside from those
necessary for the considered CRC computation.

Also, when I was investigating the bitwise CRC implementations used in
different software, in all cases the loop was calculating just one CRC
and no other calculations were done.
Thus, in almost all cases, the first phase will filter out non-CRCs,
and during the second phase, only real CRCs with no other calculations
will be executed.
This ensures that unnecessary statements won't be executed in most cases.

Leaving the loop to DCE will simplify the process of removing parts
connected to a single CRC calculation.
However, since now we detect a loop that only calculates a single CRC,
we can entirely remove it at this stage without additional checks.

>If we really want a separate pass (or utility to work on a single loop) then we might consider moving some of the final value replacement code that doesn’t work with only SCEV there as well.  There’s also special code in loop distribution for strlen recognition now, not exactly fitting in.
>

>Note I had patches to do final value replacement on demand from CD-DCE when it figures a loop has no side effects besides of its reduction outputs (still want to pick this up at some point again).

Oh, this could provide useful insights for our implementation.

Thanks,
Mariam

>Richard > >>* Jeff *>>

^ permalink raw reply	[flat|nested] 12+ messages in thread
* [RFC/RFA] [PATCH 08/12] Add a new pass for naive CRC loops detection
@ 2024-05-24  8:42 Mariam Arutunian
  2024-05-28  4:20 ` Jeff Law
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Mariam Arutunian @ 2024-05-24  8:42 UTC (permalink / raw)
  To: GCC Patches


[-- Attachment #1.1: Type: text/plain, Size: 1683 bytes --]

This patch adds a new compiler pass aimed at identifying naive CRC
implementations,
characterized by the presence of a loop calculating a CRC (polynomial long
division).
Upon detection of a potential CRC, the pass prints an informational message.

Performs CRC optimization if optimization level is >= 2,
besides optimizations for size and if fno_gimple_crc_optimization given.

This pass is added for the detection and optimization of naive CRC
implementations,
improving the efficiency of CRC-related computations.

This patch includes only initial fast checks for filtering out non-CRCs,
detected possible CRCs verification and optimization parts will be provided
in subsequent patches.

  gcc/

    * Makefile.in (OBJS): Add gimple-crc-optimization.o.
    * common.opt (fgimple-crc-optimization): New option.
    * doc/invoke.texi (-fgimple-crc-optimization): Add documentation.
    * gimple-crc-optimization.cc: New file.
    * gimple.cc (set_phi_stmts_not_visited): New function.
    (set_gimple_stmts_not_visited): Likewise.
    (set_bbs_stmts_not_visited): Likewise.
    * gimple.h (set_gimple_stmts_not_visited): New extern function
declaration.
    (set_phi_stmts_not_visited): New extern function declaration.
    (set_bbs_stmts_not_visited): New extern function declaration.
    * opts.cc (default_options_table): Add OPT_fgimple_crc_optimization.
    (enable_fdo_optimizations): Enable gimple-crc-optimization.
    * passes.def (pass_crc_optimization): Add new pass.
    * timevar.def (TV_GIMPLE_CRC_OPTIMIZATION): New timevar.
    * tree-pass.h (make_pass_crc_optimization): New extern function
declaration.

Signed-off-by: Mariam Arutunian <mariamarutunian@gmail.com>

[-- Attachment #2: 0008-Add-a-new-pass-for-naive-CRC-loops-detection.patch --]
[-- Type: application/x-patch, Size: 39685 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-06-19 15:27 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-04 13:41 [RFC/RFA] [PATCH 08/12] Add a new pass for naive CRC loops detection Mariam Arutunian
2024-06-08 21:47 ` Jeff Law
2024-06-19 14:29   ` Mariam Arutunian
  -- strict thread matches above, loose matches on Subject: below --
2024-05-24  8:42 Mariam Arutunian
2024-05-28  4:20 ` Jeff Law
2024-05-29 11:12   ` Mariam Arutunian
2024-06-08 22:00     ` Jeff Law
2024-06-19 15:27       ` Mariam Arutunian
2024-05-28  7:01 ` Richard Biener
2024-05-29 22:30   ` Jeff Law
2024-05-30  7:33     ` Richard Biener
2024-05-29 12:43 ` David Malcolm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).