Guess that peephole optimization should refrain from folding SUB (and potentially ADD) followed by a conditional.
Was going to propose another improvement to case
in addition to #40755 (related to case
having a range that covers the last possible value, so that the last check in the ladder can be changed to an unconditional jump), but instead found a bug.
This code, at -O2
+:
var
x: uint32;
begin
x := uint32(random(0) - 1); // x = 4294967295.
case x of
0 .. 1: begin writeln('x is 0 ~ 1'); halt(1); end;
5 .. 6: begin writeln('x is 5 ~ 6'); halt(2); end;
end;
end.
prints x is 0 ~ 1
. Be very careful with adding more operations esp. involving x
, they very easily make the bug vanish. :)
Edited by Rika