Bug 82454

Summary: Possible future performance regression in x86 for 64-bit constant expansions
Product: gcc Reporter: Sudakshina Das <sudi.das>
Component: rtl-optimizationAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: enhancement Keywords: missed-optimization
Priority: P3    
Version: 8.0   
Target Milestone: ---   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82339
Host: Target: x86_64-*-*, i?86-*-*
Build: Known to work:
Known to fail: Last reconfirmed: 2023-08-03 00:00:00
Attachments: test1
test2

Description Sudakshina Das 2017-10-06 16:57:08 UTC
Created attachment 42317 [details]
test1

As per the discussions on 

https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00570.html
https://gcc.gnu.org/ml/gcc-patches/2017-08/msg00039.html
https://gcc.gnu.org/ml/gcc-patches/2017-09/msg01736.html

The patch to add a simplification of 1U << (31 - x) for PR 80131, may lead to a performance regression for x86.

I am adding the tests that Jakub mentioned as a runtime performance regression tests.
Comment 1 Sudakshina Das 2017-10-06 16:57:49 UTC
Created attachment 42318 [details]
test2
Comment 2 Richard Biener 2017-10-09 11:54:20 UTC
__INT64_TYPE__ f1 (__INT64_TYPE__ i)
{
  return (((__INT64_TYPE__)1) << 63) >> i;
}

is already an existing missed optimization.
Comment 3 Richard Biener 2017-10-09 11:58:39 UTC
Note the missed-optimization is that any

 (1 << C) >> x

can be instead written as

 1 << C - x

iff we know that C - x > 0.  For C == precision(x)-1 we can infer that
directly from x being mentioned in the shift.
Comment 4 Andrew Pinski 2023-08-04 00:28:14 UTC
Note the -Os regression part was improved via r8-3504-g2891beff1aa8e6 (PR 82339).
Comment 5 Andrew Pinski 2023-08-04 00:30:22 UTC
Actually this looks almost exactly the same as PR 82339 .