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 optimization/14752] New: [tree-ssa] "~a" should be changed to "a" if used in the condition of an if statement


Consider:

void bar (void);

void
foo (unsigned int a)
{
  if (((a >> 2) & 1))
    bar ();
}

void
baz (unsigned int a)
{
  if (((~a >> 2) & 1))
    bar ();
}

tree-ssa optimizers cannot absorb "~" in "~a" by swapping then and else clauses.
Here is the last tree in SSA form.


;; Function foo (foo)

foo (a)
{
  _Bool T.2;
  unsigned int T.1;
  unsigned int T.0;

<bb 0>:
  T.0_2 = a_1 >> 2;
  T.1_3 = T.0_2 & 1;
  T.2_4 = (_Bool)T.1_3;
  if (T.2_4) goto <L0>; else goto <L1>;

<L0>:;
  bar () [tail call];

<L1>:;
  return;

}



;; Function baz (baz)

baz (a)
{
  _Bool T.6;
  unsigned int T.5;
  unsigned int T.4;
  unsigned int T.3;

<bb 0>:
  T.3_2 = ~a_1;          <- we could remove this "~" by ...
  T.4_3 = T.3_2 >> 2;
  T.5_4 = T.4_3 & 1;
  T.6_5 = (_Bool)T.5_4;
  if (T.6_5) goto <L0>; else goto <L1>;  <- flipping the labels

<L0>:;
  bar () [tail call];

<L1>:;
  return;

}

The combiner can atually take care of this, but we can reduce initial rtl
if we remove "~".

-- 
           Summary: [tree-ssa] "~a" should be changed to "a" if used in the
                    condition of an if statement
           Product: gcc
           Version: tree-ssa
            Status: UNCONFIRMED
          Keywords: pessimizes-code
          Severity: enhancement
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kazu at cs dot umass dot edu
                CC: gcc-bugs at gcc dot gnu dot org


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


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