* handle unrolling of for ... downto ... correctly, resolves #15668

git-svn-id: trunk@14884 -
This commit is contained in:
florian 2010-02-10 21:08:54 +00:00
parent e89d0bcee3
commit 092153e7ad
3 changed files with 24 additions and 3 deletions

1
.gitattributes vendored
View File

@ -10278,6 +10278,7 @@ tests/webtbs/tw15504.pp svneol=native#text/plain
tests/webtbs/tw15530.pp svneol=native#text/pascal
tests/webtbs/tw15607.pp svneol=native#text/plain
tests/webtbs/tw15619.pp svneol=native#text/plain
tests/webtbs/tw15668.pp svneol=native#text/pascal
tests/webtbs/tw1567.pp svneol=native#text/plain
tests/webtbs/tw15690.pp svneol=native#text/plain
tests/webtbs/tw15693.pp svneol=native#text/plain

View File

@ -127,9 +127,13 @@ unit optloop;
{ for itself increases at the last iteration }
if i<unrolls then
begin
{ insert incrementation of counter var }
addstatement(unrollstatement,
geninlinenode(in_inc_x,false,ccallparanode.create(tfornode(node).left.getcopy,nil)));
{ insert incr/decrementation of counter var }
if lnf_backward in tfornode(node).loopflags then
addstatement(unrollstatement,
geninlinenode(in_dec_x,false,ccallparanode.create(tfornode(node).left.getcopy,nil)))
else
addstatement(unrollstatement,
geninlinenode(in_inc_x,false,ccallparanode.create(tfornode(node).left.getcopy,nil)));
end;
end;
{ can we get rid of the for statement? }

16
tests/webtbs/tw15668.pp Normal file
View File

@ -0,0 +1,16 @@
{ %OPT=-Ooloopunroll -O2 -S2 -Cr }
const
StrArray :array[0..1] of string = ('s1','s2');
function FindStr(const s :string) :Integer;
var
i :Integer;
begin
for i := High(StrArray) downto 0 do
if StrArray[i] = s then Exit(i);
Result := -1;
end;
begin
FindStr('s1');
end.