public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Qing Zhao <QING.ZHAO@ORACLE.COM>
To: Richard Sandiford <richard.sandiford@arm.com>
Cc: Segher Boessenkool <segher@kernel.crashing.org>,
	Kees Cook <keescook@chromium.org>,
	Kees Cook via Gcc-patches <gcc-patches@gcc.gnu.org>,
	Jakub Jelinek <jakub@redhat.com>, Uros Bizjak <ubizjak@gmail.com>,
	"Rodriguez Bahena, Victor" <victor.rodriguez.bahena@intel.com>
Subject: Re: PING [Patch][Middle-end]Add -fzero-call-used-regs=[skip|used-gpr|all-gpr|used|all]
Date: Mon, 14 Sep 2020 15:24:45 -0500	[thread overview]
Message-ID: <EA9F204F-1E0B-40B6-9594-8F35B3C85920@ORACLE.COM> (raw)
In-Reply-To: <mpt7dsw6u81.fsf@arm.com>



> On Sep 14, 2020, at 2:20 PM, Richard Sandiford <richard.sandiford@arm.com> wrote:
> 
> Qing Zhao <QING.ZHAO@ORACLE.COM <mailto:QING.ZHAO@ORACLE.COM>> writes:
>>> On Sep 14, 2020, at 11:33 AM, Richard Sandiford <richard.sandiford@arm.com> wrote:
>>> 
>>> Qing Zhao <QING.ZHAO@ORACLE.COM> writes:
>>>>> Like I mentioned earlier though, passes that run after
>>>>> pass_thread_prologue_and_epilogue can use call-clobbered registers that
>>>>> weren't previously used.  For example, on x86_64, the function might
>>>>> not use %r8 when the prologue, epilogue and returns are generated,
>>>>> but pass_regrename might later introduce a new use of %r8.  AIUI,
>>>>> the “used” version of the new command-line option is supposed to clear
>>>>> %r8 in these circumstances, but it wouldn't do so if the data was
>>>>> collected at the point that the return is generated.
>>>> 
>>>> Thanks for the information.
>>>> 
>>>>> 
>>>>> That's why I think it's more robust to do this later (at the beginning
>>>>> of pass_late_compilation) and insert the zeroing before returns that
>>>>> already exist.
>>>> 
>>>> Yes, looks like it’s not correct to insert the zeroing at the time when prologue, epilogue and return are generated.
>>>> As I also checked, “return” might be also generated as late as pass “pass_delay_slots”,  So, shall we move the
>>>> New pass as late as possible?
>>> 
>>> If we insert the zeroing before pass_delay_slots and describe the
>>> result correctly, pass_delay_slots should do the right thing.
>>> 
>>> Describing the result correctly includes ensuring that the cleared
>>> registers are treated as live on exit from the function, so that the
>>> zeroing doesn't get deleted again, or skipped by pass_delay_slots.
>> 
>> In the current implementation for x86, when we generating a zeroing insn as the following:
>> 
>> (insn 18 16 19 2 (set (reg:SI 1 dx)
>>        (const_int 0 [0])) "t10.c":11:1 -1
>>     (nil))
>> (insn 19 18 20 2 (unspec_volatile [
>>            (reg:SI 1 dx)
>>        ] UNSPECV_PRO_EPILOGUE_USE) "t10.c":11:1 -1
>>     (nil))
>> 
>> i.e, after each zeroing insn, the register that is zeroed is marked as “UNSPECV_PRO_EPILOGUE_USE”, 
>> By doing this, we can avoid this zeroing insn from being deleted or skipped. 
>> 
>> Is doing this enough to describe the result correctly?
>> Is there other thing we need to do in addition to this?
> 
> I guess that works, but I think it would be better to abstract
> EPILOGUE_USES into a new target-independent wrapper function that
> (a) returns true if EPILOGUE_USES itself returns true and (b) returns
> true for registers that need to be zero on return, if the zeroing
> instructions have already been inserted.  The places that currently
> test EPILOGUE_USES should then test this new wrapper function instead.

Okay, I see. 
Looks like that EPILOGUE_USES is used in df-scan.c to compute the data flow information. If EPILOUGE_USES return true
for registers that need to be zeroed on return, those registers will be included in the data flow information, as a result, later
passes will not be able to delete them. 

This sounds to be a cleaner approach than the current one that marks the registers  “UNSPECV_PRO_EPILOGUE_USE”. 

A more detailed implementation question on this: 
Where should I put this new target-independent wrapper function in? Which header file will be a proper place to hold this new function?

> 
> After inserting the zeroing instructions, the pass should recompute the
> live-out sets based on this.

Is only computing the live-out sets of the block that including the return insn enough? Or we should re-compute the whole procedure? 

Which utility routine I should use to recompute the live-out sets?

> 
>>>>> But the dataflow information has to be correct between
>>>>> pass_thread_prologue_and_epilogue and pass_free_cfg, otherwise
>>>>> any pass in that region could clobber the registers in the same way.
>>>> 
>>>> You mean, the data flow information will be not correct after pass_free_cfg? 
>>>> “pass_delay_slots” is after “pass_free_cfg”,  and there might be new “return” generated in “pass_delay_slots”, 
>>>> If we want to generate zeroing for the new “return” which was generated in “pass_delay_slots”, can we correctly to do so?
>>> 
>>> …the zeroing has to be done before pass_free_cfg, because the information
>>> isn't reliable after that point.  I think it would make sense to do it
>>> before pass_compute_alignments, because inserting the zeros will affect
>>> alignment.
>> 
>> Okay. 
>> 
>> Then there is another problem:  what about the new “return”s that are generated at pass_delay_slots?
>> 
>> Should we generate the zeroing for these new returns? Since the data flow information might not be correct at this pass,
>> It looks like that there is no correct way to add the zeroing insn for these new “return”, then, what should we do about this?
> 
> pass_delay_slots isn't a problem.  It doesn't change *what* happens
> on each return path, it just changes how the instructions to achieve
> it are arranged.
> 
> So e.g. if every path through the function clears register R before
> pass_delay_slots, and if that clearing is represented as being necessary,
> then every path through the function will clear register R after the pass
> as well.

Okay, I might now understand what you mean here.

My understanding is:

In our new pass that is put in the beginning of the pass_late_compilation, I,e pass_zero_call_used_regs;

      PUSH_INSERT_PASSES_WITHIN (pass_late_compilation)
++++  NEXT_PASS (pass_zero_call_used_regs);
          NEXT_PASS (pass_compute_alignments);
          NEXT_PASS (pass_variable_tracking);
          NEXT_PASS (pass_free_cfg);
          NEXT_PASS (pass_machine_reorg);
          NEXT_PASS (pass_cleanup_barriers);
          NEXT_PASS (pass_delay_slots);

When we scan the EXIT BLOCK of the routine, all the return insns have already been there.
The later passes including “pass_delay_slots” will not generate additional returns anymore,  they might just call “target.gen_return” or “target.gen_simple_return() to replace 
“ret_rtx” or “simple_ret_rtx” ?


> 
>>> For extra safety, you could/should also check targetm.hard_regno_scratch_ok
>>> to see whether there's a target-specific reason why a register can't
>>> be clobbered.
>> 
>> /* Return true if is OK to use a hard register REGNO as scratch register
>>   in peephole2.  */
>> DEFHOOK
>> (hard_regno_scratch_ok,
>> 
>> 
>> Is this checking only valid for pass_peephole2?
> 
> No, that comment looks out of date.  The hook is already used in
> postreload, for example.

Okay, I see.

thanks.

Qing
> 
> Thanks,
> Richard


  reply	other threads:[~2020-09-14 20:24 UTC|newest]

Thread overview: 188+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-04 19:01 [PATCH 1/4] matcher-1.m: Change return type to int H.J. Lu
2020-05-04 19:01 ` [PATCH 2/4] x86: Add -mzero-caller-saved-regs=[skip|used-gpr|all-gpr|used|all] H.J. Lu
2020-05-04 23:19   ` Rodriguez Bahena, Victor
2020-05-05  8:14   ` Uros Bizjak
2020-05-05  8:20     ` Richard Biener
2020-07-14 14:45       ` [Patch][Middle-end]Add -fzero-call-used-regs=[skip|used-gpr|all-gpr|used|all] Qing Zhao
2020-07-16 13:17         ` Victor Rodriguez
2020-07-28 20:05         ` PING " Qing Zhao
2020-07-31 17:57           ` Uros Bizjak
2020-08-03 15:42             ` Qing Zhao
2020-08-04  7:35               ` Richard Biener
2020-08-04 18:23                 ` H.J. Lu
2020-08-05  7:06                   ` Richard Biener
2020-08-05 12:26                     ` H.J. Lu
2020-08-05 12:30                       ` Richard Biener
2020-08-05 12:34                         ` H.J. Lu
2020-08-05 14:45                           ` H.J. Lu
2020-08-05 15:00                             ` Qing Zhao
2020-08-05 18:53                             ` Richard Biener
2020-08-05 19:08                               ` H.J. Lu
2020-08-05 20:22                               ` Qing Zhao
2020-08-06  8:37                                 ` Richard Biener
2020-08-06 15:45                                   ` Qing Zhao
2020-08-06 20:45                                   ` Kees Cook
2020-08-07  6:21                                     ` Richard Biener
2020-08-07 16:15                                       ` Qing Zhao
2020-08-05 21:35                 ` Qing Zhao
2020-08-06  8:31                   ` Richard Biener
2020-08-06  8:41                     ` Jakub Jelinek
2020-08-06  9:31                       ` Uros Bizjak
2020-08-06 14:56                     ` Qing Zhao
2020-08-06 23:37                     ` Segher Boessenkool
2020-08-07 16:06                       ` Qing Zhao
2020-08-07 22:59                         ` Segher Boessenkool
2020-08-10 16:34                           ` Qing Zhao
2020-08-10 19:51                             ` Qing Zhao
2020-08-19 20:05                       ` Qing Zhao
2020-08-19 22:57                         ` Segher Boessenkool
2020-08-19 23:27                           ` Qing Zhao
2020-08-24 14:47                             ` Rodriguez Bahena, Victor
2020-08-24 17:59                               ` Segher Boessenkool
2020-08-24 18:48                                 ` Qing Zhao
2020-08-24 20:26                                   ` Segher Boessenkool
2020-08-24 20:49                                     ` Qing Zhao
2020-09-04 15:18                                       ` Segher Boessenkool
2020-09-04 17:34                                         ` H.J. Lu
2020-09-04 18:09                                           ` Segher Boessenkool
2020-09-04 18:52                                             ` H.J. Lu
2020-09-07 14:06                                               ` Segher Boessenkool
2020-09-07 15:58                                                 ` H.J. Lu
2020-09-08 16:43                                                   ` Qing Zhao
2020-09-10 22:05                                                     ` Segher Boessenkool
2020-09-10 22:50                                                       ` Qing Zhao
2020-09-11 17:18                                                         ` Segher Boessenkool
2020-09-11 19:53                                                           ` Qing Zhao
2020-08-24 17:49                             ` Segher Boessenkool
2020-08-24 18:02                               ` Qing Zhao
2020-08-24 20:20                                 ` Segher Boessenkool
2020-08-24 20:43                                   ` Qing Zhao
2020-08-25  6:41                                     ` Uros Bizjak
2020-08-25 14:05                                       ` Qing Zhao
2020-08-25 22:31                                         ` Qing Zhao
2020-09-04 15:26                                     ` Segher Boessenkool
2020-08-25 21:54                                   ` Qing Zhao
2020-09-03 14:29                                     ` Qing Zhao
2020-09-03 15:08                                       ` Qing Zhao
2020-09-03 16:19                                         ` Qing Zhao
2020-09-03 17:13                                       ` Kees Cook
2020-09-03 17:43                                         ` Qing Zhao
2020-09-04  1:23                                           ` Rodriguez Bahena, Victor
2020-09-04 14:18                                             ` Qing Zhao
2020-09-07 13:06                                               ` Rodriguez Bahena, Victor
2020-09-08 15:00                                                 ` Qing Zhao
2020-09-10 19:07                                                   ` Kees Cook
2020-09-10 22:40                                                     ` Qing Zhao
2020-09-11 10:06                                                     ` Richard Sandiford
2020-09-11 16:14                                                       ` Segher Boessenkool
2020-09-11 16:52                                                         ` Qing Zhao
2020-09-11 17:13                                                           ` Segher Boessenkool
2020-09-11 19:40                                                             ` Qing Zhao
2020-09-11 20:05                                                               ` Segher Boessenkool
2020-09-11 20:17                                                                 ` Qing Zhao
2020-09-11 20:36                                                                   ` Segher Boessenkool
2020-09-11 21:12                                                                     ` Qing Zhao
2020-09-11 17:32                                                           ` Richard Sandiford
2020-09-11 20:01                                                             ` Segher Boessenkool
2020-09-11 20:14                                                             ` Qing Zhao
2020-09-11 21:03                                                               ` Segher Boessenkool
2020-09-11 21:29                                                                 ` Qing Zhao
2020-09-11 21:51                                                                   ` Segher Boessenkool
2020-09-11 22:41                                                                     ` Qing Zhao
2020-09-14 23:09                                                                       ` Segher Boessenkool
2020-09-15  3:07                                                                         ` Qing Zhao
2020-09-15 18:51                                                                           ` Segher Boessenkool
2020-09-11 21:44                                                               ` Richard Sandiford
2020-09-11 22:24                                                                 ` Qing Zhao
2020-09-11 22:56                                                                   ` Richard Sandiford
2020-09-14 14:56                                                                     ` Qing Zhao
2020-09-14 16:33                                                                       ` Richard Sandiford
2020-09-14 18:50                                                                         ` Qing Zhao
2020-09-14 19:20                                                                           ` Richard Sandiford
2020-09-14 20:24                                                                             ` Qing Zhao [this message]
2020-09-15  9:11                                                                               ` Richard Sandiford
2020-09-15 15:05                                                                                 ` Qing Zhao
2020-09-15 19:41                                                                                 ` Segher Boessenkool
2020-09-15 22:31                                                                                   ` Qing Zhao
2020-09-15 23:09                                                                                     ` Segher Boessenkool
2020-09-16  1:51                                                                                       ` Qing Zhao
2020-09-16 10:35                                                                                         ` Segher Boessenkool
2020-09-16 20:57                                                                                           ` Qing Zhao
2020-09-17  6:17                                                                                             ` Richard Sandiford
2020-09-17 14:40                                                                                               ` Qing Zhao
2020-09-17 16:27                                                                                                 ` Richard Sandiford
2020-09-17 19:07                                                                                                   ` Qing Zhao
2020-09-22 17:06                                                                                                     ` Richard Sandiford
2020-09-22 21:32                                                                                                       ` Qing Zhao
2020-09-23 11:05                                                                                                         ` Richard Sandiford
2020-09-23 14:14                                                                                                           ` Qing Zhao
2020-09-23 14:32                                                                                                             ` Richard Sandiford
2020-09-23 14:48                                                                                                               ` Qing Zhao
2020-09-23 15:21                                                                                                                 ` Richard Sandiford
2020-09-23 16:08                                                                                                                   ` Qing Zhao
2020-09-23 23:46                                                                                                           ` Segher Boessenkool
2020-09-22 22:37                                                                                                       ` Segher Boessenkool
2020-09-23 14:28                                                                                                         ` Qing Zhao
2020-09-23 23:40                                                                                                           ` Segher Boessenkool
2020-09-17 22:26                                                                                                   ` Segher Boessenkool
2020-09-14 23:35                                                                         ` Segher Boessenkool
2020-09-15 11:46                                                                           ` Richard Sandiford
2020-09-15 19:22                                                                             ` Segher Boessenkool
2020-09-14 23:20                                                                   ` Segher Boessenkool
2020-09-18 20:31                                                                 ` Qing Zhao
2020-09-18 22:51                                                                   ` Segher Boessenkool
2020-09-21 14:13                                                                     ` Qing Zhao
2020-09-21 20:34                                                                       ` Segher Boessenkool
2020-09-21 20:58                                                                         ` Qing Zhao
2020-09-22  0:25                                                                           ` Segher Boessenkool
2020-09-21  7:23                                                                   ` Richard Sandiford
2020-09-21 14:29                                                                     ` Qing Zhao
2020-09-21 15:35                                                                       ` Richard Sandiford
2020-09-21 16:34                                                                         ` Qing Zhao
2020-09-21 19:11                                                                           ` Richard Sandiford
2020-09-21 19:22                                                                             ` Qing Zhao
2020-09-21 20:05                                                                               ` Qing Zhao
2020-09-22 16:31                                                                                 ` Richard Sandiford
2020-09-22 18:25                                                                                   ` Qing Zhao
2020-09-22 18:35                                                                                     ` H.J. Lu
2020-09-22 19:34                                                                                       ` Qing Zhao
2020-09-23 10:43                                                                                         ` Richard Sandiford
2020-09-23 13:54                                                                                           ` Qing Zhao
2020-09-23 14:22                                                                                             ` Richard Sandiford
2020-09-23 14:35                                                                                               ` Qing Zhao
2020-09-23 14:40                                                                                                 ` Richard Sandiford
2020-09-23 14:49                                                                                                   ` Qing Zhao
2020-09-07 14:44                                             ` Segher Boessenkool
2020-09-08 15:05                                               ` Patrick McGehearty
2020-09-10 12:11                                                 ` Richard Sandiford
2020-09-10 14:34                                                   ` Qing Zhao
2020-09-10 14:59                                                     ` Rodriguez Bahena, Victor
2020-09-03 17:48                                         ` Ramana Radhakrishnan
2020-09-03 19:20                                           ` Qing Zhao
2020-09-04 15:43                                         ` Segher Boessenkool
2020-09-04 17:18                                           ` Qing Zhao
2020-09-04 18:04                                             ` Segher Boessenkool
2020-09-04 19:00                                               ` Qing Zhao
2020-09-07 14:36                                                 ` Segher Boessenkool
2020-09-08 14:55                                                   ` Qing Zhao
2020-09-10 21:56                                                     ` Segher Boessenkool
2020-08-24 14:36                           ` Rodriguez Bahena, Victor
2020-08-06 22:32                   ` Qing Zhao
2020-08-07 13:20           ` Alexandre Oliva
2020-08-07 17:04             ` Qing Zhao
2020-08-11  2:39               ` Alexandre Oliva
2020-08-11  5:57                 ` Kees Cook
2020-08-11 17:30                 ` Qing Zhao
2020-08-24 10:50                   ` Richard Biener
2020-08-24 14:48                     ` Qing Zhao
2020-08-25  5:16                     ` Alexandre Oliva
2020-08-25 14:19                       ` Jeff Law
2020-08-26 12:02                         ` Alexandre Oliva
2020-08-26 17:58                           ` Qing Zhao
2020-08-28  7:47                             ` Alexandre Oliva
2020-08-28 15:21                               ` Qing Zhao
2020-08-28 15:33                                 ` H.J. Lu
2020-08-26 18:36                           ` Jeff Law
2020-05-04 19:01 ` [PATCH 3/4] x86: Add ix86_any_return_p H.J. Lu
2020-05-04 19:01 ` [PATCH 4/4] Update gcc.target/i386/ret-thunk-2[234].c H.J. Lu
2020-05-05 16:29 ` [PATCH 1/4] matcher-1.m: Change return type to int Jeff Law

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=EA9F204F-1E0B-40B6-9594-8F35B3C85920@ORACLE.COM \
    --to=qing.zhao@oracle.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=keescook@chromium.org \
    --cc=richard.sandiford@arm.com \
    --cc=segher@kernel.crashing.org \
    --cc=ubizjak@gmail.com \
    --cc=victor.rodriguez.bahena@intel.com \
    /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).