http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48688
Summary: [x64]: shift/or instead of lea Product: gcc Version: 4.5.1 Status: UNCONFIRMED Severity: minor Priority: P3 Component: rtl-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: piotr.wyder...@gmail.com There is a missing optimization in expressions such as: unsigned v = ... r = (v << k) | m where k and m are constants. GCC generates: shl\sal $k, %rN or $m, %rN If the expression is replaced with: r = (v << k) + m GCC correctly folds it into a single lea: lea m(,%rN, k), %rM If k is small (on x86/x64 k = 1, 2, 4, 8) and m < (1 << k) then both expressions are equivalent, but GCC does not notice that fact.