History log of /llvm-project/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp (Results 1 – 25 of 126)
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
# b02e5bc5 07-Nov-2024 Kazu Hirata <kazu@google.com>

[Transforms] Remove unused includes (NFC) (#115263)

Identified with misc-include-cleaner.


# 8851ea64 04-Nov-2024 Nikita Popov <npopov@redhat.com>

[ConstantHoist] Fix APInt ctor assertion

The result here may require truncation. Fix this by removing the
calculateOffsetDiff() helper entirely. As far as I can tell, this
code does not actually hav

[ConstantHoist] Fix APInt ctor assertion

The result here may require truncation. Fix this by removing the
calculateOffsetDiff() helper entirely. As far as I can tell, this
code does not actually have to deal with different bitwidths.

findBaseConstants() will produce ranges of constants with equal
types, which is what maximizeConstantsInRange() will then work
on.

Fixes assertion reported at:
https://github.com/llvm/llvm-project/pull/114539#issuecomment-2453008679

show more ...


# 94f9cbbe 02-Nov-2024 Kazu Hirata <kazu@google.com>

[Scalar] Remove unused includes (NFC) (#114645)

Identified with misc-include-cleaner.


Revision tags: llvmorg-19.1.3
# 6ab26eab 28-Oct-2024 Ellis Hoag <ellis.sparky.hoag@gmail.com>

Check hasOptSize() in shouldOptimizeForSize() (#112626)


Revision tags: 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
# 4169338e 28-Jun-2024 Nikita Popov <npopov@redhat.com>

[IR] Don't include Module.h in Analysis.h (NFC) (#97023)

Replace it with a forward declaration instead. Analysis.h is pulled in
by all passes, but not all passes need to access the module.


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


Revision tags: llvmorg-18.1.8, llvmorg-18.1.7, llvmorg-18.1.6, llvmorg-18.1.5, llvmorg-18.1.4, llvmorg-18.1.3, llvmorg-18.1.2
# 5b59b3af 19-Mar-2024 Jeremy Morse <jeremy.morse@sony.com>

[NFC][RemoveDIs] Switch constant-hoisting to insert with iterators (#84738)

Seeing how constant-hoisting also happens to store an insertion-point in
a DenseMap, this means we have to install DenseM

[NFC][RemoveDIs] Switch constant-hoisting to insert with iterators (#84738)

Seeing how constant-hoisting also happens to store an insertion-point in
a DenseMap, this means we have to install DenseMapInfo for hashing
BasicBlock::iterators and comparing them. I'm not really sure where to
put the DenseMapInfo declarations as BasicBlock.h seems most logical,
but that then means including DenseMap.h into pretty much all of LLVM.
I've sent this up to the compile time tracker to see whether there's a
major cost from this.

---------

Merged by: Stephen Tozer <stephen.tozer@sony.com>

show more ...


# a60deaa2 18-Mar-2024 Paul Walker <paul.walker@arm.com>

[ConstantHoisting] Don't attempt to hoist ConstantInt vectors. (#85416)

The pass uses the TTI hook getIntImmCostIntrin that only supports scalar
integer types. Whilst hoisting expensive vector cons

[ConstantHoisting] Don't attempt to hoist ConstantInt vectors. (#85416)

The pass uses the TTI hook getIntImmCostIntrin that only supports scalar
integer types. Whilst hoisting expensive vector constant is likely
worthwhile, this is new behaviour and so I've followed the path taken by
the GEP variant of collectConstantCandidates and simply bail for vector
types.

show more ...


Revision tags: llvmorg-18.1.1, llvmorg-18.1.0, llvmorg-18.1.0-rc4, llvmorg-18.1.0-rc3, llvmorg-18.1.0-rc2, llvmorg-18.1.0-rc1, llvmorg-19-init
# edeaf41e 23-Jan-2024 Alina Sbirlea <asbirlea@google.com>

[ConstantHoisting] Cache OptForSize. (#79170)

CacheOptForSize to remove quadratic behavior.

For each constant analyzed, ConstantHoising calls
`shouldOptimizeForSize(F)`, which calls `PSI.getTota

[ConstantHoisting] Cache OptForSize. (#79170)

CacheOptForSize to remove quadratic behavior.

For each constant analyzed, ConstantHoising calls
`shouldOptimizeForSize(F)`, which calls `PSI.getTotalCallCount(F)`.
PSI.getTotalCallCount(F) goes through all the instructions in all basic
blocks, and checks if each is a call, to count them up.

This reduces `llc` time for a very large IR from ~10min to under 3min.
Reproducer testcase is much too large to share.

show more ...


# dea16ebd 18-Dec-2023 Paul Walker <paul.walker@arm.com>

[LLVM][IR] Replace ConstantInt's specialisation of getType() with getIntegerType(). (#75217)

The specialisation will not be valid when ConstantInt gains native
support for vector types.

This is

[LLVM][IR] Replace ConstantInt's specialisation of getType() with getIntegerType(). (#75217)

The specialisation will not be valid when ConstantInt gains native
support for vector types.

This is largely a mechanical change but with extra attention paid to constant
folding, InstCombineVectorOps.cpp, LoopFlatten.cpp and Verifier.cpp to
remove the need to call `getIntegerType()`.

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

show more ...


# 930b5b52 13-Dec-2023 Paul Walker <paul.walker@arm.com>

[ConstantHoisting] Add a TTI hook to prevent hoisting. (#69004)

Code generation can sometimes simplify expensive operations when
an operand is constant. An example of this is divides on AArch64
w

[ConstantHoisting] Add a TTI hook to prevent hoisting. (#69004)

Code generation can sometimes simplify expensive operations when
an operand is constant. An example of this is divides on AArch64
where they can be rewritten using a cheaper sequence of multiplies
and subtracts. Doing this is often better than hoisting expensive
constants which are likely to be hoisted by MachineLICM anyway.

show more ...


Revision tags: llvmorg-17.0.6, llvmorg-17.0.5, llvmorg-17.0.4, llvmorg-17.0.3, llvmorg-17.0.2, llvmorg-17.0.1, llvmorg-17.0.0, llvmorg-17.0.0-rc4, llvmorg-17.0.0-rc3
# 85eeba48 14-Aug-2023 Bjorn Pettersson <bjorn.a.pettersson@ericsson.com>

[ConstantHoisting] Add back ptr->ptr bitcast to avoid assertion failure

In commit a7ee80fab213fe7a a ptr->ptr bitcast was removed. But that
seem to cause "Expected an cast instruction!" assertions l

[ConstantHoisting] Add back ptr->ptr bitcast to avoid assertion failure

In commit a7ee80fab213fe7a a ptr->ptr bitcast was removed. But that
seem to cause "Expected an cast instruction!" assertions later in
that pass. This patch will add back the bitcast again.

This was a bit unexpected since there is no bitcast added after
creating the Add instruction in the else clause, but I guess there
is something special with the GetElementPtr scenario which makes this
bitcast needed to avoid such asserts.

This patch is also adding a reproducer for
https://github.com/llvm/llvm-project/issues/52689
that started to fail due to hitting the above mentioned assert. Now
it should end up hitting the assertion failure from #52689 again.

show more ...


# a7ee80fa 11-Aug-2023 Bjorn Pettersson <bjorn.a.pettersson@ericsson.com>

[llvm] Drop some more typed pointer bitcasts etc.


Revision tags: llvmorg-17.0.0-rc2, llvmorg-17.0.0-rc1, llvmorg-18-init
# dda3b706 17-Jul-2023 Nick Desaulniers <ndesaulniers@google.com>

[ConstantHoisting] stop rematerializing InsertionPt

Reading this code, I noticed that we call findMatInsertPt a lot, for the
same inputs. Calculate it once and save the result.

Reviewed By: MaskRay

[ConstantHoisting] stop rematerializing InsertionPt

Reading this code, I noticed that we call findMatInsertPt a lot, for the
same inputs. Calculate it once and save the result.

Reviewed By: MaskRay

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

show more ...


# bec04b4b 17-Jul-2023 Nick Desaulniers <ndesaulniers@google.com>

[ConstantHoisting] use struct rather than tuple for adjustments

We pack this info in a tuple just to spread it back out for a function
call. Spreads in C++ are awkward. If I want to add an addition

[ConstantHoisting] use struct rather than tuple for adjustments

We pack this info in a tuple just to spread it back out for a function
call. Spreads in C++ are awkward. If I want to add an additional
element to the tuple, I need to add more calls to std::get<> later. Just
use a struct.

Reviewed By: void

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

show more ...


# cb79b5b5 12-Jul-2023 Nick Desaulniers <ndesaulniers@google.com>

[ConstantHoisting] simplify NumUses accounting NFC

The `Uses` variable is unnecessary. Just use `UsesNum` instead.

Reviewed By: MaskRay

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


# 1936bb81 12-Jul-2023 Nick Desaulniers <ndesaulniers@google.com>

[ConstantHoisting] use BasicBlock::getFirstInsertionPt NFC

Rather than open coding the same implementation.

Reviewed By: MaskRay, void

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


# 63157656 11-Jul-2023 Nick Desaulniers <ndesaulniers@google.com>

[ConstantHoisting] remove a LLVM_DEBUG statement

There is no need to print the entire function after a transform via
LLVM_DEBUG statements. These can be emulated via:
$ llc -print-after=consthoist

[ConstantHoisting] remove a LLVM_DEBUG statement

There is no need to print the entire function after a transform via
LLVM_DEBUG statements. These can be emulated via:
$ llc -print-after=consthoist -filter-print-funcs=<function name>

Otherwise, this makes the output of
$ llc -debug-only=consthoist
too verbose.

Reviewed By: MaskRay

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

show more ...


Revision tags: llvmorg-16.0.6, llvmorg-16.0.5, llvmorg-16.0.4, 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 ...


Revision tags: llvmorg-16.0.0-rc3, llvmorg-16.0.0-rc2, llvmorg-16.0.0-rc1, llvmorg-17-init
# 898b5c9f 22-Jan-2023 Piotr Fusik <fox@scene.pl>

[NFC] Fix "form/from" typos

Reviewed By: #libc, ldionne

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


Revision tags: llvmorg-15.0.7
# 51b68573 16-Dec-2022 Fangrui Song <i@maskray.me>

[Transforms,CodeGen] std::optional::value => operator*/operator->

value() has undesired exception checking semantics and calls
__throw_bad_optional_access in libc++. Moreover, the API is unavailable

[Transforms,CodeGen] std::optional::value => operator*/operator->

value() has undesired exception checking semantics and calls
__throw_bad_optional_access in libc++. Moreover, the API is unavailable without
_LIBCPP_NO_EXCEPTIONS on older Mach-O platforms (see
_LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS).

show more ...


# 31521563 13-Dec-2022 Fangrui Song <i@maskray.me>

[Transforms/Scalar] llvm::Optional => std::optional


# 405fc404 07-Dec-2022 Kazu Hirata <kazu@google.com>

[ADT] Don't including None.h (NFC)

These source files no longer use None, so they do not need to include
None.h.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://

[ADT] Don't including None.h (NFC)

These source files no longer use None, so they do not need to include
None.h.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

show more ...


Revision tags: llvmorg-15.0.6, llvmorg-15.0.5, llvmorg-15.0.4, llvmorg-15.0.3, working, llvmorg-15.0.2, llvmorg-15.0.1, llvmorg-15.0.0, llvmorg-15.0.0-rc3
# 258531b7 21-Aug-2022 Kazu Hirata <kazu@google.com>

Remove redundant initialization of Optional (NFC)


123456