Bug 118254 - missed knowing lower bits of a variable when using comparison of shorter type
Summary: missed knowing lower bits of a variable when using comparison of shorter type
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 14.2.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks: VRP
  Show dependency treegraph
 
Reported: 2024-12-30 23:53 UTC by Andrew Pinski
Modified: 2024-12-30 23:54 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2024-12-30 23:53:53 UTC
Take:
```

void foo(void);
int il=1000;

int main(void)
{
  short t = il;
  unsigned t1 = t;
  if (t1 == 0) {
#if 1
    char b = t1;
#else
    char b = il;
#endif
    if (b != 1) __builtin_unreachable();
    foo();
  }
}
```

The call to foo should be optimized away since `b` is never 1. as il&0xffff and therefor b is always 0.