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;