https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117193
Bug ID: 117193
Summary: Missing (a < b) < (b < a) transformation at gimple
level
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: pinskia at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Found via PR 117186.
Basically `bool0 < bool1` is `!bool0 & bool1` So `(a < b) < (a > b)` becomes
`(a >= b) & (a > b)` which becomes `(a > b)` .
Note this will make PR 117186 go latent.
We already have:
/* Convert (X OP1 CST1) && (X OP2 CST2).
Convert (X OP1 Y) && (X OP2 Y). */
(for code1 (lt le gt ge)
(for code2 (lt le gt ge)
Which we could do for </<= too.
Something like:
(for cmp1 (lt le gt ge)
(for cmp2 (lt le gt ge)
(simplify (lt:c (cmp1:c @0 @1) (cmp2:c @0 @1))
/* a < a -> false. */
(if (cmp1 == cmp2)
{ constant_boolean_node (false, type); }
/* a < !a -> true. */
(if (cmp1 == invert_tree_comparison (cmp2, TREE_TYPE (@0)))
...