Bug 95176 - Failure to optimize division followed by multiplication to modulo followed by subtraction
Summary: Failure to optimize division followed by multiplication to modulo followed by...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 11.0
: P3 enhancement
Target Milestone: 12.0
Assignee: Not yet assigned to anyone
URL:
Keywords: easyhack, missed-optimization
Depends on:
Blocks: 19987
  Show dependency treegraph
 
Reported: 2020-05-17 17:13 UTC by Gabriel Ravier
Modified: 2023-08-24 21:43 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-05-18 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gabriel Ravier 2020-05-17 17:13:57 UTC
int f(int a, int b)
{
    return a * (b / a);
}

This is equivalent to `return b - (b % a);`. This transformation is done by LLVM, but not by GCC.
Comment 1 Richard Biener 2020-05-18 06:28:32 UTC
Confirmed.
Comment 2 Arjun Shankar 2021-08-12 14:09:41 UTC
This appears to have been fixed as bug 96696 via the following commit:

https://gcc.gnu.org/g:3dcd1334b4f522352b80814513fdca902fc2a207
Comment 3 Arjun Shankar 2021-08-24 19:51:00 UTC
This should make it to GCC 12 when it's released, so I'm closing it accordingly.