Browse Source

* In TAddNode.Simplify, commutative operations now ensure integer constant operands go on the right for simplicity

J. Gareth "Curious Kit" Moreton 2 years ago
parent
commit
487ca08cf3
1 changed files with 5 additions and 0 deletions
  1. 5 0
      compiler/nadd.pas

+ 5 - 0
compiler/nadd.pas

@@ -816,6 +816,11 @@ implementation
             exit;
             exit;
           end;
           end;
 
 
+        { For operations that follow the commutative law, put integer constants on the right }
+        if (nodetype in [addn,orn,xorn,andn,muln]) and
+          is_constintnode(left) and (is_integer(right.resultdef) or is_pointer(right.resultdef)) then
+          SwapLeftRight;
+
         { Add,Sub,Mul,Or,Xor,Andn with constant 0, 1 or -1?  }
         { Add,Sub,Mul,Or,Xor,Andn with constant 0, 1 or -1?  }
         if is_constintnode(right) and (is_integer(ld) or is_pointer(ld)) then
         if is_constintnode(right) and (is_integer(ld) or is_pointer(ld)) then
           begin
           begin