public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Condition execution optimization with gcc 7.5
@ 2023-05-09  7:54 Benjamin Minguez
  2023-05-09  9:49 ` Kyrylo Tkachov
  0 siblings, 1 reply; 8+ messages in thread
From: Benjamin Minguez @ 2023-05-09  7:54 UTC (permalink / raw)
  To: gcc-help

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

Hello everyone,

I'm trying to optimize an application that contains a lot of branches. I'm targeting armv8 processors and I'm using GCC 7.5.0 for compatibility reason.
As the original application is similar to NGINX, I investigated on NGINX. I'm focusing on the HTTP header parsing. Basically, the algorithm parse byte per byte and based on the value stores some variables.
Here is an example, /src/http/ngx_http_parse.c: ngx_http_parse_header_line
                if (c) {
                    hash = ngx_hash(0, c);
                    r->lowcase_header[0] = c;
                    i = 1;
                    break;
                }

                if (ch == '_') {
                    if (allow_underscores) {
                        hash = ngx_hash(0, ch);
                        r->lowcase_header[0] = ch;
                        i = 1;

                    } else {
                        r->invalid_header = 1;
                    }

                    break;
                }
Also, most of branches are not predictable because it compares against data coming from the network.
From these observations, I looked at the conditional execution optimization step in GCC and I found this function that should do the work: cond_exec_find_if_block. And how to customize the decision to use conditional instructions:
                #define MAX_CONDITIONAL_EXECUTE arm_max_conditional_execute ()
                int
                arm_max_conditional_execute (void)
                {
                  return max_insns_skipped;
                }
                static int max_insns_skipped = 5;

I tried to compile NGNIX in -O2 (that should enable if-conversion2) but I did not noticed any change in the code. I enable GCC debug (-da) and also add some debug in this function and I figure out that targetm.have_conditional_execution is set to false.

First, do you how to switch this variable to true. I guess it is an option during the configuration step of GCC.
Then, I know  that the decision to use conditional execution is based on the extra cost added to compute both branches compare to the cost of a branch. In this specific case, branches are miss predicted and the cost is, indeed, high. Do you think that increasing the max_insns_skipped will be enough to help GCC to use conditional execution?

Thank you in advance for your answers.

Best,
Benjamin Minguez

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

end of thread, other threads:[~2023-05-23  6:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-09  7:54 Condition execution optimization with gcc 7.5 Benjamin Minguez
2023-05-09  9:49 ` Kyrylo Tkachov
2023-05-10  6:42   ` Benjamin Minguez
2023-05-17  8:17     ` Benjamin Minguez
2023-05-18 11:02       ` Richard Earnshaw (lists)
2023-05-22 15:43         ` Benjamin Minguez
2023-05-22 16:12           ` Richard Earnshaw (lists)
2023-05-23  6:36             ` Benjamin Minguez

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).