This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/20701] New: [tcb] VRP does not eliminate a redundant "if" statement.


Consider:

typedef struct {
  int code;
} *rtx;

int
can_combine_p (rtx insn, rtx elt)
{
  rtx set;

  set = 0;
  if (insn->code == 3)
    set = insn;
  else
    {
      set = elt;
      if (set == 0)
	return 0;
    }

  if (set == 0)
    return 1;

  return 0;
}

Note that the last "if" statement never triggers.  That is, its condition
is always false.

Here is the dump with ASSERT_EXPRs.

can_combine_p (insn, elt)
{
  struct 
  {
    int code;
  } * set;
  int D.1138;
  int D.1137;

<bb 0>:
  D.1137_5 = insn_4->code;
  insn_7 = ASSERT_EXPR <insn_4, insn_4 != 0B>;
  if (D.1137_5 == 3) goto <L3>; else goto <L1>;

<L1>:;
  if (elt_9 == 0B) goto <L7>; else goto <L3>;

  # set_1 = PHI <insn_7(0), elt_9(1)>;
<L3>:;
  if (set_1 == 0B) goto <L5>; else goto <L7>;

<L5>:;

  # D.1138_2 = PHI <0(1), 1(3), 0(2)>;
<L7>:;
  return D.1138_2;

}

For some reason, VRP does not insert an ASSERT_EXPR for elt_9,
so VRP proper cannot figure out that set_1 != 0B.

This opportunity is picked up by DOM in the form of jump threading.

This function is reduced from combine.c:can_combine_p.

-- 
           Summary: [tcb] VRP does not eliminate a redundant "if" statement.
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kazu at cs dot umass dot edu
                CC: dnovillo at redhat dot com,gcc-bugs at gcc dot gnu dot
                    org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20701


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]