From 276d97f653f174342dca0e00f8de4a5e0fc26508 Mon Sep 17 00:00:00 2001 From: florian Date: Sat, 11 Apr 2015 13:52:29 +0000 Subject: [PATCH] * generate better code for comparisons with constants git-svn-id: trunk@30543 - --- compiler/avr/navradd.pas | 41 +++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/compiler/avr/navradd.pas b/compiler/avr/navradd.pas index 8388328498..5def115a10 100644 --- a/compiler/avr/navradd.pas +++ b/compiler/avr/navradd.pas @@ -51,7 +51,8 @@ interface cpuinfo,pass_1,pass_2,regvars,procinfo, cpupara, ncon,nset,nadd, - ncgutil,tgobj,rgobj,rgcpu,cgobj,cg64f32; + ncgutil,tgobj,rgobj,rgcpu,cgobj,cg64f32, + hlcgobj; {***************************************************************************** TAVRAddNode @@ -187,15 +188,30 @@ interface i : longint; begin pass_left_right; - force_reg_left_right(true,false); + force_reg_left_right(true,true); unsigned:=not(is_signed(left.resultdef)) or not(is_signed(right.resultdef)); if getresflags(unsigned)=F_NotPossible then - swapleftright; + begin + swapleftright; + { if we have to swap back and left is a constant, force it to a register because we cannot generate + the needed code using a constant } + if left.location.loc=LOC_CONSTANT then + hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false); + end; - current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CP,left.location.register,right.location.register)); + if right.location.loc=LOC_CONSTANT then + begin + { decrease register pressure on registers >= r16 } + if (right.location.value and $ff)=0 then + current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CPC,left.location.register,NR_R1)) + else + current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_CPI,left.location.register,right.location.value and $ff)) + end + else + current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CP,left.location.register,right.location.register)); tmpreg1:=left.location.register; tmpreg2:=right.location.register; @@ -204,14 +220,25 @@ interface if i=5 then begin tmpreg1:=left.location.registerhi; - tmpreg2:=right.location.registerhi; + if right.location.loc<>LOC_CONSTANT then + tmpreg2:=right.location.registerhi; end else begin tmpreg1:=GetNextReg(tmpreg1); - tmpreg2:=GetNextReg(tmpreg2); + if right.location.loc<>LOC_CONSTANT then + tmpreg2:=GetNextReg(tmpreg2); + end; + if right.location.loc=LOC_CONSTANT then + begin + tmpreg2:=cg.getintregister(current_asmdata.CurrAsmList,OS_8); + cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_8,(right.location.value64 shr (i*8)) and $ff,tmpreg2); + current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CPC,tmpreg1,tmpreg2)); + end + else + begin + current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CPC,tmpreg1,tmpreg2)); end; - current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CPC,tmpreg1,tmpreg2)); end; location_reset(location,LOC_FLAGS,OS_NO);