History log of /llvm-project/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp (Results 1 – 25 of 104)
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
Revision tags: llvmorg-21-init
# 8e702735 24-Jan-2025 Jeremy Morse <jeremy.morse@sony.com>

[NFC][DebugInfo] Use iterator moveBefore at many call-sites (#123583)

As part of the "RemoveDIs" project, BasicBlock::iterator now carries a
debug-info bit that's needed when getFirstNonPHI and sim

[NFC][DebugInfo] Use iterator moveBefore at many call-sites (#123583)

As part of the "RemoveDIs" project, BasicBlock::iterator now carries a
debug-info bit that's needed when getFirstNonPHI and similar feed into
instruction insertion positions. Call-sites where that's necessary were
updated a year ago; but to ensure some type safety however, we'd like to
have all calls to moveBefore use iterators.

This patch adds a (guaranteed dereferenceable) iterator-taking
moveBefore, and changes a bunch of call-sites where it's obviously safe
to change to use it by just calling getIterator() on an instruction
pointer. A follow-up patch will contain less-obviously-safe changes.

We'll eventually deprecate and remove the instruction-pointer
insertBefore, but not before adding concise documentation of what
considerations are needed (very few).

show more ...


Revision tags: llvmorg-19.1.7, llvmorg-19.1.6, llvmorg-19.1.5, llvmorg-19.1.4, llvmorg-19.1.3, llvmorg-19.1.2, llvmorg-19.1.1, llvmorg-19.1.0, llvmorg-19.1.0-rc4, llvmorg-19.1.0-rc3, llvmorg-19.1.0-rc2, llvmorg-19.1.0-rc1, llvmorg-20-init
# 8f9d156d 01-Jul-2024 Shan Huang <52285902006@stu.ecnu.edu.cn>

[DebugInfo][SeparateConstOffsetFromGEP] Fix missing debug location updates (#96849)

Fix #96841 .


# 9df71d76 28-Jun-2024 Nikita Popov <npopov@redhat.com>

[IR] Add getDataLayout() helpers to Function and GlobalValue (#96919)

Similar to https://github.com/llvm/llvm-project/pull/96902, this adds
`getDataLayout()` helpers to Function and GlobalValue, re

[IR] Add getDataLayout() helpers to Function and GlobalValue (#96919)

Similar to https://github.com/llvm/llvm-project/pull/96902, this adds
`getDataLayout()` helpers to Function and GlobalValue, replacing the
current `getParent()->getDataLayout()` pattern.

show more ...


# 2d209d96 27-Jun-2024 Nikita Popov <npopov@redhat.com>

[IR] Add getDataLayout() helpers to BasicBlock and Instruction (#96902)

This is a helper to avoid writing `getModule()->getDataLayout()`. I
regularly try to use this method only to remember it does

[IR] Add getDataLayout() helpers to BasicBlock and Instruction (#96902)

This is a helper to avoid writing `getModule()->getDataLayout()`. I
regularly try to use this method only to remember it doesn't exist...

`getModule()->getDataLayout()` is also a common (the most common?)
reason why code has to include the Module.h header.

show more ...


# b635d690 18-Jun-2024 David Green <david.green@arm.com>

[NFC] Fix laod -> load typos. NFC


Revision tags: llvmorg-18.1.8, llvmorg-18.1.7
# 8cdecd4d 27-May-2024 Nikita Popov <npopov@redhat.com>

[IR] Add getelementptr nusw and nuw flags (#90824)

This implements the `nusw` and `nuw` flags for `getelementptr` as
proposed at
https://discourse.llvm.org/t/rfc-add-nusw-and-nuw-flags-for-getelem

[IR] Add getelementptr nusw and nuw flags (#90824)

This implements the `nusw` and `nuw` flags for `getelementptr` as
proposed at
https://discourse.llvm.org/t/rfc-add-nusw-and-nuw-flags-for-getelementptr/78672.

The three possible flags are encapsulated in the new `GEPNoWrapFlags`
class. Currently this class has a ctor from bool, interpreted as the
InBounds flag. This ctor should be removed in the future, as code gets
migrated to handle all flags.

There are a few places annotated with `TODO(gep_nowrap)`, where I've had
to touch code but opted to not infer or precisely preserve the new
flags, so as to keep this as NFC as possible and make sure any changes
of that kind get test coverage when they are made.

show more ...


# 9c784817 21-May-2024 Nikita Popov <npopov@redhat.com>

[SeparateConstOffsetFromGEP] Support multiple indices in reorderGEP (#92339)

The code was essentially already ready to handle multiple indices -- we
only need to adjust the non-negative index check

[SeparateConstOffsetFromGEP] Support multiple indices in reorderGEP (#92339)

The code was essentially already ready to handle multiple indices -- we
only need to adjust the non-negative index check to check all indices,
instead of only the first one.

show more ...


Revision tags: llvmorg-18.1.6
# b4d1a606 16-May-2024 Nikita Popov <npopov@redhat.com>

[SeparateConstOffsetFromGEP] Check correct index for non-negativity

We were checking the index of GEP twice, instead of checking both
GEP and PtrGEP.


# 1650f1b3 15-May-2024 Jay Foad <jay.foad@amd.com>

Fix typo "indicies" (#92232)


# f865dbff 09-May-2024 Jeffrey Byrnes <jeffrey.byrnes@amd.com>

[SeparateConstOffsetFromGEP] Support GEP reordering for different types (#90802)

This doesn't show up in existing lit tests, but has an impact on real
code -- especially after the canonicalization

[SeparateConstOffsetFromGEP] Support GEP reordering for different types (#90802)

This doesn't show up in existing lit tests, but has an impact on real
code -- especially after the canonicalization of GEPs to i8.

Alive2 tests for the inbounds handling:

Case 1: https://alive2.llvm.org/ce/z/6bfFY3
Case 2: https://alive2.llvm.org/ce/z/DkLMLF

show more ...


Revision tags: llvmorg-18.1.5, llvmorg-18.1.4, llvmorg-18.1.3, llvmorg-18.1.2, llvmorg-18.1.1
# 2fe81ede 04-Mar-2024 Jeremy Morse <jeremy.morse@sony.com>

[NFC][RemoveDIs] Insert instruction using iterators in Transforms/

As part of the RemoveDIs project we need LLVM to insert instructions using
iterators wherever possible, so that the iterators can c

[NFC][RemoveDIs] Insert instruction using iterators in Transforms/

As part of the RemoveDIs project we need LLVM to insert instructions using
iterators wherever possible, so that the iterators can carry a bit of
debug-info. This commit implements some of that by updating the contents of
llvm/lib/Transforms/Utils to always use iterator-versions of instruction
constructors.

There are two general flavours of update:
* Almost all call-sites just call getIterator on an instruction
* Several make use of an existing iterator (scenarios where the code is
actually significant for debug-info)
The underlying logic is that any call to getFirstInsertionPt or similar
APIs that identify the start of a block need to have that iterator passed
directly to the insertion function, without being converted to a bare
Instruction pointer along the way.

Noteworthy changes:
* FindInsertedValue now takes an optional iterator rather than an
instruction pointer, as we need to always insert with iterators,
* I've added a few iterator-taking versions of some value-tracking and
DomTree methods -- they just unwrap the iterator. These are purely
convenience methods to avoid extra syntax in some passes.
* A few calls to getNextNode become std::next instead (to keep in the
theme of using iterators for positions),
* SeparateConstOffsetFromGEP has it's insertion-position field changed.
Noteworthy because it's not a purely localised spelling change.

All this should be NFC.

show more ...


Revision tags: llvmorg-18.1.0, llvmorg-18.1.0-rc4, llvmorg-18.1.0-rc3
# 7180c23c 14-Feb-2024 Jeffrey Byrnes <jeffrey.byrnes@amd.com>

[SeparateConstOffsetFromGEP] Reland: Reorder trivial GEP chains to separate constants (#81671)

Actually update tests w.r.t
https://github.com/llvm/llvm-project/commit/9e5a77f252badfc932d1e28ee99874

[SeparateConstOffsetFromGEP] Reland: Reorder trivial GEP chains to separate constants (#81671)

Actually update tests w.r.t
https://github.com/llvm/llvm-project/commit/9e5a77f252badfc932d1e28ee998746072ddc33f
and reland https://github.com/llvm/llvm-project/pull/73056

show more ...


# 99c5a66c 13-Feb-2024 Philip Reames <preames@rivosinc.com>

Revert "[SeparateConstOffsetFromGEP] Reorder trivial GEP chains to separate constants (#73056)" and follow ups

"ninja check-llvm" is failing on tip of tree.

This reverts commit ec0aa1646e9953d1a8d0

Revert "[SeparateConstOffsetFromGEP] Reorder trivial GEP chains to separate constants (#73056)" and follow ups

"ninja check-llvm" is failing on tip of tree.

This reverts commit ec0aa1646e9953d1a8d0d15dc381d3250c854572.
This reverts commit 1b65742f8c71f576381fe85d5e34579b24f2d874.

show more ...


# 1b65742f 13-Feb-2024 Jeffrey Byrnes <jeffrey.byrnes@amd.com>

[SeparateConstOffsetFromGEP] Reorder trivial GEP chains to separate constants (#73056)

In this case, a trivial GEP chain has the form:

```
%ptr = getelementptr sameType, %base, constant
%val =

[SeparateConstOffsetFromGEP] Reorder trivial GEP chains to separate constants (#73056)

In this case, a trivial GEP chain has the form:

```
%ptr = getelementptr sameType, %base, constant
%val = getelementptr sameType, %ptr, %variable
```

That is, a one-index GEP consumes another (of the same basis and result
type) one-index GEP, where the inner GEP uses a constant index and the
outer GEP uses a variable index. For chains of this type, it is trivial
to reorder them (by simply swapping the indexes). The result of doing so
is better AddrMode matching for users of the ultimate ptr produced by
GEP chain.

Future patches can extend this to support non-trivial GEP chains (e.g.
those with different basis types and/or multiple indices).

show more ...


Revision tags: llvmorg-18.1.0-rc2, llvmorg-18.1.0-rc1
# 63fe80fb 26-Jan-2024 Krzysztof Drewniak <Krzysztof.Drewniak@amd.com>

[SeperateConstOffsetFromGEP] Handle `or disjoint` flags (#76997)

This commit extends separate-const-offset-from-gep to look at the
newly-added `disjoint` flag on `or` instructions so as to preserve

[SeperateConstOffsetFromGEP] Handle `or disjoint` flags (#76997)

This commit extends separate-const-offset-from-gep to look at the
newly-added `disjoint` flag on `or` instructions so as to preserve
additional opportunities for optimization.

The tests were pre-committed in #76972.

show more ...


Revision tags: llvmorg-19-init
# 6c2fbc3a 12-Jan-2024 Nikita Popov <npopov@redhat.com>

[IRBuilder] Add CreatePtrAdd() method (NFC) (#77582)

This abstracts over the common pattern of creating a gep with i8 element
type.


# 9e5a77f2 10-Jan-2024 Nikita Popov <npopov@redhat.com>

[SeparateConstOffsetFromGEP] Always emit i8 gep

Always emit canonical i8 GEPs, don't try to preserve the original
element type. As this is a backend pass, trying to preserve the
type is not useful.


# 7954c571 04-Jan-2024 Jannik Silvanus <37809848+jasilvanus@users.noreply.github.com>

[IR] Fix GEP offset computations for vector GEPs (#75448)

Vectors are always bit-packed and don't respect the elements' alignment
requirements. This is different from arrays. This means offsets of

[IR] Fix GEP offset computations for vector GEPs (#75448)

Vectors are always bit-packed and don't respect the elements' alignment
requirements. This is different from arrays. This means offsets of
vector GEPs need to be computed differently than offsets of array GEPs.

This PR fixes many places that rely on an incorrect pattern
that always relies on `DL.getTypeAllocSize(GTI.getIndexedType())`.
We replace these by usages of `GTI.getSequentialElementStride(DL)`,
which is a new helper function added in this PR.

This changes behavior for GEPs into vectors with element types for which
the (bit) size and alloc size is different. This includes two cases:

* Types with a bit size that is not a multiple of a byte, e.g. i1.
GEPs into such vectors are questionable to begin with, as some elements
are not even addressable.
* Overaligned types, e.g. i16 with 32-bit alignment.

Existing tests are unaffected, but a miscompilation of a new test is fixed.

---------

Co-authored-by: Nikita Popov <github@npopov.com>

show more ...


Revision tags: llvmorg-17.0.6, llvmorg-17.0.5
# af50d6ef 02-Nov-2023 Nikita Popov <npopov@redhat.com>

[SeparateConstOffsetFromGEP] Avoid use of ConstantExpr::getCast()

Try to constant fold, otherwise fall back to generating an
instruction.


Revision tags: llvmorg-17.0.4, llvmorg-17.0.3
# 80fa5a63 10-Oct-2023 Nikita Popov <npopov@redhat.com>

[ValueTracking] Use SimplifyQuery in haveNoCommonBitsSet() (NFC)

Pass SimplifyQuery instead of unpacked list of arguments.


Revision tags: llvmorg-17.0.2, llvmorg-17.0.1, llvmorg-17.0.0, llvmorg-17.0.0-rc4, llvmorg-17.0.0-rc3
# c7d65e44 11-Aug-2023 Paul Walker <paul.walker@arm.com>

[IR] Enable load/store/alloca for arrays of scalable vectors.

Differential Revision: https://reviews.llvm.org/D158517


Revision tags: llvmorg-17.0.0-rc2, llvmorg-17.0.0-rc1, llvmorg-18-init
# f2596b75 22-Jun-2023 Matt Arsenault <Matthew.Arsenault@amd.com>

SeparateConstOffsetFromGEP: Don't use SCEV

This was only using the SCEV expressions as a map key, which we can do
just as well with the value pointers. This also allows it to handle
vectors.


# 574f2bac 24-Jun-2023 Matt Arsenault <Matthew.Arsenault@amd.com>

SeparateConstOffsetForGEP: Remove some typed pointer code


Revision tags: llvmorg-16.0.6, llvmorg-16.0.5, llvmorg-16.0.4
# 2e3cabe1 05-May-2023 Tom Stellard <tstellar@redhat.com>

[SeparateConstOffsetFromGEP] Fix bug handling negative offsets

Fix bug constants and sub instructions

When finding constants in a chain starting with the RHS operator of
sub instructions, we were n

[SeparateConstOffsetFromGEP] Fix bug handling negative offsets

Fix bug constants and sub instructions

When finding constants in a chain starting with the RHS operator of
sub instructions, we were negating the constant before zero extending
it, which is incorrect.

Unfortunately, I was unable to find a simple way to implement this
transformation correctly, so for now I just disabled this optimization
for constants that feed into the RHS of a sub.

Resolves #62379

Transformation from alive2.llvm.org:

define i16 @src(i8 %a, i8 %b, i8 %c) {
entry:
%0 = sub nuw nsw i8 %c, %a
%1 = sub nuw nsw i8 %b, %0
%2 = zext i8 %1 to i16
ret i16 %2
}

Before/Bad:

define i16 @tgt(i8 %a, i8 %b, i8 %c) {
entry:
%0 = zext i8 %a to i16
%1 = zext i8 %b to i16
%c_neg = sub i8 0, %c
%c_zext = zext i8 %c_neg to i16
%2 = sub i16 0, %0
%3 = sub i16 %1, %2
%4 = add i16 %3, %c_zext
ret i16 %4
}

Correct:

define i16 @tgt(i8 %a, i8 %b, i8 %c) {
entry:
%0 = zext i8 %a to i16
%1 = zext i8 %b to i16
%c_zext = zext i8 %c to i16
%c_neg = sub i16 0, %c_zext
%2 = sub i16 0, %0
%3 = sub i16 %1, %2
%4 = add i16 %3, %c_neg
ret i16 %4
}

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D149507

show more ...


Revision tags: llvmorg-16.0.3, llvmorg-16.0.2, llvmorg-16.0.1, llvmorg-16.0.0, llvmorg-16.0.0-rc4
# 916425b2 23-Feb-2023 Krzysztof Drewniak <Krzysztof.Drewniak@amd.com>

[llvm] Use pointer index type for more GEP offsets (pre-codegen)

Many uses of getIntPtrType() were using that type to calculate the
neened type for GEP offset arguments. However, some time ago,
Data

[llvm] Use pointer index type for more GEP offsets (pre-codegen)

Many uses of getIntPtrType() were using that type to calculate the
neened type for GEP offset arguments. However, some time ago,
DataLayout was extended to support pointers where the size of the
pointer is not equal to the size of the values used to index it.

Much code was already migrated to, for example, use getIndexSizeInBits
instead of getPtrSizeInBits, but some rewrites still used
getIntPtrType() to get the type for GEP offsets.

This commit changes uses of getIntPtrType() to getIndexType() where
they are involved in a GEP-related calculation.

In at least one case (bounds check insertion) this resolves a compiler
crash that the new test added here would previously trigger.

This commit does not impact
- C library-related rewriting (memcpy()), which are operating under
the assumption that intptr_t == size_t. While all the mechanisms for
breaking this assumption now exist, doing so is outside the scope of
this commit.
- Code generation and below. Note that the use of getIntPtrType() in
CodeGenPrepare will be changed in a future commit.
- Usage of getIntPtrType() in any backend

Depends on D143435

Reviewed By: arichardson

Differential Revision: https://reviews.llvm.org/D143437

show more ...


12345