public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/97519] New: builtin_constant_p (x + cst) should be optimized to builtin_constant_p (x)
@ 2020-10-21 15:14 hubicka at gcc dot gnu.org
  2020-10-21 16:23 ` [Bug tree-optimization/97519] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: hubicka at gcc dot gnu.org @ 2020-10-21 15:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97519

            Bug ID: 97519
           Summary: builtin_constant_p (x + cst) should be optimized to
                    builtin_constant_p (x)
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hubicka at gcc dot gnu.org
  Target Milestone: ---

As discussed in PR97445 we should optimize builtins_constant_p (var+cst) and
similar cases.

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

* [Bug tree-optimization/97519] builtin_constant_p (x + cst) should be optimized to builtin_constant_p (x)
  2020-10-21 15:14 [Bug tree-optimization/97519] New: builtin_constant_p (x + cst) should be optimized to builtin_constant_p (x) hubicka at gcc dot gnu.org
@ 2020-10-21 16:23 ` pinskia at gcc dot gnu.org
  2020-10-21 16:23 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-10-21 16:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97519

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-10-21
     Ever confirmed|0                           |1
           Keywords|                            |missed-optimization
            Version|unknown                     |11.0

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, the generic is X OP CST (for / and %: CST OP X) into X inside
__builtin_constant_p.

Though the question should we do this on the gimple level or before hand?

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

* [Bug tree-optimization/97519] builtin_constant_p (x + cst) should be optimized to builtin_constant_p (x)
  2020-10-21 15:14 [Bug tree-optimization/97519] New: builtin_constant_p (x + cst) should be optimized to builtin_constant_p (x) hubicka at gcc dot gnu.org
  2020-10-21 16:23 ` [Bug tree-optimization/97519] " pinskia at gcc dot gnu.org
@ 2020-10-21 16:23 ` pinskia at gcc dot gnu.org
  2020-10-22  7:02 ` rguenth at gcc dot gnu.org
  2020-10-22  8:23 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-10-21 16:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97519

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

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

* [Bug tree-optimization/97519] builtin_constant_p (x + cst) should be optimized to builtin_constant_p (x)
  2020-10-21 15:14 [Bug tree-optimization/97519] New: builtin_constant_p (x + cst) should be optimized to builtin_constant_p (x) hubicka at gcc dot gnu.org
  2020-10-21 16:23 ` [Bug tree-optimization/97519] " pinskia at gcc dot gnu.org
  2020-10-21 16:23 ` pinskia at gcc dot gnu.org
@ 2020-10-22  7:02 ` rguenth at gcc dot gnu.org
  2020-10-22  8:23 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-10-22  7:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97519

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Implemented in match.pd it will cover both.  SSA backprop would be the most
natural classical pass candidate but that runs after IPA.  The other candidate
is of course forwprop where it would be "cheaper" (not so many new patterns
to match in match.pd), "chewing" ops during re-processing of processed stmts.

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

* [Bug tree-optimization/97519] builtin_constant_p (x + cst) should be optimized to builtin_constant_p (x)
  2020-10-21 15:14 [Bug tree-optimization/97519] New: builtin_constant_p (x + cst) should be optimized to builtin_constant_p (x) hubicka at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2020-10-22  7:02 ` rguenth at gcc dot gnu.org
@ 2020-10-22  8:23 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-10-22  8:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97519

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
We would certainly need to punt on gimple_could_trap_p assignments, as can be
seen e.g. on
static inline int
foo (int x)
{
  return __builtin_constant_p ((x + 32) / 0);
}

int
bar (void)
{
  return foo (35);
}
with -O2 -fno-early-inlining.
Anyway, I'm actually not sure if it is safe to perform this change at all.
Consider:
int
foo (int x)
{
  if (x < __INT_MAX__ - 30)
    return 23;
  int y = x + 30;
  if (__builtin_constant_p (y))
    return y;
  return 42;
}
with -O2 -fdisable-tree-evrp
y is constant (__INT_MAX__), but x is certainly not constant.

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

end of thread, other threads:[~2020-10-22  8:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-21 15:14 [Bug tree-optimization/97519] New: builtin_constant_p (x + cst) should be optimized to builtin_constant_p (x) hubicka at gcc dot gnu.org
2020-10-21 16:23 ` [Bug tree-optimization/97519] " pinskia at gcc dot gnu.org
2020-10-21 16:23 ` pinskia at gcc dot gnu.org
2020-10-22  7:02 ` rguenth at gcc dot gnu.org
2020-10-22  8:23 ` jakub 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).