[llvm-commits] PATCH: Move the global-copy-to-alloca optimization to InstCombine

Chris Lattner clattner at apple.com
Tue Aug 21 15:45:29 PDT 2012

On Aug 21, 2012, at 1:43 AM, Chandler Carruth <chandlerc at gmail.com> wrote:

> On Mon, Aug 20, 2012 at 9:48 AM, Chris Lattner <clattner at apple.com> wrote:
> On Aug 20, 2012, at 2:27 AM, Chandler Carruth <chandlerc at gmail.com> wrote:
> > Hello,
> >
> > I've been hacking on SROA a lot (email coming up on that front..) and one of the oddities is that SROA is doing a very instcombine-like optimization. I was able to move it over to InstCombine w/o touching any other aspect of SROA. It simplifies the model of SROA a bit, and also the optimization works much better in the instcombine framework: this is about nuking one instruction, and replacing it with another.
> Makes sense to me.
> Thanks, r162271.
> Can pointsToConstantGlobal be simplified with Value::stripInBoundsOffsets ?
> It's not clear to me that this would be an improvement... pointsToConstantGlobal get's to cheat pretty spectacularly by only ever handling constant expressions. It's also pretty simple. Any particular reason to write it using the more general value stripping? We'd still have almost as much code in order to assert that it was still a constant expression.

I was thinking that you replace this:

+static bool pointsToConstantGlobal(Value *V) {
+  if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
+    return GV->isConstant();
+  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
+    if (CE->getOpcode() == Instruction::BitCast ||
+        CE->getOpcode() == Instruction::GetElementPtr)
+      return pointsToConstantGlobal(CE->getOperand(0));
+  return false;

with this:

static bool pointsToConstantGlobal(Value *V) {
   if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V->stripInBoundsOffsets()))
     return GV->isConstant();
  return false;

which is then inlined into its only caller.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120821/11062c2f/attachment.html>

More information about the llvm-commits mailing list