https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103325
Bug ID: 103325
Summary: 1 << -1 is never reduced to a constant during gimple
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
int main() {
return 1 >> (-1);
}
GCC is the only compiler I have tried (MSVC, ICC and clang/LLVM) which does not
remove the shift.
Yes this is undefined behavior but really I think it is best to reduce to
something rather than keeping around the shift. Even converting it to
__builtin_unreachable will be ok in my book.