This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by bjope on Sep 22 2021, 7:44 AM.

Details

Summary

Deriving NoAlias based on having the same index in two BaseIndexOffset
expressions seemed weird (and as shown in the added unittest the
correctness of doing so depended on undocumented pre-conditions that
the user of BaseIndexOffset::computeAliasing would need to take care
of.

This patch removes the code that dereived NoAlias based on indices
being the same. As a compensation, to avoid regressions/diffs in
various lit test, we also add a new check. The new check derives
NoAlias in case the two base pointers are based on two different
GlobalValue:s (neither of them being a GlobalAlias).

Diff Detail

Event Timeline

bjope created this revision.Sep 22 2021, 7:44 AM
bjope requested review of this revision.Sep 22 2021, 7:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 22 2021, 7:44 AM
bjope added inline comments.Sep 23 2021, 12:39 AM
llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp
156

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?

nikic added a subscriber: nikic.Sep 23 2021, 12:50 AM
nikic added inline comments.
llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp
156

Accessing an object using a pointer that is based on a different object is undefined behavior under our pointer aliasing rules.

bjope added inline comments.Sep 23 2021, 1:41 AM
llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp
156

@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.

niravd accepted this revision.Oct 4 2021, 9:51 AM

LGTM.

This revision is now accepted and ready to land.Oct 4 2021, 9:51 AM
This revision was landed with ongoing or failed builds.Oct 5 2021, 3:17 AM
This revision was automatically updated to reflect the committed changes.