diff options
author | florian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2021-03-06 14:48:15 +0000 |
---|---|---|
committer | florian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2021-03-06 14:48:15 +0000 |
commit | ede15e2b08e0b4899d361ec8d0aca87b0c16d4e1 (patch) | |
tree | df33edd917e775fef4bd0423aeafb9e9efec68e0 /tests/test | |
parent | a0128196d009c0fd064cf32c21eb5f21de079d82 (diff) | |
download | fpc-ede15e2b08e0b4899d361ec8d0aca87b0c16d4e1.tar.gz |
* do not apply the (a and b) or (c and not(b)) into c xor ((c xor a) and b) optimziation if short boolean evaluation is used, should resolve #38576
* improved test
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@48884 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'tests/test')
-rw-r--r-- | tests/test/tandorandnot1.pp | 150 |
1 files changed, 119 insertions, 31 deletions
diff --git a/tests/test/tandorandnot1.pp b/tests/test/tandorandnot1.pp index aff04507ea..f67e5dd7cd 100644 --- a/tests/test/tandorandnot1.pp +++ b/tests/test/tandorandnot1.pp @@ -1,34 +1,122 @@ { test (a and b) or (c and not(b)) into c xor ((c xor a) and b) optimization with random values } -var - i,a,b,c,_a,_b,_c : word; +procedure test_word; + var + i,a,b,c,_a,_b,_c : word; + begin + for i:=1 to 1000 do + begin + a:=random(65536); + _a:=a; + b:=random(65536); + _b:=b; + c:=random(65536); + _c:=c; + if (a and b) or (c and not(b))<>_c xor ((_c xor _a) and _b) then + begin + writeln('Error: ','a=',a,'b=',b,'c=',c); + halt(1); + end; + if (a and b) or (not(b) and c)<>_c xor ((_c xor _a) and _b) then + begin + writeln('Error: ','a=',a,'b=',b,'c=',c); + halt(1); + end; + if (not(b) and c) or (a and b)<>_c xor ((_c xor _a) and _b) then + begin + writeln('Error: ','a=',a,'b=',b,'c=',c); + halt(1); + end; + if (not(b) and c) or (b and a)<>_c xor ((_c xor _a) and _b) then + begin + writeln('Error: ','a=',a,'b=',b,'c=',c); + halt(1); + end; + end; + end; + +procedure test_boolean; + var + i : word; + a,b,c,_a,_b,_c : boolean; + begin + for i:=1 to 100 do + begin + a:=boolean(random(1)); + _a:=a; + b:=boolean(random(1)); + _b:=b; + c:=boolean(random(1)); + _c:=c; + if (a and b) or (c and not(b))<>_c xor ((_c xor _a) and _b) then + begin + writeln('Error: ','a=',a,'b=',b,'c=',c); + halt(11); + end; + if (a and b) or (not(b) and c)<>_c xor ((_c xor _a) and _b) then + begin + writeln('Error: ','a=',a,'b=',b,'c=',c); + halt(11); + end; + if (not(b) and c) or (a and b)<>_c xor ((_c xor _a) and _b) then + begin + writeln('Error: ','a=',a,'b=',b,'c=',c); + halt(11); + end; + if (not(b) and c) or (b and a)<>_c xor ((_c xor _a) and _b) then + begin + writeln('Error: ','a=',a,'b=',b,'c=',c); + halt(11); + end; + end; + end; + + +procedure test_pboolean; + var + i : word; + a,b,c : pboolean; + _a,_b,_c : boolean; + begin + new(a); + new(b); + for i:=1 to 100 do + begin + a^:=true; + _a:=a^; + b^:=true; + _b:=b^; + c:=nil; + { c should not matter in this case } + _c:=boolean(random(1)); + if (a^ and b^) or (c^ and not(b^))<>_c xor ((_c xor _a) and _b) then + begin + writeln('Error: ','a=',a^,'b=',b^,'c=',c^); + halt(21); + end; + if (a^ and b^) or (not(b^) and c^)<>_c xor ((_c xor _a) and _b) then + begin + writeln('Error: ','a=',a^,'b=',b^,'c=',c^); + halt(21); + end; + if (not(b^) and c^) or (a^ and b^)<>_c xor ((_c xor _a) and _b) then + begin + writeln('Error: ','a=',a^,'b=',b^,'c=',c^); + halt(21); + end; + if (not(b^) and c^) or (b^ and a^)<>_c xor ((_c xor _a) and _b) then + begin + writeln('Error: ','a=',a^,'b=',b^,'c=',c^); + halt(21); + end; + end; + dispose(a); + dispose(b); + end; + + begin - for i:=1 to 1000 do - begin - a:=random(65536); - _a:=a; - b:=random(65536); - _b:=b; - c:=random(65536); - _c:=c; - if (a and b) or (c and not(b))<>_c xor ((_c xor _a) and _b) then - begin - writeln('Error: ','a=',a,'b=',b,'c=',c); - halt(1); - end; - if (a and b) or (not(b) and c)<>_c xor ((_c xor _a) and _b) then - begin - writeln('Error: ','a=',a,'b=',b,'c=',c); - halt(1); - end; - if (not(b) and c) or (a and b)<>_c xor ((_c xor _a) and _b) then - begin - writeln('Error: ','a=',a,'b=',b,'c=',c); - halt(1); - end; - if (not(b) and c) or (b and a)<>_c xor ((_c xor _a) and _b) then - begin - writeln('Error: ','a=',a,'b=',b,'c=',c); - halt(1); - end; - end; + test_word; + test_boolean; + test_pboolean; end. + |