public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Shubham Narlawar <gsocshubham@gmail.com>
To: GCC Development <gcc@gcc.gnu.org>
Subject: Hoisting built-in call out of loop - LIM pass [tree-ssa-loop-im.c]
Date: Wed, 1 Jun 2022 19:27:59 +0530	[thread overview]
Message-ID: <CAN=hqDBEiLTgMm8uFNvZ2Gd3EWHqWQC2P52fK_yWkywy4uchng@mail.gmail.com> (raw)

Hello,

[1] I want to achieve hosting of a custom built-in call out of loop that
loads an immediate value.

    for (int i = 0; i < 4000; i++) {
       _9 = (unsigned int) _1;
       slli_6 = _9 << 8;
       srli_36 = slli_6 >> 8;
       li_37 = __builtin_load_immediate (15);        //I want to hoist this
out of loop which will cause hoisting of add_39 stmt also
       add_39 = srli_36 + li_37;
       _10 = __builtin_foo (add_39, 1, _9);
    }

First 5 instructions in the above loop are being inserted by a custom
gimple plugin whenever it sees a __builtin_foo().

LICM pass () could hoist below instructions out of loop -

       _9 = (unsigned int) _1;
       slli_6 = _9 << 8;
       srli_36 = slli_6 >> 8;

I want to hoist below gimple statement out of loop

li_22 = __builtin_riscv_load_immediate(15);      //BUILTIN_MD

I am generating above builtin call using a custom GCC gimple plugin using -

              tree li_tmp_name = make_temp_ssa_name (integer_type_node,
NULL, "li");
              tree load = build_int_cst (unsigned_type_node, 15);

              gcall *li_stmt = gimple_build_call (decl,
1);                          //where decl is function_decl
              gimple_call_set_lhs (li_stmt, li_tmp_name);
              gimple_call_set_arg (li_stmt, 0, load);
              gsi_insert_after (&gsi, li_stmt, GSI_NEW_STMT);

How do I make a GIMPLE function call as const such that loop invariant code
motion hoist it out of the loop.

[2] I tried below approaches to make it happen -

a. I made load_immediate decl as constant but that did not help
TREE_CONSTANT(decl) = 1

b. I teached licm pass to forcefull move out __builtin_load_immediate() by
introducing various checks but in the end, it alters function cfg and some
other pass like ""tree-ssa-loop-manip.c"" crashes here -

          /* We should have met DEF_BB along the way.  */
          gcc_assert (pred != ENTRY_BLOCK_PTR_FOR_FN (cfun));

From above approaches, making changes in licm pass is proving to be costly
and inappropriate. Is there any other way I can achieve it? I am guessing
making it a constant gimple function call with no side effects will be
hoisted automatically by LICM.

If yes, how can I make a gimple call as constant so that it is hoisted out
by LICM. Also, please suggest any other approaches to achieve it.

Thanks and Regards,
Shubham

             reply	other threads:[~2022-06-01 13:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-01 13:57 Shubham Narlawar [this message]
2022-06-02  8:26 ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN=hqDBEiLTgMm8uFNvZ2Gd3EWHqWQC2P52fK_yWkywy4uchng@mail.gmail.com' \
    --to=gsocshubham@gmail.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).