From 7f447748528d0518d7881335b048212974039d95 Mon Sep 17 00:00:00 2001 From: florian Date: Tue, 7 Jun 2016 20:01:13 +0000 Subject: [PATCH] * i386 uses OptPass1And from aoptx86 git-svn-id: trunk@33936 - --- compiler/i386/aoptcpu.pas | 30 ++-------------------------- compiler/x86/aoptx86.pas | 42 +++++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 43 deletions(-) diff --git a/compiler/i386/aoptcpu.pas b/compiler/i386/aoptcpu.pas index cb3a708da5..87f6871f57 100644 --- a/compiler/i386/aoptcpu.pas +++ b/compiler/i386/aoptcpu.pas @@ -835,34 +835,8 @@ begin end; case taicpu(p).opcode Of A_AND: - begin - if (taicpu(p).oper[0]^.typ = top_const) and - (taicpu(p).oper[1]^.typ = top_reg) and - GetNextInstruction(p, hp1) and - (tai(hp1).typ = ait_instruction) and - (taicpu(hp1).opcode = A_AND) and - (taicpu(hp1).oper[0]^.typ = top_const) and - (taicpu(hp1).oper[1]^.typ = top_reg) and - (getsupreg(taicpu(p).oper[1]^.reg)=getsupreg(taicpu(hp1).oper[1]^.reg)) and - (getsubreg(taicpu(p).oper[1]^.reg)<=getsubreg(taicpu(hp1).oper[1]^.reg)) then - {change "and const1, reg; and const2, reg" to "and (const1 and const2), reg"} - begin - taicpu(hp1).loadConst(0,taicpu(p).oper[0]^.val and taicpu(hp1).oper[0]^.val); - asml.remove(p); - p.free; - p:=hp1; - end - else - {change "and x, reg; jxx" to "test x, reg", if reg is deallocated before the - jump, but only if it's a conditional jump (PFV) } - if (taicpu(p).oper[1]^.typ = top_reg) and - GetNextInstruction(p, hp1) and - (hp1.typ = ait_instruction) and - (taicpu(hp1).is_jmp) and - (taicpu(hp1).opcode<>A_JMP) and - not(RegInUsedRegs(taicpu(p).oper[1]^.reg,UsedRegs)) then - taicpu(p).opcode := A_TEST; - end; + if OptPass1And(p) then + continue; A_CMP: begin { cmp register,$8000 neg register diff --git a/compiler/x86/aoptx86.pas b/compiler/x86/aoptx86.pas index 6b629fd868..01605a1a96 100644 --- a/compiler/x86/aoptx86.pas +++ b/compiler/x86/aoptx86.pas @@ -1155,19 +1155,26 @@ unit aoptx86; (((taicpu(p).opsize=S_W) and (taicpu(hp1).opsize=S_BW)) or ((taicpu(p).opsize=S_L) and - (taicpu(hp1).opsize in [S_WL,S_BL])) or + (taicpu(hp1).opsize in [S_WL,S_BL])) +{$ifdef x86_64} + or ((taicpu(p).opsize=S_Q) and - (taicpu(hp1).opsize in [S_BQ,S_WQ,S_LQ])) + (taicpu(hp1).opsize in [S_BQ,S_WQ,S_LQ])) +{$endif x86_64} ) then begin - if (((taicpu(hp1).opsize) in [S_BW,S_BL,S_BQ]) and + if (((taicpu(hp1).opsize) in [S_BW,S_BL{$ifdef x86_64},S_BQ{$endif x86_64}]) and ((taicpu(p).oper[0]^.val and $ff)=taicpu(p).oper[0]^.val) ) or - (((taicpu(hp1).opsize) in [S_WL,S_WQ]) and - ((taicpu(p).oper[0]^.val and $ffff)=taicpu(p).oper[0]^.val)) or + (((taicpu(hp1).opsize) in [S_WL{$ifdef x86_64},S_WQ{$endif x86_64}]) and + ((taicpu(p).oper[0]^.val and $ffff)=taicpu(p).oper[0]^.val)) +{$ifdef x86_64} + or (((taicpu(hp1).opsize)=S_LQ) and ((taicpu(p).oper[0]^.val and $ffffffff)=taicpu(p).oper[0]^.val) - ) then + ) +{$endif x86_64} + then begin DebugMsg('Peephole AndMovzToAnd done',p); asml.remove(hp1); @@ -1175,28 +1182,33 @@ unit aoptx86; end; end else if MatchOpType(p,top_const,top_reg) and - MatchInstruction(hp1,A_MOVSX,A_MOVSXD,[]) and + MatchInstruction(hp1,A_MOVSX{$ifdef x86_64},A_MOVSXD{$endif x86_64},[]) and (taicpu(hp1).oper[0]^.typ = top_reg) and MatchOperand(taicpu(p).oper[1]^,taicpu(hp1).oper[1]^) and (getsupreg(taicpu(hp1).oper[0]^.reg)=getsupreg(taicpu(hp1).oper[1]^.reg)) and (((taicpu(p).opsize=S_W) and (taicpu(hp1).opsize=S_BW)) or ((taicpu(p).opsize=S_L) and - (taicpu(hp1).opsize in [S_WL,S_BL])) or + (taicpu(hp1).opsize in [S_WL,S_BL])) +{$ifdef x86_64} + or ((taicpu(p).opsize=S_Q) and (taicpu(hp1).opsize in [S_BQ,S_WQ,S_LQ])) +{$endif x86_64} ) then begin - if (((taicpu(hp1).opsize) in [S_BW,S_BL,S_BQ]) and + if (((taicpu(hp1).opsize) in [S_BW,S_BL{$ifdef x86_64},S_BQ{$endif x86_64}]) and ((taicpu(p).oper[0]^.val and $7f)=taicpu(p).oper[0]^.val) ) or - (((taicpu(hp1).opsize) in [S_WL,S_WQ]) and - ((taicpu(p).oper[0]^.val and $7fff)=taicpu(p).oper[0] - ^.val)) or + (((taicpu(hp1).opsize) in [S_WL{$ifdef x86_64},S_WQ{$endif x86_64}]) and + ((taicpu(p).oper[0]^.val and $7fff)=taicpu(p).oper[0]^.val)) +{$ifdef x86_64} + or (((taicpu(hp1).opsize)=S_LQ) and - ((taicpu(p).oper[0]^.val and $7fffffff)=taicpu(p).oper[0] - ^.val) - ) then + ((taicpu(p).oper[0]^.val and $7fffffff)=taicpu(p).oper[0]^.val) + ) +{$endif x86_64} + then begin DebugMsg('PeepHole Optimization,AndMovsxToAnd',p); asml.remove(hp1);