<div dir="ltr"><div>  Current state:<br></div><div><br></div><div>     1/ LEA with complex addressing mode are supported by Intel micro architectures after Nehalem.</div><div><br></div><div>     2/ LEA detection is being done during SelectionDAG based instruction selection through</div><div>         addressing mode based complex pattern matching. </div><div><br></div><div>     3/ This does not identify LEA patterns beyond Scaling factor 1.</div><div>         e.g.</div><div>             T1 = A  + B;</div><div>             T2 = T1 + B;</div><div>             T3 = T2 + B;</div><div>             T4 = T3 + 10;</div><div>             T5 = T4 + 20;</div><div>             T6 = T5 + B</div><div>  </div><div>         Above sequence can be folded to </div><div>  </div><div>              LEA   30( A , 4 , B); </div><div>            </div><div>         where BASE = A, SCALE = 4, INDEX = B and OFFSET = 30 </div><div>        </div><div>     4/ Control flow information is not present at SelectionDAG level, as SelectionDAG based selection</div><div>         work over a single BasicBlock at a time. Which makes it difficult to avoid generation of</div><div>         complex LEA with 3 operands (even with Scale=1) within Loops.</div><div><br></div><div>  Proposal:</div><div><br></div><div>     1/ To have a pre-RA pass to identify LEAs with dense folding. By dense folding I mean scale factor greater than 1. </div><div><br></div><div>     2/ Since this pass will run over MachineInstrs so it will be usable for FastISel and Global ISel based flows also which </div><div>         bypass SelectionDAG. </div><div><br></div><div>     3/ At MI level we have control flow Analysis info in the form of MachineDominatorTree and MachineLoopInfo</div><div>         to avoid formation of LEAs in loops.</div><div><br></div><div>     4/ Perform CSE over dense LEAs (which have Scale factor > 1) to factor out overlapping computations.</div><div>         When two LEAs share BASE , INDEX and OFFSET but have different SCALE we can<br></div><div>         take out the common complex LEA and generate a simple LEA with legal Scale. </div><div>         e.g. </div><div>   </div><div>              LEA1 : RES1 = LEA 10( A , 4 , B) </div><div>              LEA2 : RES2 = LEA 10( A , 8 , B)</div><div>        </div><div>         can be converted to </div><div>          </div><div>              LEA1 : RES1 = LEA 10( A , 4 , B)</div><div>              LEA2 : RES2 = LEA (RES1 , 4 , B)</div><div>         </div><div>      5/  Disintegration of complex LEAs with Scale 1 to simple LEA + ADD which is already being handled during </div><div>           FixupLEAPass.</div><div><br></div><div>Kindly drop your suggestions/comments. </div><div><br></div><div>Thanks,</div><div>Jatin Bhateja</div><div><br></div></div>