FR: fold shifts.
Presently, none of (1)–(5) fold.
{$mode objfpc} {$h+}
var
x: integer;
dummy: string;
begin
x := random(0);
// (1) - could fold to "shl 4".
x += random(0) * 2 shl 3;
// (2) - could fold to "shl 4".
x += random(0) shl 1 shl 3;
// (3) - could fold to "shl 4".
x += random(0) shl 3 * 2;
// (4) - could fold to "shr 4".
x += random(0) shr 1 shr 3;
// (5) - could fold to "shr 4".
x += integer(cardinal(random(0)) div 2 shr 3);
// (6) - folds to "shl 4".
x += random(0) * 2 * 8;
// (7) - folds to "shr 4".
x += integer(cardinal(random(0)) div 2 div 8);
WriteStr(dummy, x);
end.
Yesterday I saw an example where such folding could be useful, though I don't remember it anymore, all I remember is that multiplier was someone’s sizeof
.