[Bug tree-optimization/101179] New: y % (x ? 16 : 4) and y % (4 << (2 * (bool)x)) produce different code
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Jun 23 11:05:32 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101179
Bug ID: 101179
Summary: y % (x ? 16 : 4) and y % (4 << (2 * (bool)x)) produce
different code
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
These produces different assembly:
int f1(int y)
{
const bool x = y % 100 == 0;
return y % (x ? 16 : 4) == 0;
}
int f2(int y)
{
const bool x = y % 100 == 0;
return y % (4 << (x * 2)) == 0;
}
Since they do the same calculation, I would expect them to produce the same
code.
Currently f1 produces slightly smaller code for aarch64 and x86_64.
With Clang they produce the same code (but using cmov which might not be
optimal).
More information about the Gcc-bugs
mailing list