public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/103439] New: genemit emits dead code
@ 2021-11-26 12:10 rguenth at gcc dot gnu.org
  2021-11-26 12:26 ` [Bug middle-end/103439] " ubizjak at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-11-26 12:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103439

            Bug ID: 103439
           Summary: genemit emits dead code
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

Patterns like

(define_expand "nearbyinthf2"
  [(match_operand:HF 0 "register_operand")
   (match_operand:HF 1 "nonimmediate_operand")]
  "TARGET_AVX512FP16"
{
  emit_insn (gen_sse4_1_roundhf2 (operands[0],
                                  operands[1],
                                  GEN_INT (ROUND_MXCSR | ROUND_NO_EXC)));
  DONE;
})

generate

/* /home/rguenther/src/trunk/gcc/config/i386/i386.md:18636 */
rtx
gen_nearbyinthf2 (rtx operand0,
        rtx operand1)
{
  rtx_insn *_val = 0;
  start_sequence ();
  {
    rtx operands[2];
    operands[0] = operand0;
    operands[1] = operand1;
#define FAIL _Pragma ("GCC error \"nearbyinthf2 cannot FAIL\"") (void)0
#define DONE return (_val = get_insns (), end_sequence (), _val)
#line 18640 "/home/rguenther/src/trunk/gcc/config/i386/i386.md"
{
  emit_insn (gen_sse4_1_roundhf2 (operands[0],
                                  operands[1],
                                  GEN_INT (ROUND_MXCSR | ROUND_NO_EXC)));
  DONE;
}
#undef DONE
#undef FAIL
    operand0 = operands[0];
    (void) operand0;
    operand1 = operands[1];
    (void) operand1;
  }
  emit (operand0, true);
  emit (operand1, false);
  _val = get_insns ();
  end_sequence ();
  return _val;
}

where the code after DONE is not reachable.  With a proposed
-Wunreachable-code-return this diagnoses most expander patterns.

I'm not sure if there are valid cases where we have a mix of a direct
RTL pattern and manual expansion, so where the { } part falls thru.

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

* [Bug middle-end/103439] genemit emits dead code
  2021-11-26 12:10 [Bug middle-end/103439] New: genemit emits dead code rguenth at gcc dot gnu.org
@ 2021-11-26 12:26 ` ubizjak at gmail dot com
  2021-11-26 12:28 ` rguenther at suse dot de
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ubizjak at gmail dot com @ 2021-11-26 12:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103439

--- Comment #1 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Richard Biener from comment #0)
> I'm not sure if there are valid cases where we have a mix of a direct
> RTL pattern and manual expansion, so where the { } part falls thru.

Yes, we have quite some of them in e.g. i386.md, movstrict<mode>, extv<mode>,
extzv<mode>, insv<mode> and zero_extend expanders are some of them.

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

* [Bug middle-end/103439] genemit emits dead code
  2021-11-26 12:10 [Bug middle-end/103439] New: genemit emits dead code rguenth at gcc dot gnu.org
  2021-11-26 12:26 ` [Bug middle-end/103439] " ubizjak at gmail dot com
@ 2021-11-26 12:28 ` rguenther at suse dot de
  2021-11-26 13:11 ` ubizjak at gmail dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenther at suse dot de @ 2021-11-26 12:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103439

--- Comment #2 from rguenther at suse dot de <rguenther at suse dot de> ---
On Fri, 26 Nov 2021, ubizjak at gmail dot com wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103439
> 
> --- Comment #1 from Uroš Bizjak <ubizjak at gmail dot com> ---
> (In reply to Richard Biener from comment #0)
> > I'm not sure if there are valid cases where we have a mix of a direct
> > RTL pattern and manual expansion, so where the { } part falls thru.
> 
> Yes, we have quite some of them in e.g. i386.md, movstrict<mode>, extv<mode>,
> extzv<mode>, insv<mode> and zero_extend expanders are some of them.

OK, so that's conditional FAILs.  I've not yet found a conditional
DONE that eventually falls through to a "DONE via the pattern".

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

* [Bug middle-end/103439] genemit emits dead code
  2021-11-26 12:10 [Bug middle-end/103439] New: genemit emits dead code rguenth at gcc dot gnu.org
  2021-11-26 12:26 ` [Bug middle-end/103439] " ubizjak at gmail dot com
  2021-11-26 12:28 ` rguenther at suse dot de
@ 2021-11-26 13:11 ` ubizjak at gmail dot com
  2021-11-26 13:38 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ubizjak at gmail dot com @ 2021-11-26 13:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103439

--- Comment #3 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to rguenther@suse.de from comment #2)
> On Fri, 26 Nov 2021, ubizjak at gmail dot com wrote:
> 
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103439
> > 
> > --- Comment #1 from Uroš Bizjak <ubizjak at gmail dot com> ---
> > (In reply to Richard Biener from comment #0)
> > > I'm not sure if there are valid cases where we have a mix of a direct
> > > RTL pattern and manual expansion, so where the { } part falls thru.
> > 
> > Yes, we have quite some of them in e.g. i386.md, movstrict<mode>, extv<mode>,
> > extzv<mode>, insv<mode> and zero_extend expanders are some of them.
> 
> OK, so that's conditional FAILs.  I've not yet found a conditional
> DONE that eventually falls through to a "DONE via the pattern".

Look at zero_extend and extend expanders.

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

* [Bug middle-end/103439] genemit emits dead code
  2021-11-26 12:10 [Bug middle-end/103439] New: genemit emits dead code rguenth at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-11-26 13:11 ` ubizjak at gmail dot com
@ 2021-11-26 13:38 ` rguenth at gcc dot gnu.org
  2021-11-26 22:06 ` pinskia at gcc dot gnu.org
  2021-11-29  7:21 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-11-26 13:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103439

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Uroš Bizjak from comment #3)
> (In reply to rguenther@suse.de from comment #2)
> > On Fri, 26 Nov 2021, ubizjak at gmail dot com wrote:
> > 
> > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103439
> > > 
> > > --- Comment #1 from Uroš Bizjak <ubizjak at gmail dot com> ---
> > > (In reply to Richard Biener from comment #0)
> > > > I'm not sure if there are valid cases where we have a mix of a direct
> > > > RTL pattern and manual expansion, so where the { } part falls thru.
> > > 
> > > Yes, we have quite some of them in e.g. i386.md, movstrict<mode>, extv<mode>,
> > > extzv<mode>, insv<mode> and zero_extend expanders are some of them.
> > 
> > OK, so that's conditional FAILs.  I've not yet found a conditional
> > DONE that eventually falls through to a "DONE via the pattern".
> 
> Look at zero_extend and extend expanders.

Indeed.

(define_expand "zero_extendqihi2"
  [(set (match_operand:HI 0 "register_operand")
        (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
  ""
{
  if (TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))
    {
      operands[1] = force_reg (QImode, operands[1]);
      emit_insn (gen_zero_extendqihi2_and (operands[0], operands[1]));
      DONE;
    }
})

and

/* /home/rguenther/src/trunk/gcc/config/i386/i386.md:4120 */
rtx
gen_zero_extendqihi2 (rtx operand0,
        rtx operand1)
{
  rtx_insn *_val = 0;
  start_sequence ();
  {
    rtx operands[2];
    operands[0] = operand0;
    operands[1] = operand1;
#define FAIL return (end_sequence (), _val)
#define DONE return (_val = get_insns (), end_sequence (), _val)
#line 4124 "/home/rguenther/src/trunk/gcc/config/i386/i386.md"
{
  if (TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))
    {
      operands[1] = force_reg (QImode, operands[1]);
      emit_insn (gen_zero_extendqihi2_and (operands[0], operands[1]));
      DONE;
    }
}
#undef DONE
#undef FAIL
    operand0 = operands[0];
    (void) operand0;
    operand1 = operands[1];
    (void) operand1;
  }
  emit_insn (gen_rtx_SET (operand0,
        gen_rtx_ZERO_EXTEND (HImode,
        operand1)));
  _val = get_insns ();
  end_sequence ();
  return _val;
}

so quite hard if not impossible to "fix" in genemit

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

* [Bug middle-end/103439] genemit emits dead code
  2021-11-26 12:10 [Bug middle-end/103439] New: genemit emits dead code rguenth at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-11-26 13:38 ` rguenth at gcc dot gnu.org
@ 2021-11-26 22:06 ` pinskia at gcc dot gnu.org
  2021-11-29  7:21 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-26 22:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103439

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #4)
> so quite hard if not impossible to "fix" in genemit

The most complex one I saw in action was mod<mode>3 in aarch64.md:
(define_expand "mod<mode>3"
  [(match_operand:GPI 0 "register_operand")
   (match_operand:GPI 1 "register_operand")
   (match_operand:GPI 2 "const_int_operand")]

Where the pattern in the expand is not going to be used at all (obviously) but
has a conditional FAIL and then an unconditional DONE.
    if (val <= 0
       || exact_log2 (val) <= 0
       || !aarch64_bitmask_imm (val - 1, <MODE>mode))
      FAIL;
....
    rtx masked_neg = gen_reg_rtx (<MODE>mode);
    emit_insn (gen_and<mode>3 (masked_neg, neg_op, mask));

    emit_insn (gen_csneg3<mode>_insn (operands[0], cond,
                                       masked_neg, masked_pos));
    DONE;


And even splits will have issues too. See "*compare_condjump<GPI:mode>" in
aarch64 where the pattern in the split will not be used but then there is an
unconditional DONE:
    emit_jump_insn (gen_condjump (cmp_rtx, cc_reg, operands[2]));
    DONE;


I think we should just close this as won't fix and add -Wno-unreachable-code
while compiling the generated C file.

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

* [Bug middle-end/103439] genemit emits dead code
  2021-11-26 12:10 [Bug middle-end/103439] New: genemit emits dead code rguenth at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2021-11-26 22:06 ` pinskia at gcc dot gnu.org
@ 2021-11-29  7:21 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-11-29  7:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103439

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |WONTFIX
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
OK, agreed.

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

end of thread, other threads:[~2021-11-29  7:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-26 12:10 [Bug middle-end/103439] New: genemit emits dead code rguenth at gcc dot gnu.org
2021-11-26 12:26 ` [Bug middle-end/103439] " ubizjak at gmail dot com
2021-11-26 12:28 ` rguenther at suse dot de
2021-11-26 13:11 ` ubizjak at gmail dot com
2021-11-26 13:38 ` rguenth at gcc dot gnu.org
2021-11-26 22:06 ` pinskia at gcc dot gnu.org
2021-11-29  7:21 ` rguenth at gcc dot gnu.org

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