Bug 98966 - Failure to optimize conditional or with 1 based on boolean condition to direct or
Summary: Failure to optimize conditional or with 1 based on boolean condition to direc...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 11.0
: P3 enhancement
Target Milestone: 13.0
Assignee: Andrew Pinski
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2021-02-03 23:53 UTC by Gabriel Ravier
Modified: 2023-09-21 10:16 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-07-28 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gabriel Ravier 2021-02-03 23:53:19 UTC
int f(int m, bool c)
{
    return c ? (m | 1) : m;
}

This can be optimized to `return m | c;`. This transformation is done by LLVM, but not by GCC.
Comment 1 Andrew Pinski 2021-07-28 21:24:23 UTC
Confirmed.
Comment 2 Andrew Pinski 2022-11-26 18:53:21 UTC
A ? (b | 1) : b -> b | (convert)A

Or more generic:
(for op (...)
 (simplify
  (cond @0 (op @1 integer_one_cst) @1)
  (op @1 (convert @0)))

I think I have patches ...
Comment 3 Gabriel Ravier 2023-02-18 02:30:38 UTC
Appears to be fixed on trunk.
Comment 4 Andrew Pinski 2023-02-18 02:36:48 UTC
Fixed by r13-4459-g6508d5e5a1a8c0 .