34149 Commits

Author SHA1 Message Date
Marco Elver
4eef2e30d6 [ThreadSanitizer] Add fallback DebugLocation for memintrinsic calls
When building with debug info enabled, some load/store instructions do
not have a DebugLocation attached. When using the default IRBuilder, it
attempts to copy the DebugLocation from the insertion-point instruction.
When there's no DebugLocation, no attempt is made to add one.

Add a fallback DebugLocation with the help of InstrumentationIRBuilder for
memintrinsics. In particular, the compiler may optimize load/store without
debug info into memintrinsics, which then are missing debug info as well.
2023-07-17 17:52:16 +02:00
Jakob Koschel
913f7e93da [SanitizerCoverage] Add fallback DebugLocation for instrumented calls
When building the kernel with LTO, KCOV & debug information enabled,
multiple inlinable SanitizerCoverage functions require debug information
present.

In such cases we repurpose the InstrumentationIRBuilder that ensures
the necessary debug information is added if necessary.

This has been done analogous to the work for the ThreadSanitizer
in D124937.

Bug: https://github.com/ClangBuiltLinux/linux/issues/1721

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D155377
2023-07-17 17:52:06 +02:00
Jakob Koschel
4a8b124930 [AddressSanitizer] Add fallback DebugLocation for instrumented calls
When building the kernel with LTO, KASAN & debug information enabled,
multiple inlinable AddressSanitizer functions require debug information
present.

In such cases we repurpose the InstrumentationIRBuilder that ensures
the necessary debug information is added if necessary.

This has been done analogous to the work for the ThreadSanitizer
in D124937.

Bug: https://github.com/ClangBuiltLinux/linux/issues/1721

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D155376
2023-07-17 17:51:33 +02:00
Aleksandr Popov
bca5501869 [IRCE] Add NSW flag to main loop's indvar base
We have guarantees that induction variable will not overflow in the main
loop after the loop constrained. Therefore we can add no wrap flags on
its base in order not to miss info that loop is countable.

Add NSW flag now, since adding NUW flag requires a bit more complicated
analysis.

Reviewed By: skatkov

Differential Revision: https://reviews.llvm.org/D154954
2023-07-17 01:03:52 +02:00
Weining Lu
a926a2660a [Triple] Add llvm::Triple::isLoongArch{32,64}
Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D155163
2023-07-17 20:34:35 +08:00
Nuno Lopes
68f1391a62 [ScalarizeMaskedMemIntrin] Use poison instead of undef as placeholder [NFC]
This is used for masked out lanes, that are replaced with the passthrough value
2023-07-17 10:11:14 +01:00
Nuno Lopes
89552f3a38 [InferAddressSpaces] Use poison instead of undef as placeholder [NFC]
This placeholder is only used during the execution of the algorithm, and it's patched with a
concrete value at the end
2023-07-16 22:33:09 +01:00
Nuno Lopes
f32a9c3bc6 [LoopIdiomRecognize] Use poison instead of undef as placeholder [NFC]
It was using undef as placeholder for getting the TTI cost for cttz
While at it, update the comments about cttz's last argument (is_zero_poison)
2023-07-16 22:33:09 +01:00
ManuelJBrito
ace9b6bbf5 [NewGVN] Canonicalize expressions for commutative intrinsics
Ensure that commutative intrinsics that only differ by a permutation
of their operands get the same value number by sorting the operand value
numbers.

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

Differential Revision: https://reviews.llvm.org/D155309
2023-07-16 17:24:17 +01:00
Maksim Kita
da822ce90e [InstCombine] Generalise ((x1 ^ y1) | (x2 ^ y2)) == 0 transform
Generalise ((x1 ^ y1) | (x2 ^ y2)) == 0 transform to more than two pairs of variables https://github.com/llvm/llvm-project/issues/57831.
Depends D154384.

Reviewed By: goldstein.w.n, nikic

Differential Revision: https://reviews.llvm.org/D154306
2023-07-15 16:57:16 -05:00
khei4
b02d349cbf Revert "Revert "[MemCpyOpt] implement single BB stack-move optimization which unify the static unescaped allocas""
This reverts commit 36a6eb7d12a9f827bf3d5d4e5fdc68b8a62807b2.

[MemCpyOpt] check that load/store and dest/src alloca are all in the same bb

Differential Revision: https://reviews.llvm.org/D153453
Co-authored-by: serge-sans-paille <sguelton@mozilla.com>
2023-07-15 16:27:38 +09:00
Johannes Doerfert
55544518c6 [Attributor] Allow IR-attr deduction for non-IPO amendable functions
If the function is non-IPO amendable we do skip most attributes/AAs.
However, if an AA has a isImpliedByIR that can deduce the attribute from
other attributes, we can run those. For now, we manually enable them,
if we have more later we can use some automation/flag.
2023-07-14 13:54:04 -07:00
Alexey Bataev
8ab962e411 [SLP]Relax assertion to check if the input scalars were extended to
match the size of base node (PR63668).

Need to adjust the check for assert and take into account case where the
original scalars are reused and were extended to match the vector factor
of the reused SLP node.
2023-07-14 07:19:49 -07:00
Alexey Bataev
bc8abb42bb Revert "[SLP]Relax assertion to check if the input scalars were extended to"
This reverts commit 6fdfc81287ecdc2a7f409d08538ec6ce2bd698da to fix the
check in the assert )need to use end, nod begin function).
2023-07-14 07:04:06 -07:00
Benjamin Kramer
6e55370b81 Hide some implementation details so they can't cause ODR conflicts. NFC. 2023-07-14 15:54:04 +02:00
Alexey Bataev
6fdfc81287 [SLP]Relax assertion to check if the input scalars were extended to
match the size of base node (PR63668).

Need to adjust the check for assert and take into account case where the
original scalars are reused and were extended to match the vector factor
of the reused SLP node.
2023-07-14 06:48:25 -07:00
Alexandros Lamprineas
bb6d60bf9d [FuncSpec][NFC] Sink cast into function.
Before looking up a value in the map of known constants we attempt
to dynamically cast it. The code looks cleaner if we move the cast
inside findConstantFor(), where the look up happens.

Differential Revision: https://reviews.llvm.org/D155177
2023-07-14 14:00:23 +01:00
Nikita Popov
21827268ad [InstCombine] Fold add of zext and sext of i1
(zext a) + (sext a) is 0 if a is a bool.

The regression is in a fuzzer-generated test.

Proof: https://alive2.llvm.org/ce/z/KotnN6
2023-07-14 14:52:13 +02:00
Nikita Popov
dc2b2ae7dc [InstCombine] Fold cttz of lowest set bit
cttz(-a & a) is the same as cttz(a). -a & a is an idiom to extract
the lowest set bit, which naturally does not affect the number of
trailing zeroes.

Proof: https://alive2.llvm.org/ce/z/Yp26x7
2023-07-14 14:31:35 +02:00
Jay Foad
9ff71814cb [EarlyCSE] Do not CSE convergent calls with memory effects
D149348 did this for readnone calls, which are handled by SimpleValue.
This patch does the same for all other CSEable calls, which are handled
by CallValue.

Differential Revision: https://reviews.llvm.org/D153151
2023-07-14 11:43:41 +01:00
Nikita Popov
cd1dcd2c95 [InstCombine] Handle const select arm in foldSelectCtlzToCttz()
The select arm that takes the ctlz result can also instead be a
constant with the bit width (as this is what the ctlz evaluates to
for a==0).

This avoids a regression when strengthening the
simplifyWithOpReplaced() fold.

Proof: https://alive2.llvm.org/ce/z/DMRL5A
2023-07-14 12:00:39 +02:00
Nikita Popov
3eae1bf4c2 [llvm] Remove uses of getNonOpaquePointerElementType() (NFC) 2023-07-14 11:52:13 +02:00
Nikita Popov
06807957c5 [llvm] Remove uses of hasSameElemenTypeAs() (NFC)
Always returns true with opaque pointers.
2023-07-14 10:32:43 +02:00
Nikita Popov
61e0822efa [llvm][clang] Remove uses of isOpaquePointerTy() (NFC)
This now always returns true (for pointer types).
2023-07-14 10:27:58 +02:00
Nikita Popov
0d81093742 [llvm] Remove calls to supportsTypedPointers() (NFC)
Always returns false now.
2023-07-14 09:34:46 +02:00
Noah Goldstein
ddd18d02c7 [InstCombine] Transform icmp eq/ne ({su}div exact X,Y),C -> icmp eq/ne X, Y*C
We can do this if `Y*C` doesn't overflow. This is trivial if `C` is
0/1. Otherwise we actually generate a `mul` instruction iff the `div`
has one use.

Alive2 Links:
    udiv: https://alive2.llvm.org/ce/z/GWPW67
    sdiv: https://alive2.llvm.org/ce/z/bUoX9h

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D150091
2023-07-13 19:36:59 -05:00
Nikita Popov
ddb46abd3c [LSR] Don't consider users of constant outside loop
In CollectLoopInvariantFixupsAndFormulae(), LSR looks at users
outside the loop. E.g. if we have an addrec based on %base, and
%base is also used outside the loop, then we have to keep it in a
register anyway, which may make it more profitable to use
%base + %idx style addressing.

This reasoning doesn't hold up when the base is a constant, because
the constant can be rematerialized. The lsr-memcpy.ll test regressed
when enabling opaque pointers, because inttoptr (i64 6442450944 to ptr)
now also has a use outside the loop (previously it didn't due to a
pointer type difference), and that extra "use" results in worse use
of addressing modes in the loop. However, the use outside the loop
actually gets rematerialized, so the alleged register saving does
not occur.

The same reasoning also applies to other types of constants, such
as global variable references.

Differential Revision: https://reviews.llvm.org/D155073
2023-07-13 12:22:38 +02:00
khei4
36a6eb7d12 Revert "[MemCpyOpt] implement single BB stack-move optimization which unify the static unescaped allocas"
This reverts commit 96ae0851c26237378fa1280b0a9ad713e1b72bdb.
2023-07-13 18:04:49 +09:00
khei4
96ae0851c2 [MemCpyOpt] implement single BB stack-move optimization which unify the static unescaped allocas
Differential Revision: https://reviews.llvm.org/D153453
2023-07-13 14:52:30 +09:00
Noah Goldstein
d50c1fcb5d [InstCombine] Fold (icmp eq/ne (zext i1 X) (sext i1 Y))-> (icmp eq/ne (or X, Y), 0)
This comes up when adding two `bool` types in C/C++
```
    bool foo(bool a, bool b) {
        return a + b;
    }
    ...
    ->
    define i1 @foo(i1 %a, i1 %b) {
        %conv = zext i1 %a to i32
        %conv3.neg = sext i1 %b to i32
        %tobool4 = icmp ne i32 %conv, %conv3.neg
        ret i1 %tobool4
}
```

Proof: https://alive2.llvm.org/ce/z/HffWAN

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D154574
2023-07-12 17:17:52 -05:00
Mircea Trofin
95d833d7c3 [nfc] rename AM to MAM in PGOInstrumentation
Consistency with how we tend to name `ModuleAnalysisManager` parameters.
2023-07-12 14:45:58 -07:00
Mircea Trofin
cdfd1475c0 [nfc] simplify promoteIndirectCalls
There's no caller to `promoteIndirectCalls` that would pass a nullptr
`ModuleAnalysisManager`, so passing it by reference does away with a
bunch of nullptr tests, and also removes the need for a "OwnedORE".

Differential Revision: https://reviews.llvm.org/D155027
2023-07-12 14:20:06 -07:00
Shilei Tian
bcba20b5d0 [Attributor] Add AAAddressSpace to deduce address spaces
This patch adds initial support for the `AAAddressSpace` abstract
attributor interface to deduce and query address space information for a
pointer. We simply query the underlying objects that a pointer can point
to and find a common address space if they exist. This is the minimal
support for the interface, we currently manifest changes on loads and
stores. Additionally we should use the target transform information to
deduce if an address space transformation is a no-op for the target
machine when calculating compatibility.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D120586
2023-07-12 15:47:41 -04:00
Eli Friedman
60712732ea [IndVars] Teach replaceCongruentIVs to avoid scrambling induction variables
replaceCongruentIVs analysis is based on ScalarEvolution; this makes
comparing different PHIs and performing the replacement straightforward.
However, it can have some side-effects: it isn't aware whether an
induction variable is in canonical form, so it can perform replacements
which obscure the meaning of the IR.

In test22 in widen-loop-comp.ll, the resulting loop can't be analyzed by
ScalarEvolution at all.

My attempted solution is to restrict the transform: don't try to replace
induction variables using PHI nodes that don't represent simple
induction variables.

I'm not sure if this is the best solution; suggestions welcome.

Differential Revision: https://reviews.llvm.org/D121950
2023-07-12 12:27:39 -07:00
Anna Thomas
1159266734 [SLP] Add support for fmaximum/fminimum reduction
This patch adds support for vectorized reduction of maximum/minimum
intrinsics which are under the appropriate reduction kind.

Differential Revision: https://reviews.llvm.org/D154463
2023-07-12 15:22:38 -04:00
Matt Arsenault
0f4eb557e8 ValueTracking: Replace CannotBeNegativeZero
This is now just a wrapper around computeKnownFPClass.
2023-07-12 13:14:05 -04:00
Nick Desaulniers
cb79b5b571 [ConstantHoisting] simplify NumUses accounting NFC
The `Uses` variable is unnecessary. Just use `UsesNum` instead.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D155020
2023-07-12 09:53:46 -07:00
Nick Desaulniers
1936bb81aa [ConstantHoisting] use BasicBlock::getFirstInsertionPt NFC
Rather than open coding the same implementation.

Reviewed By: MaskRay, void

Differential Revision: https://reviews.llvm.org/D154996
2023-07-12 09:40:54 -07:00
Nikita Popov
b75254270e [SCEVExpander] Remove GEP add rec splitting code (NFCI)
I don't believe this is relevant anymore with opaque pointers,
where we always expand the entire offset, without splitting it into
parts.
2023-07-12 16:53:51 +02:00
Peixin Qiao
ab73bd3897 [InstCombine] Enhance select icmp and folding
This folds (a << k) ? 2^k * a : 0 to 2^k * a.

https://alive2.llvm.org/ce/z/_dDRjo

Fix #62155.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D148420
2023-07-12 22:39:45 +08:00
Jie Fu
67f1e8d737 [Transforms] Remove FactorOutConstant to fix -Wunneeded-internal-declaration (NFC)
/Users/jiefu/llvm-project/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp:293:13: error: function 'FactorOutConstant' is not needed and will not be emitted [-Werror,-Wunneeded-internal-declaration]
static bool FactorOutConstant(const SCEV *&S, const SCEV *&Remainder,
            ^
1 error generated.
2023-07-12 21:57:12 +08:00
Nikita Popov
94abecca6b [IVDescriptors] Remove typed pointer support (NFC)
This also removes the element type from the descriptor, as it is
always i8. The meaning of the step is now the same between
integers and pointers.
2023-07-12 15:48:29 +02:00
Nikita Popov
02ba40593d [SCEVExpander] Remove typed pointer support (NFC) 2023-07-12 15:34:58 +02:00
Nikita Popov
d69033d245 [SCEVExpander] Fix GEP IV inc reuse logic for opaque pointers
Instead of checking the pointer type, check the element type of
the GEP.

Previously we ended up reusing GEP increments that were not in
expanded form, thus not respecting LSRs choice of representation.

The change in 2011-10-06-ReusePhi.ll recovers a regression that
appeared when converting that test to opaque pointers.

Changes in various Thumb tests now compute the step outside the
loop instead of using add.w inside the loop, which is LSR's
preferred representation for this target.
2023-07-12 11:32:13 +02:00
Aleksandr Popov
cdcefd2f9a [IRCE] Implement runtime overflow check for computed range's end
Here is activated check elimination which was parsed previously in
https://reviews.llvm.org/D154069

* Added runtime check that computed range's boundary doesn't overflow in
terms of range type.

* From the statement INT_MIN <= END <= INT_MAX is inferred check:
isNonNegative(INT_MAX - END) * isNonNegative(END - INT_MIN).

* If overflow happens, check will return 0 and the safe interval will be
empty.

Reviewed By: skatkov

Differential Revision: https://reviews.llvm.org/D154188
2023-07-12 11:19:25 +02:00
Dhruv Chawla
20ae2d200d
[InstCombine] Generalize foldAndOrOfICmpEqZeroAndICmp
This patch generalizes the fold implemented by foldAndOrOfICmpEqZeroAndICmp,
which are:

(icmp eq X, 0) | (icmp ult Other, X) -> (icmp ule Other, X-1)
(icmp ne X, 0) & (icmp uge Other, X) -> (icmp ugt Other, X-1)

to the following:

(icmp eq X, C) | (icmp ult Other, (X - C)) -> (icmp ule Other, (X - (C + 1)))
(icmp ne X, C) & (icmp uge Other, (X - C)) -> (icmp ugt Other, (X - (C + 1)))

The function foldAndOrOfICmpEqZeroAndICmp is also renamed to
foldAndOrOfICmpEqConstantAndICmp to reflect the changes.

Proofs: https://alive2.llvm.org/ce/z/yXGv6q

Fixes #63749.

Differential Revision: https://reviews.llvm.org/D154937
2023-07-12 11:13:37 +05:30
Matt Arsenault
f3059e223d GlobalOpt: Drop code for handling pointer bitcasts
I got confused and must have closed the wrong revision for
https://reviews.llvm.org/D149291
2023-07-11 21:05:18 -04:00
Matt Arsenault
6640df94f9 ValueTracking: Remove CannotBeOrderedLessThanZero
Replace the last user of CannotBeOrderedLessThanZero with new
version. Makes assumes work in this case.
2023-07-11 20:42:18 -04:00
Matt Arsenault
3701ebe76b AtomicExpand: Fix expanding atomics into unconstrained FP in strictfp functions
Ideally the normal fadd/fmin/fmax this was creating would fail the verifier.
It's probably also necessary to force off FP exception handlers in the cmpxchg
loop but we don't have a generic way to do that now.

Note strictfp builder is broken in the minnum/maxnum case

https://reviews.llvm.org/D154993
2023-07-11 18:51:15 -04:00
Teresa Johnson
546ec641b4 Restore "[MemProf] Use new option/pass for profile feedback and matching"
This restores commit b4a82b62258c5f650a1cccf5b179933e6bae4867, reverted
in 3ab7ef28eebf9019eb3d3c4efd7ebfd160106bb1 because it was thought to
cause a bot failure, which ended up being unrelated to this patch set.

Differential Revision: https://reviews.llvm.org/D154856
2023-07-11 13:16:20 -07:00