Bug 102188 - Over widening detection doesn't work when no range information when doing bitwise operations (|, ^, and &)
Summary: Over widening detection doesn't work when no range information when doing bit...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 12.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks: vectorizer
  Show dependency treegraph
 
Reported: 2021-09-03 08:31 UTC by Tamar Christina
Modified: 2023-07-13 18:30 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-07-13 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tamar Christina 2021-09-03 08:31:20 UTC
The following example:

#include <stdint.h>

int f( int16_t a[16] )
{
    int res = 0;
    for ( int i = 0; i < 16; i++ )
      res |= (a[i]);

    return res;
}

gets vectorized with the ORs happening as int32, but since | can't overflow or underflow the ORs could have been done as int16.  This saves 2 ORs and 4 widenings.

I would have expected overwidening detection to handle this, however that fails because VRP has no range information for `a` but in this case it's safe to do based on the type alone.
Comment 1 Andrew Pinski 2021-09-03 20:19:06 UTC
Confirmed.