Bug 14442 - missed sib if conversion optimization on the tree level (PHI-OPT misses that !(a == 0) is just a != 0)
Summary: missed sib if conversion optimization on the tree level (PHI-OPT misses that ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: tree-ssa
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on: 14440 15618 17671
Blocks:
  Show dependency treegraph
 
Reported: 2004-03-05 06:30 UTC by Andrew Pinski
Modified: 2023-12-31 17:44 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-12-27 04:33:45


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2004-03-05 06:30:50 UTC
These two functions should produce the same asm (drivided from GCC's sources):
_Bool t();
_Bool t1();

_Bool f(int i)
{
   if (!t())
    return 0;
   return t1();
}
_Bool f1()
{
  return t() && t1();
}
Comment 1 Andrew Pinski 2004-03-06 04:00:06 UTC
Confirmed again by honza on the IRC, he said it will be fixed after the merge of the tree-
ssa into the mainline by the same patch which will fix 14440.
Comment 2 Andrew Pinski 2004-03-07 03:44:57 UTC
Woops wrong PR.
Comment 3 Andrew Pinski 2004-04-05 01:06:13 UTC
f1 right now is equivement to
_Bool f2()
{
  int t3 = 0;
  if (t())
    if (t1())
      t3 = 1;
   return t3;
}
Comment 4 Andrew Pinski 2004-05-14 22:11:13 UTC
The problem here is tree-ssa-phi-opt is not smart enough:
  T.2_6 = t1 ();
  if (T.2_6 == 0) goto <L2>; else goto <L3>;

<L2>:;

  # iftmp.0_1 = PHI <0(2), 0(0), 1(1)>;
<L3>:;
  T.3_3 = (_Bool)iftmp.0_1;
  return (int)T.3_3;
Comment 5 Andrew Pinski 2004-09-28 18:29:52 UTC
Mine, PHI-OPT is not smart enough.
Comment 6 Andrew Pinski 2004-09-28 20:01:33 UTC
With some work I have it down to:
f1 ()
{
  _Bool D.1122;
  _Bool D.1120;
  int iftmp.0;

<bb 0>:
  D.1120 = t ();
  if (D.1120 == 0) goto <L6>; else goto <L0>;

<L6>:;
  iftmp.0 = 0;
  goto <bb 2> (<L3>);

<L0>:;
  D.1122 = t1 ();
  iftmp.0 = (int) !(D.1122 == 0);  <-- still can be fixed some more to just (int) (D.1122). but that will be 
a fold issue (there is another bug about that).

<L3>:;
  return (int) (_Bool) iftmp.0;

}
Comment 7 Andrew Pinski 2004-09-29 02:40:25 UTC
Basically PR 17671 is the PR for the new PHI-OPT and PR 15618 is for fold a!=0 to a when a is of the 
boolean_type.  Also note the C++ front-end for the code in comment 3 (when the int is changed to 
bool) is already fixed by the new PHI-OPT.
Comment 8 Andrew Pinski 2005-05-01 18:26:48 UTC
(In reply to comment #7)
> Basically PR 17671 is the PR for the new PHI-OPT and PR 15618 is for fold a!=0 to a when a is of the 
> boolean_type.  Also note the C++ front-end for the code in comment 3 (when the int is changed to 
> bool) is already fixed by the new PHI-OPT.

Actually PHI-OPT needs to improved after the patch for PR 15618 is applied, instead of creating one 
statement at a time and then letting the passes after wards fold it (which does not happen right now), 
we should instead create one new statement which fold as we build it.
Comment 9 Andrew Pinski 2005-05-01 18:44:11 UTC
(In reply to comment #8)
> Actually PHI-OPT needs to improved after the patch for PR 15618 is applied, instead of creating one 
> statement at a time and then letting the passes after wards fold it (which does not happen right now), 
> we should instead create one new statement which fold as we build it.

Actually I am wrong, we just need a fold around the invert_truthvalue call.

Mine still.
Comment 10 Andrew Pinski 2005-10-23 00:01:11 UTC
And I don't have time for this any more.  Maybe After I have laptop fixed.
Comment 11 Andrew Pinski 2006-08-21 06:14:21 UTC
I am going try to get this fixed for 4.3.0.
Comment 12 Andrew Pinski 2007-05-28 21:22:10 UTC
I am no longer working on this one.
Comment 13 Steven Bosscher 2009-02-22 19:13:57 UTC
Works on the trunk.  The .final_cleanup dumps are the same for f and f1, and so is the asm output.