3800 Commits

Author SHA1 Message Date
Joshua Cao
e19d9eea6e [SCEV] Add automated test checks for some tests 2023-02-18 23:58:23 -08:00
Noah Goldstein
3bd38f6639 [ValueTracking] Add cases for additional ops in isKnownNonZero
Add cases for the following ops:
    - 0-X            -- https://alive2.llvm.org/ce/z/6C75Li
    - bitreverse(X)  -- https://alive2.llvm.org/ce/z/SGG1q9
    - bswap(X)       -- https://alive2.llvm.org/ce/z/p7pzwh
    - ctpop(X)       -- https://alive2.llvm.org/ce/z/c5y3BC
    - abs(X)         -- https://alive2.llvm.org/ce/z/yxXGz_
                        https://alive2.llvm.org/ce/z/rSRg4K
    - uadd_sat(X, Y) -- https://alive2.llvm.org/ce/z/Zw-y4W
                        https://alive2.llvm.org/ce/z/2NRqRz
                        https://alive2.llvm.org/ce/z/M1OpF8

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D142828
2023-02-18 13:45:15 -06:00
Noah Goldstein
e0ce87509b [ValueTracking] Add tests for additional isKnownNonZero cases; NFC
Add cases for the following ops:
    - 0-X
    - bitreverse(X)
    - bswap(X)
    - ctpop(X)
    - abs(X)
    - uadd_sat(X, Y)

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D142827
2023-02-18 13:44:55 -06:00
Noah Goldstein
9a8f517f57 [ValueTracking] Add KnownBits patterns xor(x, x - 1) and and(x, -x) for knowing upper bits to be zero
These two BMI pattern will clear the upper bits of result past the
first set bit. So if we know a single bit in `x` is set, we know that
`results[bitwidth - 1, log2(x) + 1] = 0`.

Alive2:
blsmsk: https://alive2.llvm.org/ce/z/a397BS
blsi: https://alive2.llvm.org/ce/z/tsbQhC

Differential Revision: https://reviews.llvm.org/D142271
2023-02-18 13:31:17 -06:00
Noah Goldstein
c8fb2775ce [ValueTracking] Add tests for known bits after common BMI pattern (blsmsk/blsi); NFC
Differential Revision: https://reviews.llvm.org/D142270
2023-02-18 13:31:12 -06:00
Maksim Kazantsev mkazantsev@azul.com
f79a5fb9df [Test][SCEV] Add a test where the trip count can't be calculated
Add a test in which the trip count could have been calculated
correctly thanks to an assume since it is known to divide by the
step of the IV.

Patch by Alon Kom!

Differential Revision: https://reviews.llvm.org/D143644
2023-02-13 08:29:26 +00:00
Dmitry Makogon
c77c186a64 [LVI] Don't traverse uses when calculating range at use
This effectively reverts 5c38c6a and 4f772b0.

A recently introduced LazyValueInfo::getConstantRangeAtUse returns incorrect
ranges for values in certain cases. One such example is described in PR60629.
The issue has something to do with traversing PHI uses of a value transitively.
As nikic pointed out, we're effectively reasoning about values from different
loop iterations.

In the faulting test case, CVP made a miscompilation because the calculated
range for a shift argument was incorrect. It returned empty-set, however it is
clearly not a dead code. CVP then erased the shift instruction because
of empty range.
2023-02-10 17:06:36 +07:00
Dmitry Makogon
0737770c3e [LVI][CVP] Add test for miscompilation by CVP due to incorrect range returned by LVI
This adds a test case from PR60629 which shows a miscompilation by CVP.
2023-02-10 17:06:35 +07:00
Max Kazantsev
faf029d972 [Test][SCEV] Add tests where multiple assumes can be used to improve trip multiple
Add tests combining assume on trip count divisibility (TV % VF) and minimum/maximum
values (TC > N, TC < M).

Patch by Alon Kom!

Differential Revision: https://reviews.llvm.org/D143337
2023-02-10 16:23:23 +07:00
Sjoerd Meijer
079c488c66 [TTI][AArch64] Cost model insertelement and indexed LD1 instructions
An indexed LD1 instruction, or "ASIMD load, 1 element, one lane, B/H/S"
instruction that loads a value and inserts an element into a vector is
an expensive instruction. It has a latency of 8 on modern cores. We
generate an indexed LD1 when an insertelement instruction has a load as an
operand and this patch is recognising and makes indexed LD1 more expensive.

Differential Revision: https://reviews.llvm.org/D141602
2023-02-09 16:28:11 +00:00
luxufan
e50a508b5c [MemorySSA] Add test for gep with loop invariant pointer operand and
indexes are all constant
2023-02-09 20:40:10 +08:00
Yashwant Singh
cde2f330b3 [AMDGPU] Introduce never uniform bit field in tablegen
IsNeverUniform can be set to 1 to mark instructions which are
inherently never-uniform/divergent. Enabling this bit in
Writelane instruction for now. To be extended to all required
instructions.

Reviewed By: arsenm, sameerds, #amdgpu

Differential Revision: https://reviews.llvm.org/D143154
2023-02-08 11:45:48 +05:30
Simon Pilgrim
1e97c73376 [CostModel][X86] Update LV UTC_ARGS regexp filter to match ptr instead of i8* etc. 2023-02-07 17:46:40 +00:00
Max Kazantsev
0c4a735200 [SCEV] Support sext in SCEVLoopGuardRewriter
There is no particular reason why it's not supported, and it is useful.

Differential Revision: https://reviews.llvm.org/D143257
Reviewed By: fhahn
2023-02-07 14:00:30 +07:00
Hassnaa Hamdi
b1c34dec64 Revert "[AArch64][CostModel]: Add costs for zero/sign extend."
This reverts commit d65c3bf39aa49eda0f5a6bff02c9292895a37e26.
2023-02-03 13:45:00 +00:00
Max Kazantsev
91ee22b03b [Test] Add tests with narrow checks for SCEVLoopGuardRewriter 2023-02-03 17:22:16 +07:00
Max Kazantsev
5f99a51745 [Test] Add signed counterparts of unsigned tests on SCEVLoopGuardRewriter 2023-02-03 17:07:15 +07:00
Max Kazantsev
16e0ebbbcf [Test] Add motivating test for umin support in SCEVLoopGuardRewriter
This test is equivalent to another one, where we can infer a
reasonable iteration count. The only difference is that umin and zext
here are swapped, and rewriter fails here.
2023-02-03 17:07:15 +07:00
Hassnaa Hamdi
d65c3bf39a [AArch64][CostModel]: Add costs for zero/sign extend.
Add cost for extending to illegal scalable vector types.
Add testing file for the extend operations.

Reviewed By: sdesmalen

Differential Revision: https://reviews.llvm.org/D142456
2023-02-02 13:37:21 +00:00
Florian Hahn
62bd944e42
[SCEV] Use fact that B >u 0 for A <u B in applyLoopGuards.
If LHS <u RHS holds, RHS should be guaranteed to be > 0. By using
using 'umax(RHS, 1) -1' instead of 'RHS - 1' the results in
applyLoopGuards can be improved in some cases.

Note that the TODO for the tests mentioned the max BTC being 11, but
unless I am missing something 10 should be correct.

https://alive2.llvm.org/ce/z/44nP7F

Reviewed By: mkazantsev

Differential Revision: https://reviews.llvm.org/D126503
2023-02-01 16:51:18 +00:00
Florian Hahn
071479806e
[SCEV] Add test for applyLoopGuards with pointer induction.
Add an additional variant of the test added in 67b712024ca1f3c5.
2023-02-01 13:30:43 +00:00
Florian Hahn
67b712024c
[SCEV] Add test for applyLoopGuards with pointer induction.
Extra test that crashes with earlier versions of D126503.
2023-02-01 12:02:55 +00:00
Matt Arsenault
63178c3635 AMDGPU: Update machine divergence analysis test 2023-01-30 16:18:20 -04:00
Joshua Cao
f9599bbc7a [AssumptionCache] caches @llvm.experimental.guard's
As discussed in https://github.com/llvm/llvm-project/issues/59901

This change is not NFC. There is one SCEV and EarlyCSE test that have an
improved analysis/optimization case. Rest of the tests are not failing.

I've mostly only added cleanup to SCEV since that is where this issue
started. As a follow up, I believe there is more cleanup opportunity in
SCEV and other affected passes.

There could be cases where there are missed registerAssumption of
guards, but this case is not so bad because there will be no
miscompilation. AssumptionCacheTracker should take care of deleted
guards.

Differential Revision: https://reviews.llvm.org/D142330
2023-01-24 20:16:46 -08:00
ShihPo Hung
5fb3a57ea7 [Cost] Add CostKind to getVectorInstrCost and its related users
LoopUnroll estimates the loop size via getInstructionCost(),
but getInstructionCost() cannot pass CostKind to getVectorInstrCost().
And so does getShuffleCost() to getBroadcastShuffleOverhead(),
getPermuteShuffleOverhead(), getExtractSubvectorOverhead(),
and getInsertSubvectorOverhead().

To address this, this patch adds an argument CostKind to these
functions.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D142116
2023-01-21 05:29:24 -08:00
Sjoerd Meijer
3e6afa77b4 [CostModel][AArch64] Precommit tests for LD1 single-element to lane. NFC. 2023-01-19 16:50:31 +00:00
James Y Knight
06210d50c0 ExceptionHandling documentation tweaks.
Delete mention of the llvm.eh.begincatch/llvm.eh.endcatch intrinsics,
and remove them from a few remaining test-cases. These intrinsics were
from a previous attempt at implementing Windows exception-handling,
but were removed from LLVM in 2015.

Also mention that dynamic exception specifications ("throw filters")
were removed from the spec in C++17.
2023-01-16 20:36:09 -05:00
Joshua Cao
2f9f11180f [SCEV] Support all Min/Max SCEVs for GetMinTrailingZeros
There is already support for U/SMax. No reason why Min and SequentialMin
should not be supported.

NFC: code in GetMinTrailingZeroes is copied for a couple node types.
Refactor them into a single code block.

Differential Revision: https://reviews.llvm.org/D141568
2023-01-13 02:31:33 -08:00
Stanislav Mekhanoshin
24b66f6da5 [AMDGPU] Mark wmma intrinsics as source of divergence
I do not believe any code can hit this, but these do not give
a uniform answer with all unifirm sources.

Differential Revision: https://reviews.llvm.org/D141544
2023-01-11 14:16:18 -08:00
Max Kazantsev
d423e17986 [Test] Regenerate checks in fold.ll using auto-update script 2023-01-11 19:22:51 +07:00
Max Kazantsev
3c83bbd35d [Test] Add complementary test for umin_seq 2023-01-11 18:49:09 +07:00
Max Kazantsev
b5fa3574b5 [Test] Add test showing missing canonicalization opportunity in SCEV
We could have same SCEVs for the following expressions:
  zext(umin(x, y)) and umin(zext(x), zext(y));
  zext(umax(x, y)) and umax(zext(x), zext(y))
  sext(smin(x, y)) and smin(zsxt(x), sext(y));
  sext(smax(x, y)) and smax(sext(x), sext(y)).
2023-01-11 18:17:20 +07:00
Johannes Doerfert
1041053469 [CallGraph][FIX] Ensure generic intrinsics are represented in the CG
Intrinsics have historically been excluded from the call graph with an
exception of 3 special ones added at some point. This meant that passes
depending on the call graph needed to handle intrinsics explicitly as
the underlying assumption, namely that intrinsics can't call or modify
things, doesn't hold. We are slowly moving away from special handling of
intrinsics, or at least towards explicitly checking what intrinsics we
want to handle differently.

This patch:
 - Includes most intrinsics in the call graph. Debug intrinsics are
   still excluded.
 - Removes the special handling of intrinsics in the GlobalsAA pass.
 - Removes the `IntrinsicInst::isLeaf` method.

Properly
Fixes: https://github.com/llvm/llvm-project/issues/52706

See also:
https://discourse.llvm.org/t/intrinsics-are-not-special-stop-pretending-i-mean-it/67545

Differential Revision: https://reviews.llvm.org/D14119
2023-01-10 11:38:58 -08:00
Sjoerd Meijer
551a3d8777 [CostModel][AArch64] Add insert/extract element tests for neoverse cores. NFC. 2023-01-10 11:26:53 +00:00
Joshua Cao
8d92a8226e [SCEV] Add llvm.experimental.guard conditions to applyLoopGuards()
Conditions for dominating branches and llvm.assumes are already
collected. This also adds conditions from guards.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D141243
2023-01-09 19:35:16 -08:00
liqinweng
1f8746cc80 [RISCV][CostModel] Add half type support for the cost model of sqrt/fabs
1. Refactor for costs of sqrt/fabs
2. Add half type support for the cost model of sqrt/fabs

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D132908
2023-01-09 12:57:03 +08:00
liqinweng
f3408739da [RISCV][CostModel] Add cost model for integer abs
Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D132999
2023-01-09 11:38:24 +08:00
Alexey Bataev
9b5f62685a [SLP]Fix cost of the broadcast buildvector/gather.
Need to include the cost of the initial insertelement to the cost of the
broadcasts. Also, need to adjust the cost of the gather/buildvector if
the element is inserted into poison/undef vector.

Differential Revision: https://reviews.llvm.org/D140498
2023-01-06 09:25:05 -08:00
Matt Arsenault
53075f8f4e Verifier: Move test from test/Analysis to test/Verifier
This test was purely checking the verifier error, and had no reason
to be running instcombine.
2023-01-05 10:26:02 -05:00
Yeting Kuo
1e9e1b9cf8 [VP][RISCV] Add vp.ctlz/cttz and RISC-V support.
The patch also adds expandVPCTLZ and expandVPCTTZ to expand vp.ctlz/cttz nodes
and the cost model of vp.ctlz/cttz.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D140370
2023-01-04 15:15:01 +08:00
Florian Hahn
a564048899
[SCEV] Properly clean up duplicated FoldCacheUser ID entries.
The current code did not properly handled duplicated FoldCacheUser ID
entries when overwriting an existing entry in the FoldCache.

This triggered verification failures reported by @uabelho and #59721.

The patch fixes that by removing stale IDs when overwriting an existing
entry in the cache.

Fixes #59721.
2022-12-28 00:09:52 +00:00
Florian Hahn
71ed89041f
[IVUsers] Precommit test for zext SCEV invalidation issue.
Test case for issue reported by @uabelho and #59721
2022-12-27 23:24:21 +00:00
Sameer Sahasrabuddhe
e4377cdde6 [UniformityAnalysis][NFC] Make checks independent of order using CHECK-DAG.
This fixes the buildbot failure on reverse iteration:
https://lab.llvm.org/buildbot/#/builders/54/builds/3034
2022-12-20 11:35:45 +05:30
Sameer Sahasrabuddhe
475ce4c200 RFC: Uniformity Analysis for Irreducible Control Flow
Uniformity analysis is a generalization of divergence analysis to
include irreducible control flow:

  1. The proposed spec presents a notion of "maximal convergence" that
     captures the existing convention of converging threads at the
     headers of natual loops.

  2. Maximal convergence is then extended to irreducible cycles. The
     identity of irreducible cycles is determined by the choices made
     in a depth-first traversal of the control flow graph. Uniformity
     analysis uses criteria that depend only on closed paths and not
     cycles, to determine maximal convergence. This makes it a
     conservative analysis that is independent of the effect of DFS on
     CycleInfo.

  3. The analysis is implemented as a template that can be
     instantiated for both LLVM IR and Machine IR.

Validation:
  - passes existing tests for divergence analysis
  - passes new tests with irreducible control flow
  - passes equivalent tests in MIR and GMIR

Based on concepts originally outlined by
Nicolai Haehnle <nicolai.haehnle@amd.com>

With contributions from Ruiling Song <ruiling.song@amd.com> and
Jay Foad <jay.foad@amd.com>.

Support for GMIR and lit tests for GMIR/MIR added by
Yashwant Singh <yashwant.singh@amd.com>.

Differential Revision: https://reviews.llvm.org/D130746
2022-12-20 07:22:24 +05:30
Nikita Popov
12aef5df0c [LAA] Convert test to opaque pointers (NFC)
When converting this test to opaque pointers (and dropping bitcast),
we get improved memory checks. Per fhahn:

> It looks like the difference is due to the logic that determines
> pointer strides in LAA not handling bitcasts. Without the
> bitcasts, the logic now triggers successfully.

Differential Revision: https://reviews.llvm.org/D140204
2022-12-19 16:58:33 +01:00
Florian Hahn
8a3efcd40b
[ValueTracking] Consider single poison operands in propgatesPoison.
This patch updates propgatesPoison to take a Use as argument and
propagatesPoison now returns true if the passed in operand causes the
user to yield poison if the operand is poison

This allows propagating poison if the condition of a select is poison.
This helps improve results for programUndefinedIfUndefOrPoison.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D111643
2022-12-19 11:47:51 +00:00
Matt Arsenault
bf67186bd2 Function: Respect IgnoreLLVMUsed with addrspacecasted functions
Try to respect IgnoreLLVMUsed if the function was addrspacecasted to
match llvm.used's type.
2022-12-16 14:24:03 -05:00
David Goldblatt
61042d2806 [AA][Intrinsics] Add separate_storage assumptions.
This operand bundle on an assume informs alias analysis that the
arguments point to regions of memory that were allocated separately
(i.e. different heap allocations, different allocas, or different
globals).

As a safety measure, we leave the analysis flag-disabled by default.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D136514
2022-12-16 11:05:00 -08:00
Sjoerd Meijer
5c94faba0b [TTI] [AArch64] getMemoryOpCost for ptr types
Opaque ptr types have a size in bits of 0. The legalised type is an i64 or
vector of i64s, which do have a size. Because of this difference in size, target
hook getMemoryOpCost modelled stores of ptr types as extending/truncating
load/stores. Now we just check for opaque ptr types and return the legalised
cost. This makes stores of pointers cheaper, and as a result we now SLP
vectorise the changed test case.

Differential Revision: https://reviews.llvm.org/D140193
2022-12-16 15:38:17 +00:00
Sjoerd Meijer
e909c3d31f [CostModel][AArch64] Precommit opaque ptr store tests. NFC. 2022-12-16 15:34:12 +00:00