This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Introduce and use DAG.getPointerAdd()
AbandonedPublic

Authored by arichardson on Dec 2 2019, 11:55 AM.

Details

Reviewers
spatel
bogner
Summary

This change does not change functionality but I believe it does slightly
increase readability.

Additionally, this change is required for our out-of-tree CHERI backend
(https://github.com/CTSRD-CHERI/llvm-project). We use a separate register
type to store pointers (128-bit capabilities, which are effectively
unforgeable and monotonic fat pointers). These capabilities permit a
reduced set of operations and therefore use a separate ValueType (iFATPTR).
to represent pointers implemented as capabilities.
Therefore, we can no longer use ISD::ADD for our patterns that operate on
pointers and added a DAG.getPointerAdd() function that uses a custom
ISD::PTRADD opcode.

Committing this change will significantly reduce our merge conflicts
for each upstream merge.

I noticed that this is effectively the same as getMemBasePlusOffset().
However, that function only allows unsigned arguments.
The only other difference is that the operands are in the same order as
DAG.getNode(). Should I be using getMemBasePlusOffset() instead and add
an overload that takes an SDNode and a signed offset?

To find potential opportunities to use getPointerAdd() I looked at
all ISD::ADD uses found with the regex getNode\(ISD::ADD,.+,.+Ptr
in lib/CodeGen/SelectionDAG. If this patch is accepted I will convert
the files in the individual backens too.

Diff Detail

Event Timeline

arichardson created this revision.Dec 2 2019, 11:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 2 2019, 11:55 AM
spatel added a comment.Dec 4 2019, 1:13 PM

This looks like a good change to me, but I think we should split it into smaller patches to reduce risk.
Since getMemBasePlusOffset() takes an "unsigned", it should be safe to modify that to take an int64_t, right? So something like this:

  1. Change getMemBasePlusOffset to take int64_t.
  2. (Optionally) change the name/signature - I don't have a strong preference on this, but the SDLoc param should remain "const SDLoc &DL" because that was intentionally changed to a reference for efficiency.
  3. Add uses for the form that takes a int64_t.
  4. Add the variant that takes an "SDValue Offset" and convert existing code to use it.