diff --git a/compiler/cgbase.pas b/compiler/cgbase.pas index 6f1a241028..98d8514876 100644 --- a/compiler/cgbase.pas +++ b/compiler/cgbase.pas @@ -305,6 +305,9 @@ interface { return the inverse condition of opcmp } function inverse_opcmp(opcmp: topcmp): topcmp;{$ifdef USEINLINE}inline;{$endif} + { return the opcmp needed when swapping the operands } + function swap_opcmp(opcmp: topcmp): topcmp;{$ifdef USEINLINE}inline;{$endif} + { return whether op is commutative } function commutativeop(op: topcg): boolean;{$ifdef USEINLINE}inline;{$endif} @@ -551,6 +554,16 @@ implementation end; + function swap_opcmp(opcmp: topcmp): topcmp;{$ifdef USEINLINE}inline;{$endif} + const + list: array[TOpCmp] of TOpCmp = + (OC_NONE,OC_EQ,OC_LT,OC_GT,OC_LTE,OC_GTE,OC_NE,OC_AE,OC_A, + OC_BE,OC_B); + begin + swap_opcmp := list[opcmp]; + end; + + function commutativeop(op: topcg): boolean;{$ifdef USEINLINE}inline;{$endif} const list: array[topcg] of boolean = diff --git a/compiler/cgobj.pas b/compiler/cgobj.pas index 5bd8838ddc..a18efd2119 100644 --- a/compiler/cgobj.pas +++ b/compiler/cgobj.pas @@ -264,6 +264,7 @@ unit cgobj; procedure a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel); virtual; procedure a_cmp_reg_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg : tregister; const ref: treference; l : tasmlabel); virtual; procedure a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel); + procedure a_cmp_reg_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; reg: tregister; const loc: tlocation; l : tasmlabel); procedure a_cmp_ref_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; const ref: treference; const loc: tlocation; l : tasmlabel); @@ -1220,6 +1221,12 @@ implementation end; + procedure tcg.a_cmp_reg_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; reg: tregister; const loc: tlocation; l : tasmlabel); + begin + a_cmp_loc_reg_label(list,size,swap_opcmp(cmp_op),loc,reg,l); + end; + + procedure tcg.a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel); begin case loc.loc of diff --git a/compiler/ncgflw.pas b/compiler/ncgflw.pas index ca8ef23e08..695024bb06 100644 --- a/compiler/ncgflw.pas +++ b/compiler/ncgflw.pas @@ -332,7 +332,7 @@ implementation var l3,oldclabel,oldblabel : tasmlabel; temptovalue : boolean; - temp1 : treference; +// temp1 : tregister; hop : topcg; hcond : topcmp; opsize : tcgsize; @@ -368,10 +368,14 @@ implementation if t1.nodetype<>ordconstn then begin do_loopvar_at_end:=false; - tg.GetTemp(exprasmlist,t1.resulttype.def.size,tt_normal,temp1); + location_force_reg(exprasmlist,t1.location,t1.location.size,true); temptovalue:=true; +{ + temp1 := cg.getintregister(exprasmlist, + tg.GetTemp(exprasmlist,t1.resulttype.def.size,tt_normal,temp1); cg.a_load_loc_ref(exprasmlist,opsize,t1.location,temp1); location_freetemp(exprasmlist,t1.location); +} end else temptovalue:=false; @@ -407,8 +411,8 @@ implementation if temptovalue then begin - cg.a_cmp_ref_loc_label(exprasmlist,opsize,hcond, - temp1,left.location,aktbreaklabel); + cg.a_cmp_reg_loc_label(exprasmlist,opsize,hcond, + t1.location.register,left.location,aktbreaklabel); end else begin @@ -504,9 +508,9 @@ implementation { jump } if temptovalue then begin - cg.a_cmp_ref_loc_label(exprasmlist,opsize,hcond,temp1, + cg.a_cmp_reg_loc_label(exprasmlist,opsize,hcond,t1.location.register, left.location,l3); - tg.ungetiftemp(exprasmlist,temp1); +{ tg.ungetiftemp(exprasmlist,temp1); } end else begin