[PATCH] D45748: [RISCV] Separate base from offset in lowerGlobalAddress

Sameer AbuAsal via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 16 10:49:04 PDT 2018


sabuasal added a comment.

In https://reviews.llvm.org/D45748#1100874, @asb wrote:

> I've started a discussion on GlobalAddress lowering strategy on llvm-dev here: http://lists.llvm.org/pipermail/llvm-dev/2018-May/123359.html
>
> Your peephole code seems well written and really solid, but I'd like to discuss the dagcombiner approach some more.  The sort of approach taken in https://reviews.llvm.org/rL330630 seems to catch the cases discussed in this thread and has a simpler implementation.


This patch is similar but it handles a different situation. What they do is process that happens before you lower a generating GlobalAddressNode into a target specific node. In that case hte selection dag comes in with a generic GlobalAddressNode that has multiple uses (before it is lowered to a target specific node). so what they do is look at all the uses,  get the smallest offset in these uses (that all consist of ADD) then updating the offset in the globalAddressnode to be ( uint64_t Offset = MinOffset + GN->getOffset();).

so the dag they are handling looks like this (all generic nodes)
 GN =  GlobalAddressNode (base + offst)

this GN has multiply uses:

1. ADDR1 = GN + off1
2. ADDR2 = GN + off2
3. ADD3 = GN + off3.

  now assuming that min (off1, off2, off3= = off1 we get: GN = GlobalAddressNode(base + off +  off1)

  ADDR1 = GN              ----> this can be optimizaed away ADDR2 = GN + off2 - off1 ADDR3 = GN + off3 - off1

In our optimization, we are operating after that since lowerGlobalAddress() is actually what is creating the ISD::ADD chained to the TargetGlobalAddress.


https://reviews.llvm.org/D45748





More information about the llvm-commits mailing list