[PATCH] D110256: [SelectionDAG] Replace error prone index check in BaseIndexOffset::computeAliasing

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 23 01:41:08 PDT 2021


bjope added inline comments.


================
Comment at: llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp:156
+      auto *GV1 = cast<GlobalAddressSDNode>(BasePtr1.getBase())->getGlobal();
+      // It doesn't make sense to access one global value using another globals
+      // values address, so we can assume that there is no aliasing in case of
----------------
nikic wrote:
> bjope wrote:
> > I'm not 100% sure about this. https://llvm.org/docs/LangRef.html#global-variables says that "code could assume that the globals are densely packed in their section and try to iterate over them as an array", so does that mean that for example a global variable `@foo` can be accessed using a global variable `@bar` as base ptr and with `(@bar - @foo)` as offset?
> Accessing an object using a pointer that is based on a different object is undefined behavior under our [pointer aliasing rules](https://llvm.org/docs/LangRef.html#pointer-aliasing-rules).
@nikic: Thanks! Well, then my assumption here seem to hold (at least for LLVM IR).

Although, afaict LangRef covers LLVM IR, and not neccessarily MIR. And SelectionDAG/DAGCombiner is a bit in-between. So when LangRef talks about pointer aliasing rules for constants, then I figure that there is no guarantee that those rules also holds for ConstantPoolSDNode objects, etc.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110256/new/

https://reviews.llvm.org/D110256



More information about the llvm-commits mailing list