From 3616627d0bde75c67f2c027d79f959f5b533b906 Mon Sep 17 00:00:00 2001 From: nickysn Date: Sun, 9 Apr 2017 14:55:15 +0000 Subject: [PATCH] * at -O3 optimization level, convert "i:=not i" and "i:=-i" to the new in_not_assign_x and in_neg_assign_x inline nodes, which may generate better code on certain cpus (such as x86) git-svn-id: trunk@35758 - --- compiler/nld.pas | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/compiler/nld.pas b/compiler/nld.pas index 3a1b80f48a..b6f30331d2 100644 --- a/compiler/nld.pas +++ b/compiler/nld.pas @@ -668,6 +668,31 @@ implementation taddnode(right).left:=nil; exit; end; + { replace i:=not i by in_not_assign_x(i) + i:=-i by in_neg_assign_x(i) + todo: for some integer types, there are extra implicit + typecasts inserted by the compiler; this code should be + updated to handle them as well } + if (right.nodetype in [notn,unaryminusn]) and + (tunarynode(right).left.isequal(left)) and + + is_integer(tunarynode(right).left.resultdef) and + + ((localswitches*[cs_check_overflow,cs_check_range])=[]) and + ((right.localswitches*[cs_check_overflow,cs_check_range])=[]) and + valid_for_var(tunarynode(right).left,false) and + not(might_have_sideeffects(tunarynode(right).left)) then + begin + if right.nodetype=notn then + newinlinenodetype:=in_not_assign_x + else + newinlinenodetype:=in_neg_assign_x; + result:=cinlinenode.createintern( + newinlinenodetype,false,tunarynode(right).left); + left:=nil; + tunarynode(right).left:=nil; + exit; + end; end; end; end;