public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Jeff Law <law@redhat.com>
Cc: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: Re: [RFA/RFC] [PR tree-optimization/80635] Optimize some V_C_Es with limited ranges into NOP_EXPRs
Date: Mon, 6 Apr 2020 11:14:55 +0200	[thread overview]
Message-ID: <CAFiYyc0+=egQVwUbx7jLAE=HGjv0nrPDqMXC2KuytiWe5g1_sQ@mail.gmail.com> (raw)
In-Reply-To: <bd372f109962a4fc9197c48c6d3bc85b939c9f77.camel@redhat.com>

On Sun, Apr 5, 2020 at 5:25 PM Jeff Law via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
>
> So here's an approach to try and address PR80635.
>
> In this BZ we're getting a false positive uninitialized warning using
> std::optional.
>
> As outlined in the BZ this stems from SRA using a VIEW_CONVERT_EXPR  which isn't
> handled terribly well by the various optimizers/analysis passes.
>
> We have these key blocks:
>
> ;;   basic block 5, loop depth 0
> ;;    pred:       3
> ;;                2
>   # maybe_a$m_6 = PHI <_5(3), maybe_a$m_4(D)(2)>
>   # maybe_a$4_7 = PHI <1(3), 0(2)>
> <L0>:
>   _8 = maybe_b.live;
>   if (_8 != 0)
>     goto <bb 6>; [0.00%]
>   else
>     goto <bb 7>; [0.00%]
> ;;    succ:       6
> ;;                7
>
> ;;   basic block 6, loop depth 0
> ;;    pred:       5
>   B::~B (&maybe_b.D.2512.m_item);
> ;;    succ:       7
>
> ;;   basic block 7, loop depth 0
> ;;    pred:       5
> ;;                6
>   maybe_b ={v} {CLOBBER};
>   resx 3
> ;;    succ:       8
>
> ;;   basic block 8, loop depth 0
> ;;    pred:       7
> <L1>:
>   _9 = VIEW_CONVERT_EXPR<bool>(maybe_a$4_7);

So this is a reg-reg copy.  But if you replace it with a NOP_EXPR
it becomes a truncation which is less optimal.

Testcase:

char y;
_Bool x;
void __GIMPLE(ssa) foo()
{
  _Bool _1;
  char _2;

  __BB(2):
  _2 = y;
  _1 = (_Bool)_2;
  x = _1;
  return;
}
void __GIMPLE(ssa) bar()
{
  _Bool _1;
  char _2;

  __BB(2):
  _2 = y;
  _1 = __VIEW_CONVERT <_Bool> (_2);
  x = _1;
  return;
}

where assembly is

foo:
.LFB0:
        .cfi_startproc
        movzbl  y(%rip), %eax
        andl    $1, %eax
        movb    %al, x(%rip)
        ret

vs.

bar:
.LFB1:
        .cfi_startproc
        movzbl  y(%rip), %eax
        movb    %al, x(%rip)
        ret

so the reverse transformation is what should be done ...

Which means other analyses have to improve their handling
of VIEW_CONVERT_EXPR instead.

Richard.

>   if (_9 != 0)
>     goto <bb 9>; [0.00%]
>   else
>     goto <bb 10>; [0.00%]
> ;;    succ:       9
> ;;                10
>
> Where there is a use of maybe_a$m_6 in block #9.
>
> Of course maybe_a$m_6 only takes the value of maybe_a$m_4(D) when we traverse the
> edge 2->5 but in that case maybe_a$4_7 will always have the value zero and thus
> we can not reach bb #9..  But the V_C_E gets in the way of the analysis and we
> issue the false positive warning.  Martin Jambor has indicated that he doesn't
> see a way to avoid the V_C_E from SRA without reintroducing PR52244.
>
> This patch optimizes the V_C_E into a NOP_EXPR by verifying that the V_C_E folds
> to a constant value for the min & max values of the range of the input operand
> and the result of folding is equal to the original input.  We do some additional
> checking beyond just that original value and converted value are equal according
> to operand_equal_p.
>
> Eventually the NOP_EXPR also gets removed as well and the conditional in bb8
> tests maybe_a$4_7 against 0 directly.
>
> That in turn allows the uninit analysis to determine the use of maybe_a$_m_6 in
> block #9 is properly guarded and the false positive is avoided.
>
> The optimization of a V_C_E into a NOP_EXPR via this patch occurs a couple
> hundred times during a bootstrap, so this isn't a horribly narrow change just to
> fix a false positive warning.
>
> Bootstrapped and regression tested on x86_64.  I've also put it through its paces
> in the tester.  The tester's current failures (aarch64, mips, h8) are unrelated
> to this patch.
>
>
> Thoughts?  OK for the trunk?  Alternately I wouldn't lose sleep moving this to
> gcc-11.
>
> jeff
>
>

      parent reply	other threads:[~2020-04-06  9:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-05 15:25 Jeff Law
2020-04-05 18:48 ` Richard Biener
2020-04-05 18:52   ` Jeff Law
2020-04-05 20:12   ` Eric Botcazou
2020-04-05 20:21     ` Eric Botcazou
2020-04-06  9:14 ` Richard Biener [this message]

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='CAFiYyc0+=egQVwUbx7jLAE=HGjv0nrPDqMXC2KuytiWe5g1_sQ@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.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).