public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/111324] New: More optimization about "(X * Y) / Y"
@ 2023-09-07  8:53 guojiufu at gcc dot gnu.org
  2023-09-07  9:01 ` [Bug middle-end/111324] " guojiufu at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: guojiufu at gcc dot gnu.org @ 2023-09-07  8:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111324
           Summary: More optimization about "(X * Y) / Y"
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: guojiufu at gcc dot gnu.org
  Target Milestone: ---

For case:
------ t.c
typedef unsigned int INT;

INT
foo (INT x, INT y)
{
  if (x > 100 || y > 100)
    return 0;
  return (x * y) / y;
}
---------
gcc -O2 t.c -S -fdump-tree-optimized

  <bb 4> [local count: 467721933]:
  _1 = x_3(D) * y_4(D);
  _5 = _1 / y_4(D);

  <bb 5> [local count: 1073741824]:
  # _2 = PHI <0(2), _5(4), 0(3)>
  return _2;

While for the below case, it can be optimized.

------
typedef unsigned int INT;

INT
foo (INT x, INT y)
{
  if (x > 100 || y > 100)
    return 0;
  INT x1 = x + 1;
  INT y1 = y + 1;
  return (x1 * y1) / y1;
}
-------

The "(x1 * y1) / y1" is optimized to "x1". 

  <bb 4> [local count: 467721933]:
  x1_4 = x_2(D) + 1;

  <bb 5> [local count: 1073741824]:
  # _1 = PHI <0(2), x1_4(4), 0(3)>
  return _1;

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

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

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-07  8:53 [Bug middle-end/111324] New: More optimization about "(X * Y) / Y" guojiufu at gcc dot gnu.org
2023-09-07  9:01 ` [Bug middle-end/111324] " guojiufu at gcc dot gnu.org
2023-09-07 19:15 ` pinskia at gcc dot gnu.org
2023-09-11  3:26 ` guojiufu at gcc dot gnu.org
2023-09-13  8:43 ` guojiufu at gcc dot gnu.org
2023-09-13  8:59 ` guojiufu at gcc dot gnu.org
2023-09-18  2:30 ` guojiufu at gcc dot gnu.org
2023-09-18  2:36 ` guojiufu 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).