Update, looked at some other cases as well, it does optimize for plusses, not for negates:
STRANGELY ENOUGH DELPHI COMPILER DOES NOT OPTIMIZE THIS SITUATION, IT JUST
PRODUCES A BUNCH OF NEGATES.
WEIRD OR WHAT... MAYBE IT'S THE LLVM COMPILER...
IS THERE A REASON FOR THIS ? MAYBE TO ALLOW RACE CONDITIONS OR TIMING CODE
TO BE WRITTEN LIKE THIS ?
IS REDUCING IT TO A SINGLE NEGATE NOT "LOGICALLY EQUIVALENT"
MAYBE PHYLOSOPHICAL ISSUE... OF "EQUIVALENCY"... TIME WISE HEHE.
MAYBE IT IS JUST AN OVER SIGHT, OR A MISSED OPPERTUNITY TO OPTIMIZE.
OR MOST LIKELY... THIS KIND OF CODE IS SIMPLY VERY RARE... MOSTLY CONSIDERED
A PROGRAMMING MISTAKE... AND THEREFORE THERE IS NO OPTIMIZATION FOR THIS...
SO THIS KINDA HINTS AT, THAT WHO-EVER WROTE THE COMPILER CONSIDERS THIS
EXOTIC/STRANGE/RARE/STRANGE/ODITY/CURIOSITY CODE AND
THAT KINDA WARRENTS A HINT OR EVEN WARNING MESSAGES
THAT THE COMPILER DETECTED SOMETHING STRANGE !
}
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
procedure Main;
var
A, B, C : integer;
begin
writeln('program started');
A := 50;
B := 25;
// C := A + B; // produces 75
// C := A +- B; // the bugged code, produces 25
// nice obfuscation ! =D and that in Delphi/Pascal ?! HOLYFUK.
// C := A +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-B; // the funny code produces 75
// C := A +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+B; // still produces 75, how ? strange ?
// NOT OPTIMIZED BY COMPILER.
// C := A -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+B; // still produces 25
// C := A ------------------------------------------------------B; // produces 75
// DOES SEEM TO BE OPTIMIZED BY COMPILER.
// C := A ++++++++++++++++++++++++++++++++++++++++++++++++++++++B; // produces 75
// C := A ++++++++++++++++++++++++-+++++++++++++++++++++++++++++B;
// IT DOES SEEM TO DO SOME KIND OF OPTIMIZATION, BUT ONLY FOR PLUSSES ?! NOT MINUSSES ?!? WHY ?!
// ISN'T THAT A BIT INCONSISTENT ?
// MAYBE BECAUSE NEGATE INFLUENCES THE FLAGS ?!?!?
// WHY DID COMPILER WRITERS TAKE THIS DECISION TO NOT "OPTIMIZE WAY MULTIPLE NEGATES"
// THAT IS WHAT I WOULD LIKE TO KNOW...........................
C := A ++++++++++-+++++++++++++-+++++++++++++-+++++++++++++++B;
// My hypothesis about what is going on above: Limited compiler operator room/buffer/processing ?
// I am starting to suspect that maybe the compiler has a limited ammount of operators that
// it can handle ?!? Is this the thruth ? I don't know yet.
// nope doesn't seem to be case see below:
// last one wins on the left side ?
// C := A -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+B; // produces 25.
// another case of insane code:
// C := A ------------------------------------------------------B; // produces 75.
// now it does produce an error
// C := A -+*******-----+++----********* B; // error
// C := A ******** B; // error
// C := A / / / / / B; // error
// C := A -- B; // produces 75
// C := A --+ B; // produces 75
// C := A -+- B; // produces 75
// C := A +-- B; // produces 75
// C := A --- B; // produces 25
// C := A ---+ B; // produces 25
// C := A +-+-+-+ B; // produces 25
// C := A +-+-+-+-+ B; // produces 75
// to solve it, count the number of negatives... unequal it will subtract equal it will add.
// (cause the negatives negate each other into positive)
writeln( A );
writeln( B );
writeln( C );
writeln('program finished');
end;
begin
try
Main;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
ReadLn;
end.
Bye for now,
Skybuck.
P.S.: My internet service provider cut the connection as I was investigating this issue and reporting on it... now I have moved on... but I will check replies anyway ofcourse ! ;)
(ISP let me know this was gonna happen so no worries ! ;)=D they working on NET)
Meanwhile I found some other interesting issues like 0 * infinity = -NAN... more interesting issue for me currently... see you later ! ;)