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(); }
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.
Woops wrong PR.
f1 right now is equivement to _Bool f2() { int t3 = 0; if (t()) if (t1()) t3 = 1; return t3; }
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;
Mine, PHI-OPT is not smart enough.
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; }
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.
(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.
(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.
And I don't have time for this any more. Maybe After I have laptop fixed.
I am going try to get this fixed for 4.3.0.
I am no longer working on this one.
Works on the trunk. The .final_cleanup dumps are the same for f and f1, and so is the asm output.