[Bug tree-optimization/91882] boolean XOR tautology missed optimisation
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91882 Andrew Pinski changed: What|Removed |Added Target Milestone|--- |13.0
[Bug tree-optimization/91882] boolean XOR tautology missed optimisation
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91882 Andrew Pinski changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #8 from Andrew Pinski --- comment #0 is now fixed. Filed PR 107880 for comment #1 since it is a different issue.
[Bug tree-optimization/91882] boolean XOR tautology missed optimisation
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91882 Bug 91882 depends on bug 103356, which changed state. Bug 103356 Summary: bool0 == ~bool1 should simplify to bool1 ^ bool0 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103356 What|Removed |Added Status|ASSIGNED|RESOLVED Resolution|--- |FIXED
[Bug tree-optimization/91882] boolean XOR tautology missed optimisation
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91882 --- Comment #7 from Andrew Pinski --- Note comment #1 is not done after the patch for PR103356 .
[Bug tree-optimization/91882] boolean XOR tautology missed optimisation
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91882 Andrew Pinski changed: What|Removed |Added Depends on||103356 --- Comment #6 from Andrew Pinski --- After my patch for PR 103356, this is fixed. Before pre: _1 = a_4(D) ^ b_5(D); _2 = a_4(D) | b_5(D); if (_2 != 0) goto ; [50.00%] else goto ; [50.00%] [local count: 536870913]: _6 = a_4(D) & b_5(D); _9 = ~_6; [local count: 1073741824]: # iftmp.0_3 = PHI <_9(3), 0(2)> _7 = _1 == iftmp.0_3; After PRE (after my patch): _1 = a_4(D) ^ b_5(D); _2 = a_4(D) | b_5(D); if (_2 != 0) goto ; [50.00%] else goto ; [50.00%] [local count: 536870912]: _10 = ~_1; goto ; [100.00%] [local count: 536870913]: // _6 = a_4(D) & b_5(D); // _9 = ~_6; [local count: 1073741824]: # iftmp.0_3 = PHI <_9(4), 0(3)> # prephitmp_11 = PHI <_2(4), _10(3)> return prephitmp_11; And then dom comes and does (because if (a|b) == 0 then both a and b are zero and a^b == 0 and ~(a^b) is 1): [local count: 1073741824]: _2 = a_4(D) | b_5(D); if (_2 != 0) goto ; [50.00%] else goto ; [50.00%] [local count: 536870912]: _1 = 0; _10 = 1; [local count: 1073741824]: # prephitmp_11 = PHI <1(2), 1(3)> return 1; Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103356 [Bug 103356] bool0 == ~bool1 should simplify to bool1 ^ bool0
[Bug tree-optimization/91882] boolean XOR tautology missed optimisation
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91882 --- Comment #5 from Ivan Sučić --- I have added in match.pd a simplify. But for unknown reason it doesn't get applied. Anybody knows why?
[Bug tree-optimization/91882] boolean XOR tautology missed optimisation
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91882 Ivan Sučić changed: What|Removed |Added CC||sucicf1 at outlook dot com --- Comment #4 from Ivan Sučić --- I have added im match.pd a simplify. But fir unknown reason IT doesn't het applied. Anybody knows why?
[Bug tree-optimization/91882] boolean XOR tautology missed optimisation
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91882 --- Comment #3 from Andrew Pinski --- This is a job for reassociation pass really. coming into that pass we have: _1 = a_3(D) | b_4(D); if (_1 != 0) goto ; [50.00%] else goto ; [50.00%] [local count: 536870913]: _5 = a_3(D) & b_4(D); if (_5 != 0) goto ; [50.00%] else goto ; [50.00%] [local count: 805306369]: [local count: 1073741824]: # iftmp.0_2 = PHI <1(3), 0(4)> We should be able to transform this into: _6 = a_3(D) ^ b_4(D); if (_6 != 0) goto ; [50.00%] else goto ; [50.00%] [local count: 536870913]: if (0 != 0) goto ; [50.00%] else goto ; [50.00%] [local count: 805306369]: [local count: 1073741824]: # iftmp.0_2 = PHI <1(3), 0(4)> then cfg cleanup should do: _6 = a_3(D) ^ b_4(D); if (_6 != 0) goto ; [50.00%] else goto ; [50.00%] [local count: 805306369]: [local count: 1073741824]: # iftmp.0_2 = PHI <1(1), 0(4)> And then PHI-OPT should transform it into: _6 = a_3(D) ^ b_4(D); iftmp.0_2 = _6;
[Bug tree-optimization/91882] boolean XOR tautology missed optimisation
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91882 Andrew Pinski changed: What|Removed |Added CC||pinskia at gcc dot gnu.org Severity|normal |enhancement
[Bug tree-optimization/91882] boolean XOR tautology missed optimisation
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91882 Martin Liška changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2020-01-23 CC||marxin at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #2 from Martin Liška --- Confirmed on current master.
[Bug tree-optimization/91882] boolean XOR tautology missed optimisation
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91882 --- Comment #1 from SztfG at yandex dot ru --- Similar problem with other tautology: unsigned int impl_bit(unsigned int a, unsigned int b) // bitwise implication { return (~a | b); } unsigned int eq_bit(unsigned int a, unsigned int b) // bitwise equivalence { return (~a ^ b); } // good optimisation - "return 1;" unsigned int always_true(unsigned int a, unsigned int b) { return eq_bit(impl_bit(a,b), impl_bit(b,a)) == eq_bit(a, b); // ( (a -> b) = (b -> a) ) = (a = b) tautology } bool impl_bool(bool a, bool b { return (!a || b); } // bad optimisation bool always_true(bool a, bool b) { return (impl(a,b) == impl(b,a)) == (a == b); // ( (a -> b) = (b -> a) ) = (a = b) tautology }