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.
Created attachment 42318 [details] test2
__INT64_TYPE__ f1 (__INT64_TYPE__ i) { return (((__INT64_TYPE__)1) << 63) >> i; } is already an existing missed optimization.
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.
Note the -Os regression part was improved via r8-3504-g2891beff1aa8e6 (PR 82339).
Actually this looks almost exactly the same as PR 82339 .