[Bug tree-optimization/101240] [missed optimization] Transitivity of less-than and less-or-equal
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101240 --- Comment #5 from Andrew Pinski --- here is a better testcase: ``` int test_array(unsigned ()[3]) { int t = (a[0]+a[1]+a[2]); ALWAYS_TRUE(a[0] < a[1] && a[1] < a[2]); return (a[0] < a[2])+t; } ``` (just to make sure VRP is only dealing with SSA names). We should be able to optimize the above to just return a[0]+a[1]+a[2]+1;
[Bug tree-optimization/101240] [missed optimization] Transitivity of less-than and less-or-equal
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101240 Aldy Hernandez changed: What|Removed |Added CC||aldyh at gcc dot gnu.org --- Comment #4 from Aldy Hernandez --- (In reply to Andrew Macleod from comment #3) > in VRP2 we see: > > [local count: 1073741824]: > _1 = (*a_6(D))[0]; > _2 = (*a_6(D))[1]; > pretmp_8 = (*a_6(D))[2]; > if (_1 < _2) > goto ; [50.00%] > else > goto ; [50.00%] > >[local count: 536870913]: > if (_2 < pretmp_8) > goto ; [0.00%] > else > goto ; [100.00%] > >[count: 0]: > __builtin_unreachable (); > >[local count: 1073741824]: > _7 = _1 < pretmp_8; > return _7; > > There isnt much VRP can do about this because if we take the path 2->5, we > have no way of resolving _1 < pretmp_8 because the comparison has not been > made yet. > > interestingly, if this were to be threaded, > 2->3 would register _1 < _2 > 3->5 would register _2 >= ptrtmp_8 > then in bb5' _1 < pretmp_8 should be answered by the path oracle as TRUE > and then be folded to return true. at least it should :-) > > I guess the next question would be... why doesn't the threader think this is > worth threading? The threader only looks at paths that end in a block with multiple exits: FOR_EACH_BB_FN (bb, m_fun) if (EDGE_COUNT (bb->succs) > 1) maybe_thread_block (bb); so...a switch or a cond.
[Bug tree-optimization/101240] [missed optimization] Transitivity of less-than and less-or-equal
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101240 Andrew Macleod changed: What|Removed |Added CC||aldyh at redhat dot com --- Comment #3 from Andrew Macleod --- in VRP2 we see: [local count: 1073741824]: _1 = (*a_6(D))[0]; _2 = (*a_6(D))[1]; pretmp_8 = (*a_6(D))[2]; if (_1 < _2) goto ; [50.00%] else goto ; [50.00%] [local count: 536870913]: if (_2 < pretmp_8) goto ; [0.00%] else goto ; [100.00%] [count: 0]: __builtin_unreachable (); [local count: 1073741824]: _7 = _1 < pretmp_8; return _7; There isnt much VRP can do about this because if we take the path 2->5, we have no way of resolving _1 < pretmp_8 because the comparison has not been made yet. interestingly, if this were to be threaded, 2->3 would register _1 < _2 3->5 would register _2 >= ptrtmp_8 then in bb5' _1 < pretmp_8 should be answered by the path oracle as TRUE and then be folded to return true. at least it should :-) I guess the next question would be... why doesn't the threader think this is worth threading?
[Bug tree-optimization/101240] [missed optimization] Transitivity of less-than and less-or-equal
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101240 --- Comment #2 from Richard Biener --- Note will require a VRP pass after PRE since only there we'll be able to CSE the a[2] load.
[Bug tree-optimization/101240] [missed optimization] Transitivity of less-than and less-or-equal
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101240 Richard Biener changed: What|Removed |Added Blocks||85316 Last reconfirmed||2021-06-29 CC||amacleod at redhat dot com Status|UNCONFIRMED |NEW Ever confirmed|0 |1 --- Comment #1 from Richard Biener --- EVRP sees : _1 = (*a_8(D))[0]; _2 = (*a_8(D))[1]; if (_1 < _2) goto ; [INV] else goto ; [INV] : _4 = (*a_8(D))[2]; if (_2 < _4) goto ; [INV] else goto ; [INV] : __builtin_unreachable (); : _6 = (*a_8(D))[2]; _9 = _1 < _6; so predicate analysis should handle this (but it does not). Btw, I fixed the testcase for you: #define ALWAYS_TRUE(x) do { if (x) __builtin_unreachable(); } while (false) bool test_array(unsigned ()[3]) { ALWAYS_TRUE(a[0] < a[1] && a[1] < a[2]); return a[0] < a[2]; } Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85316 [Bug 85316] [meta-bug] VRP range propagation missed cases