mirror of
				https://gitlab.com/freepascal.org/fpc/source.git
				synced 2025-11-04 08:19:36 +01:00 
			
		
		
		
	* optimize a-const1-const2 when const1 and const2 are real constants and fast math is on, part of fixing #39782
This commit is contained in:
		
							parent
							
								
									d92bc0e760
								
							
						
					
					
						commit
						94665a40d7
					
				@ -1457,7 +1457,7 @@ implementation
 | 
			
		||||
        { slow simplifications and/or more sophisticated transformations which might make debugging harder }
 | 
			
		||||
        if cs_opt_level2 in current_settings.optimizerswitches then
 | 
			
		||||
          begin
 | 
			
		||||
            if nodetype in [addn,muln] then
 | 
			
		||||
            if nodetype in [addn,muln,subn] then
 | 
			
		||||
              begin
 | 
			
		||||
                { try to fold
 | 
			
		||||
                            op
 | 
			
		||||
@ -1470,11 +1470,27 @@ implementation
 | 
			
		||||
                }
 | 
			
		||||
                if (left.nodetype=nodetype) and
 | 
			
		||||
                  (((nodetype=addn) and ((rt=stringconstn) or is_constcharnode(right)) and ((taddnode(left).right.nodetype=stringconstn) or is_constcharnode(taddnode(left).right))) or
 | 
			
		||||
                   ((nodetype in [addn,muln]) and (cs_opt_fastmath in current_settings.optimizerswitches) and (rt=realconstn) and (taddnode(left).right.nodetype=realconstn))
 | 
			
		||||
                   ((nodetype in [addn,muln,subn]) and (cs_opt_fastmath in current_settings.optimizerswitches) and (rt=realconstn) and (taddnode(left).right.nodetype=realconstn))
 | 
			
		||||
                  ) and
 | 
			
		||||
                  (compare_defs(resultdef,left.resultdef,nothingn)=te_exact) then
 | 
			
		||||
                  begin
 | 
			
		||||
                    { SwapRightWithLeftLeft moves the nodes around in way that we need to insert a minus
 | 
			
		||||
                      on left.right: a-b-c becomes b-c-a so we
 | 
			
		||||
                      need
 | 
			
		||||
                      1) insert a minus bevor b
 | 
			
		||||
                      2) make the current node an add node, see below
 | 
			
		||||
                    }
 | 
			
		||||
                    if nodetype=subn then
 | 
			
		||||
                      begin
 | 
			
		||||
                        taddnode(left).right:=cunaryminusnode.create(taddnode(left).right);
 | 
			
		||||
                        do_typecheckpass(taddnode(left).right);
 | 
			
		||||
                      end;
 | 
			
		||||
                    Result:=SwapRightWithLeftLeft;
 | 
			
		||||
                    if nodetype=subn then
 | 
			
		||||
                      begin
 | 
			
		||||
                        Result.nodetype:=addn;
 | 
			
		||||
                        do_typecheckpass(Result);
 | 
			
		||||
                      end;
 | 
			
		||||
                    exit;
 | 
			
		||||
                  end;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user