[CGP] Extends the scope of optimizeMemoryInst optimization
authorSerguei Katkov <serguei.katkov@azul.com>
Sun, 5 Nov 2017 05:50:33 +0000 (05:50 +0000)
committerSerguei Katkov <serguei.katkov@azul.com>
Sun, 5 Nov 2017 05:50:33 +0000 (05:50 +0000)
commitd5d8d54b0811effd7115e060e313669619580fd1
treea9f92a592683210a2c4010bd15d60e81c93ad4ee
parent5c4cb8a9e3bd94143daf54f5d2e7c6ae280851e7
[CGP] Extends the scope of optimizeMemoryInst optimization

This is an implementation of PR26223.

Currently optimizeMemoryInst optimization tries to fold address computation
if all possible way to get compute the address are of the form

baseGV + base + scale * Index + offset
where scale and offset are constants and baseGV, base and Index are exactly
the same instructions if defined.

The patch extends this optimization to allow different bases. In this case
it tries to find/build a Phi node merging all possible bases and use this Phi node
as a base for sunk address computation. Also it supports Select instruction on
the way.

The main motivation for this scope extension is GCRelocateInst.
If there is a relocation of derived pointer it will be represented as relocation of base + offset.
Also there will be a Phi node merging address computation for relocated derived pointer
and derived pointer itself. If we have a Phi node merging original base and relocated base
and can fold the address computation of derived pointer then we can potentially reduce
the code size and Phi node for derived pointer. The later can have a positive impact to
register allocator.

Reviewers: efriedma, dberlin, mkazantsev, reames, john.brawn
Reviewed By: john.brawn
Subscribers: javed.absar, john.brawn, dneilson, llvm-commits
Differential Revision: https://reviews.llvm.org/D36073

llvm-svn: 317429
llvm/lib/CodeGen/CodeGenPrepare.cpp