<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div>I updated the patch, please review and provide feedback.<div><div><br></div><div>Update peephole optimization for X86 and ARM:</div><div>1> Interface: added SrcReg2 to analyzeCompare and optimizeCompare.</div><div>                       AnalyzeCompare to analyzeCompare ...</div><div><br></div><div>2> ARM: Clean up, no functional change.</div><div>Replaced a loop with existing interfaces: modifiesRegister and readsRegister.</div><div>Factored out code into inline functions and simplified the code.</div><div><br></div><div>3> X86: added peephole optimization to remove cmp instruction</div><div>It will optimize the following:</div><div>  sub r1, r3</div><div>  cmp r3, r1 or cmp r1, r3</div><div>  bge L1</div><div>TO</div><div>  sub r1, r3</div><div>  bge L1 or ble L1</div><div>If the branch instruction can use flag from "sub", then we can eliminate</div><div>the "cmp" instruction.</div><div><br></div><div>For this optimization, we need to first check the condition code of</div><div>SET|CMOV|Jcc and then update the condition code.</div><div><br></div><div><div>This patch implemented 4 helper functions:</div><div>getSwappedConditionForCMov</div><div>getSwappedConditionForBranch</div><div>getSwappedConditionForSET</div><div>isRedundantFlagInstr</div></div><div><br></div><div>I can't think of a way to easily update the condition code of an instruction</div><div>by adding flags in td file or data in MCInstrDesc, since the condition code</div><div>is hard-coded in the opcode.</div><div><br></div><div>From what I know, there are 3 pairs of equivalent falg instructions for ARM:</div><div>CMP vs SUB, CMN vs ADD, TST vs AND</div><div>2 pairs for X86:</div><div>CMP vs SUB, TST vs AND</div><div>If there are more pairs, or there is a better way to implement isRedundantFlagInstr, please let me know.</div><div><br></div><div>Comments are welcome.</div></div><div><br></div><div>Thanks,</div><div>Manman</div><div><br></div><div></div></body></html>