[PATCH] D68488: [PATCH 03/27] [noalias] [IR] Introduce ptr_provenance for LoadInst/StoreInst

Jeroen Dobbelaere via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 17 06:35:15 PDT 2020


jeroen.dobbelaere added a comment.

In D68488#2278622 <https://reviews.llvm.org/D68488#2278622>, @lebedev.ri wrote:

> I think `variant 1` is the obvious winner.
> Though while i'm not familiar with the code, i'm not sure why you'd need to move args around - can't `ptr_provenance` be added as a new last 'argument'?

This is what is done in the current patch (variant 0). I had to introduce a `NumUserOperandsDelta` to compensate, as now `getNumUserOperands() == NumUserOperands - NumUserOperandsDelta`.
This had impact on `op_end()` and `getNumUserOperands()`:

- `op_begin():  static_cast<Use*>(this)-NumUserOperands`
- `op_end(): op_begin() + NumUserOperands - NumUserOperandsDelta`
- `getNumUserOperands(): NumUserOperands - NumUserOperandsDelta`

The way how variant 1 works is the following:

- Operands are allocated before the 'this' that points to the instruction
- LoadInst/StoreInst become associated to the 'VariadicOperandTraits' (instead of the OptionalOperandTraits)
- `op_begin():  static_cast<Use*>(this)-NumUserOperands`
- `op_end(): op_begin() + NumUserOperands`
- `getNumUserOperands(): NumUserOperands`
- When we switch from 2 to 3 arguments, the operands suddenly switch place (`op_begin()` changes). The shuffling can be done like:



  void setPtrProvenance(Value *PtrProvenance) {
    if (getNumOperands() == 2) {
      setNumOperands(3);
      setOperand(0, getOperand(1));
      setOperand(1, getOperand(2));
    }
    setOperand(2, PtrProvenance);
  }

It is even likely that a more efficient mechanism for the shuffling is possible.


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

https://reviews.llvm.org/D68488



More information about the llvm-commits mailing list