History log of /llvm-project/llvm/lib/Transforms/Utils/SimplifyCFG.cpp (Results 1 – 25 of 1410)
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
Revision tags: llvmorg-21-init
# 34b13959 27-Jan-2025 Jeremy Morse <jeremy.morse@sony.com>

[NFC][DebugInfo] Switch more call-sites to using iterator-insertion (#124283)

To finalise the "RemoveDIs" work removing debug intrinsics, we're
updating call sites that insert instructions to use i

[NFC][DebugInfo] Switch more call-sites to using iterator-insertion (#124283)

To finalise the "RemoveDIs" work removing debug intrinsics, we're
updating call sites that insert instructions to use iterators instead.
This set of changes are those where it's not immediately obvious that
just calling getIterator to fetch an iterator is correct, and one or two
places where more than one line needs to change.

Overall the same rule holds though: iterators generated for the start of
a block such as getFirstNonPHIIt need to be passed into insert/move
methods without being unwrapped/rewrapped, everything else can use
getIterator.

show more ...


# 81d18ad8 27-Jan-2025 Jeremy Morse <jeremy.morse@sony.com>

[NFC][DebugInfo] Make some block-start-position methods return iterators (#124287)

As part of the "RemoveDIs" work to eliminate debug intrinsics, we're
replacing methods that use Instruction*'s as

[NFC][DebugInfo] Make some block-start-position methods return iterators (#124287)

As part of the "RemoveDIs" work to eliminate debug intrinsics, we're
replacing methods that use Instruction*'s as positions with iterators. A
number of these (such as getFirstNonPHIOrDbg) are sufficiently
infrequently used that we can just replace the pointer-returning version
with an iterator-returning version, hopefully without much/any
disruption.

Thus this patch has getFirstNonPHIOrDbg and
getFirstNonPHIOrDbgOrLifetime return an iterator, and updates all
call-sites. There are no concerns about the iterators returned being
converted to Instruction*'s and losing the debug-info bit: because the
methods skip debug intrinsics, the iterator head bit is always false
anyway.

show more ...


# 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
# 67efbd0b 08-Jan-2025 Ryan Mansfield <ryan_mansfield@apple.com>

[LLVM] Fix various cl::desc typos and whitespace issues (NFC) (#121955)


# a77346ba 06-Jan-2025 Yingwei Zheng <dtcxzyw2333@gmail.com>

[IRBuilder] Refactor FMF interface (#121657)

Up to now, the only way to set specified FMF flags in IRBuilder is to
use `FastMathFlagGuard`. It makes the code ugly and hard to maintain.

This patc

[IRBuilder] Refactor FMF interface (#121657)

Up to now, the only way to set specified FMF flags in IRBuilder is to
use `FastMathFlagGuard`. It makes the code ugly and hard to maintain.

This patch introduces a helper class `FMFSource` to replace the original
parameter `Instruction *FMFSource` in IRBuilder. To maximize the
compatibility, it accepts an instruction or a specified FMF.
This patch also removes the use of `FastMathFlagGuard` in some simple
cases.

Compile-time impact:
https://llvm-compile-time-tracker.com/compare.php?from=f87a9db8322643ccbc324e317a75b55903129b55&to=9397e712f6010be15ccf62f12740e9b4a67de2f4&stat=instructions%3Au

show more ...


# cea738bc 25-Dec-2024 DaPorkchop_ <daporkchop@daporkchop.net>

[SimplifyCFG] Replace unreachable switch lookup table holes with poison (#94990)

As discussed in #94468, this causes switch lookup table entries which
are unreachable to be poison instead of fillin

[SimplifyCFG] Replace unreachable switch lookup table holes with poison (#94990)

As discussed in #94468, this causes switch lookup table entries which
are unreachable to be poison instead of filling them with a value from
one of the reachable cases.

---------

Co-authored-by: DianQK <dianqk@dianqk.net>

show more ...


Revision tags: llvmorg-19.1.6
# c4a78b6f 13-Dec-2024 Florian Hahn <flo@fhahn.com>

[SimplifyCFG] Always allow hoisting if all instructions match. (#97158)

Generalize hoistCommonCodeFromSuccessors's `EqTermsOnly` to
`AllInstsEqOnly` and always allow hoisting if all instructions ma

[SimplifyCFG] Always allow hoisting if all instructions match. (#97158)

Generalize hoistCommonCodeFromSuccessors's `EqTermsOnly` to
`AllInstsEqOnly` and always allow hoisting if all instructions match.

In that case, all instructions can be hoisted and the
original branch will be replaced and selects for PHIs are added. This
allows preserving metadata in more cases, using the existing hoisting
logic, whereas previously FoldTwoEntryPHINode would drop the metadata.


https://llvm-compile-time-tracker.com/compare.php?from=716360367fbdabac2c374c19b8746f4de49a5599&to=986b2c47df516b31d998c055400e4f62aa76edc6&stat=instructions:u

PR: https://github.com/llvm/llvm-project/pull/97158

show more ...


# d26df322 13-Dec-2024 Antonio Frighetto <me@antoniofrighetto.com>

[SimplifyCFG] Consider preds to switch in `simplifyDuplicateSwitchArms`

Allow a duplicate basic block with multiple predecessors to the
jump table to be simplified, by considering that the same basi

[SimplifyCFG] Consider preds to switch in `simplifyDuplicateSwitchArms`

Allow a duplicate basic block with multiple predecessors to the
jump table to be simplified, by considering that the same basic
block may appear in more switch cases.

show more ...


Revision tags: llvmorg-19.1.5
# 18abc7e0 25-Nov-2024 David Green <david.green@arm.com>

[PatternMatch] Introduce m_c_Select (#114328)

This matches m_Select(m_Value(), L, R) or m_Select(m_Value(), R, L).


# 2568e52a 25-Nov-2024 Phoebe Wang <phoebe.wang@intel.com>

[X86,SimplifyCFG] Support hoisting load/store with conditional faulting (Part II) (#108812)

This is a follow up of #96878 to support hoisting load/store from BBs
have the same predecessor, if load/

[X86,SimplifyCFG] Support hoisting load/store with conditional faulting (Part II) (#108812)

This is a follow up of #96878 to support hoisting load/store from BBs
have the same predecessor, if load/store are the only instructions and
the branch is unpredictable, e.g.:

```
void test (int a, int *c, int *d) {
if (a)
*c = a;
else
*d = a;
}
```

show more ...


Revision tags: llvmorg-19.1.4
# 2188a56a 15-Nov-2024 Stephen Tozer <stephen.tozer@sony.com>

[DebugInfo][SimplifyCFG] Fully propagate merged invoke DILocations (#114235)

Currently when we merge invokes as part of SimplifyCFG we apply a merge
of the invoke DILocations to the merged invoke.

[DebugInfo][SimplifyCFG] Fully propagate merged invoke DILocations (#114235)

Currently when we merge invokes as part of SimplifyCFG we apply a merge
of the invoke DILocations to the merged invoke. We also insert an
unconditional branch to the merged invoke at the positions previously
occupied by the original invokes; as this branch is part of the
substitution for the invoke it has replaced, we should propagate the
original invoke DebugLoc to it.

show more ...


# 6b995275 15-Nov-2024 Michael Maitland <michaeltmaitland@gmail.com>

[SimplifyCFG] Simplify switch instruction that has duplicate arms (#114262)

I noticed that the two C functions emitted different IR:

```
int switch_duplicate_arms(int switch_val, int v, int w) {

[SimplifyCFG] Simplify switch instruction that has duplicate arms (#114262)

I noticed that the two C functions emitted different IR:

```
int switch_duplicate_arms(int switch_val, int v, int w) {
switch (switch_val) {
default:
break;
case 0:
w = v;
break;
case 1:
w = v;
break;
}
return w;
}

int if_duplicate_arms(int switch_val, int v, int w) {
if (switch_val == 0)
w = v;
else if (switch_val == 1)
w = v;
return v0;
}
```

We generate IR that looks like this:

```
define i32 @switch_duplicate_arms(i32 %0, i32 %1, i32 %2, i32 %3) {
switch i32 %1, label %7 [
i32 0, label %5
i32 1, label %6
]

5:
br label %7

6:
br label %7

7:
%8 = phi i32 [ %3, %4 ], [ %2, %6 ], [ %2, %5 ]
ret i32 %8
}

define i32 @if_duplicate_arms(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp ult i32 %1, 2
%6 = select i1 %5, i32 %2, i32 %3
ret i32 %6
}
```

For `switch_duplicate_arms`, taking case 0 and 1 are the same since %5
and %6
branch to the same location and the incoming values for %8 are the same
from
those blocks. We could remove one on the duplicate switch targets and
update
the switch with the single target.

On RISC-V, prior to this patch, we generate the following code:
```
switch_duplicate_arms:
li a4, 1
beq a1, a4, .LBB0_2
mv a0, a3
bnez a1, .LBB0_3
.LBB0_2:
mv a0, a2
.LBB0_3:
ret

if_duplicate_arms:
li a4, 2
mv a0, a2
bltu a1, a4, .LBB1_2
mv a0, a3
.LBB1_2:
ret
```

After this patch, the O3 code is optimized to the icmp + select pair,
which
gives us the same code gen as `if_duplicate_arms`, as desired. This
results
is one less branch instruction in the final assembly.

This may help with both code size and further switch simplification. I
found
that this patch causes no significant impact to spec2006/int/ref and
spec2017/intrate/ref.

---------

Co-authored-by: Min Hsu <min@myhsu.dev>

show more ...


Revision tags: llvmorg-19.1.3
# 255a99c2 17-Oct-2024 Nikita Popov <npopov@redhat.com>

[APInt] Fix APInt constructions where value does not fit bitwidth (NFCI) (#80309)

This fixes all the places that hit the new assertion added in
https://github.com/llvm/llvm-project/pull/106524 in t

[APInt] Fix APInt constructions where value does not fit bitwidth (NFCI) (#80309)

This fixes all the places that hit the new assertion added in
https://github.com/llvm/llvm-project/pull/106524 in tests. That is,
cases where the value passed to the APInt constructor is not an N-bit
signed/unsigned integer, where N is the bit width and signedness is
determined by the isSigned flag.

The fixes either set the correct value for isSigned, set the
implicitTrunc flag, or perform more calculations inside APInt.

Note that the assertion is currently still disabled by default, so this
patch is mostly NFC.

show more ...


Revision tags: llvmorg-19.1.2
# 82ac3997 09-Oct-2024 Noah Goldstein <goldstein.w.n@gmail.com>

[SimplifyCFG] Allow merging invoke's with different attrs

Same logic as other callsites, if the attributes are intersectable, we
merge.

Closes #111713


Revision tags: llvmorg-19.1.1
# 4d4beeb4 20-Sep-2024 Noah Goldstein <goldstein.w.n@gmail.com>

[SimplifyCFG] Supporting hoisting/sinking callbases with differing attrs

Some (many) attributes can safely be dropped to enable sinking. For
example removing `nonnull` on a return/param can't affect

[SimplifyCFG] Supporting hoisting/sinking callbases with differing attrs

Some (many) attributes can safely be dropped to enable sinking. For
example removing `nonnull` on a return/param can't affect correctness.

Closes #109472

show more ...


# 5d19d55c 30-Sep-2024 Simone Campanoni <simo.xan@gmail.com>

[SimplifyCFG] Better aligned a comment. (#109307)


# f445e39a 30-Sep-2024 Nikita Popov <npopov@redhat.com>

[SimplifyCFG] Use isWritableObject() API (#110127)

SimplifyCFG store speculation currently has some homegrown code to check
for a writable object, handling the alloca special case only.

Switch i

[SimplifyCFG] Use isWritableObject() API (#110127)

SimplifyCFG store speculation currently has some homegrown code to check
for a writable object, handling the alloca special case only.

Switch it to use the generic isWritableObject() API, which means that we
also support byval arguments, allocator return values, and writable
arguments.

I've adjusted isWritableObject() to also check for the noalias attribute
when handling writable. Otherwise, I don't think that we can generalize
from at-entry writability. This was not relevant for previous uses of
the function, because they'd already require noalias for other reasons
anyway.

show more ...


# 6f194a6d 23-Sep-2024 Nikita Popov <npopov@redhat.com>

[SimplifyCFG] Avoid truncation in linear map overflow check

This is supposed to test multiplication of the linear multiplifier
with the largest value it can be multiplied with. However, if
we trunca

[SimplifyCFG] Avoid truncation in linear map overflow check

This is supposed to test multiplication of the linear multiplifier
with the largest value it can be multiplied with. However, if
we truncate TableSize-1 here, it might not actually be the largest
value. I think in practice this still works out, because in cases
where we'd truncate the value here we'd also fail the NonMonotonic
check. But to match the intent of the code, we should treat the
truncating case as overflowing.

show more ...


# 8a6248b7 23-Sep-2024 Nikita Popov <npopov@redhat.com>

[SimplifyCFG] Don't separate a load/store from its gep during sinking (#102318)

If we can sink the a load/store, but not the gep producing its pointer
operand, don't sink the load/store either. Thi

[SimplifyCFG] Don't separate a load/store from its gep during sinking (#102318)

If we can sink the a load/store, but not the gep producing its pointer
operand, don't sink the load/store either. This may prevent the gep from
being folded into an addressing mode, and may also negatively affect
further analysis.

Fixes https://github.com/llvm/llvm-project/issues/96838.

show more ...


# c9e5c42a 21-Sep-2024 Phoebe Wang <phoebe.wang@intel.com>

[X86,SimplifyCFG][NFC] Refactor code for #108812 (#109398)


# 30cdf1e9 19-Sep-2024 Nikita Popov <npopov@redhat.com>

[SimplifyCFG] Pass context instruction to isSafeToSpeculativelyExecute() (#109132)

Pass speculation target and assumption cache to
isSafeToSpeculativelyExecute() calls.

This allows speculating b

[SimplifyCFG] Pass context instruction to isSafeToSpeculativelyExecute() (#109132)

Pass speculation target and assumption cache to
isSafeToSpeculativelyExecute() calls.

This allows speculating based on dereferenceable/align assumptions, but
the primary motivation here is to avoid regressions from planned changes
to fix https://github.com/llvm/llvm-project/issues/108854.

show more ...


# 37932643 17-Sep-2024 Noah Goldstein <goldstein.w.n@gmail.com>

[SimplifyCFG] Deduce paths unreachable if they cause div/rem UB

Same we way mark a path unreachable if it may cause a nullptr
dereference, div/rem by zero or signed div/rem of INT_MIN by -1 cause
im

[SimplifyCFG] Deduce paths unreachable if they cause div/rem UB

Same we way mark a path unreachable if it may cause a nullptr
dereference, div/rem by zero or signed div/rem of INT_MIN by -1 cause
immediate UB.

Closes #109008

show more ...


Revision tags: llvmorg-19.1.0
# 419c5347 17-Sep-2024 Noah Goldstein <goldstein.w.n@gmail.com>

[SimplifyCFG] Mark div/rem as not-cheap to sink if we are replacing const denominator

Close #109007


# a0d00c94 17-Sep-2024 Andreas Jonson <andjo403@hotmail.com>

[SimplifyCFG] Swap range metadata to attribute for calls. (#108984)

Among the last usages of range metadata for call before being able to
deprecate and only have the range attribute for calls.


# af5a45b3 16-Sep-2024 Phoebe Wang <phoebe.wang@intel.com>

[X86,SimplifyCFG] Use passthru to reduce select (#108754)


12345678910>>...57