public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/57755] New: Improve fold_binary_op_with_conditional_arg
@ 2013-06-28 18:02 glisse at gcc dot gnu.org
  2013-06-29  0:06 ` [Bug tree-optimization/57755] " glisse at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-06-28 18:02 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57755

            Bug ID: 57755
           Summary: Improve fold_binary_op_with_conditional_arg
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org

Hello,

fold_binary_op_with_conditional_arg performs the following:

   Transform `a + (b ? x : y)' into `b ? (a + x) : (a + y)'.
   Transform, `a + (x < y)' into `(x < y) ? (a + 1) : (a + 0)'.

It gives up in this first case (arg is 'a' above):

  if (!TREE_CONSTANT (arg)
      && (TREE_SIDE_EFFECTS (arg)
          || TREE_CODE (arg) == COND_EXPR || TREE_CODE (arg) == VEC_COND_EXPR
          || TREE_CONSTANT (true_value) || TREE_CONSTANT (false_value)))
    return NULL_TREE;

and after folding both branches:

  if (!TREE_CONSTANT (arg) && !TREE_CONSTANT (lhs) && !TREE_CONSTANT (rhs))
    return NULL_TREE;

This seems suboptimal. On the one hand, for ((a<b)?a:c)*3/2+1, it distributes
the operations to a < b ? (a * 3) / 2 + 1 : (c * 3) / 2 + 1 (we can add as many
operations with constants as we want) and this isn't completely undone later
(partially with -Os, not at all with -O3). On the other hand, for
((a<2)?-1u:0)&b, it gives up instead of producing (a<2)?b:0.

We must be careful with recursions (PR55219) and with folders performing the
reverse transformations, but I think we should be able to optimize:
(((a<2)?-1:0)&((b<1)?-1:0))!=0

(obviously, the title doesn't prevent from moving this functionality to gimple)


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-09-16  2:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-28 18:02 [Bug tree-optimization/57755] New: Improve fold_binary_op_with_conditional_arg glisse at gcc dot gnu.org
2013-06-29  0:06 ` [Bug tree-optimization/57755] " glisse at gcc dot gnu.org
2023-05-05  7:39 ` pinskia at gcc dot gnu.org
2023-05-05  7:43 ` pinskia at gcc dot gnu.org
2023-09-15 20:43 ` pinskia at gcc dot gnu.org
2023-09-16  2:23 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).