1493 Commits

Author SHA1 Message Date
Kazu Hirata
188ec33726 [llvm] Use llvm::bit_width (NFC) 2023-01-21 14:48:32 -08:00
Kazu Hirata
5638156a1c [llvm] Use llvm::bit_width (NFC) 2023-01-21 13:56:47 -08:00
Nikita Popov
bf23b4031e [ValueTracking] Take poison-generating metadata into account (PR59888)
In canCreateUndefOrPoison(), take not only poison-generating flags,
but also poison-generating metadata into account. The helpers are
written generically, but I believe the only case that can actually
matter is !range on calls -- !nonnull and !align are only valid on
loads, and those can create undef/poison anyway.

Unfortunately, this negatively impacts logical to bitwise and/or
conversion: For ctpop/ctlz/cttz we always attach !range metadata,
which will now block the transform, because it might introduce
poison. It would be possible to recover this regression by supporting
a ConsiderFlagsAndMetadata=false mode in impliesPoison() and clearing
flags/metadata on visited instructions.

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

Differential Revision: https://reviews.llvm.org/D142115
2023-01-20 12:18:32 +01:00
Matt Arsenault
c663b8c429 ValueTracking: Teach CannotBeOrderedLessThanZero about rounding intrinsics
These should obviously preserve the sign although the variety of these
always confuses me.
2023-01-15 09:44:45 -05:00
Guillaume Chatelet
8fd5558b29 [NFC] Use TypeSize::geFixedValue() instead of TypeSize::getFixedSize()
This change is one of a series to implement the discussion from
https://reviews.llvm.org/D141134.
2023-01-11 16:49:38 +00:00
Guillaume Chatelet
48f5d77eee [NFC] Use TypeSize::getKnownMinValue() instead of TypeSize::getKnownMinSize()
This change is one of a series to implement the discussion from
https://reviews.llvm.org/D141134.
2023-01-11 16:36:39 +00:00
Noah Goldstein
cc845e9de8 [InstCombine] Handle assume(X & Pow2 != 0) in computeKnownBits()
If we know that X & Pow2 != 0, then the bit at that position is
known one.

Differential Revision: https://reviews.llvm.org/D140851
2023-01-11 10:21:15 +01:00
serge-sans-paille
38818b60c5
Move from llvm::makeArrayRef to ArrayRef deduction guides - llvm/ part
Use deduction guides instead of helper functions.

The only non-automatic changes have been:

1. ArrayRef(some_uint8_pointer, 0) needs to be changed into ArrayRef(some_uint8_pointer, (size_t)0) to avoid an ambiguous call with ArrayRef((uint8_t*), (uint8_t*))
2. CVSymbol sym(makeArrayRef(symStorage)); needed to be rewritten as CVSymbol sym{ArrayRef(symStorage)}; otherwise the compiler is confused and thinks we have a (bad) function prototype. There was a few similar situation across the codebase.
3. ADL doesn't seem to work the same for deduction-guides and functions, so at some point the llvm namespace must be explicitly stated.
4. The "reference mode" of makeArrayRef(ArrayRef<T> &) that acts as no-op is not supported (a constructor cannot achieve that).

Per reviewers' comment, some useless makeArrayRef have been removed in the process.

This is a follow-up to https://reviews.llvm.org/D140896 that introduced
the deduction guides.

Differential Revision: https://reviews.llvm.org/D140955
2023-01-05 14:11:08 +01:00
Owen Anderson
ec40c8f6fe [ValueTracking] Improve ComputeNumSignBits to handle Trunc
Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D140796
2023-01-03 15:26:21 -07:00
Nikita Popov
3f04553e5c [ValueTracking] Use SmallVector for non-undef/poison ops
The way these APIs are used, there isn't really a benefit to
deduplicating the ops as part of the API. The only place that
benefits from this is PoisonChecking, and for that particular
use the assertion emission was potentially non-deterministic.
We should populate a vector for deterministic order and then
deduplicate via a separate set.
2023-01-02 14:40:15 +01:00
Nikita Popov
e44b11d9b6 [ValueTracking] Treat branch on undef as UB as well
We were already treating branch on poison as UB, but branch on
undef is also UB. Move the checks into the correct function.

From LangRef for br:

> If ‘cond’ is poison or undef, this instruction has undefined behavior.

From LangRef for switch:

> If ‘value’ is poison or undef, this instruction has undefined behavior.

There is a minor regression in dont-distribute-phi.ll, apparently
we handle that pattern in logical but not bitwise form.
2023-01-02 12:34:23 +01:00
Nikita Popov
86195b8361 [ValueTracking] Remove branch-on-poison-as-ub flag (NFC)
This has been enabled by default without issue for a while now,
remove the flag.
2023-01-02 11:05:01 +01:00
Matt Arsenault
7e720b010a ValueTracking: Fix canCreateUndefOrPoison for saturating shifts
These need to consider the shift amount.
2022-12-30 11:28:28 -05:00
Matt Arsenault
de8e0a4397 ValueTracking: Teach canCreateUndefOrPoison about saturating intrinsics 2022-12-23 09:42:33 -05:00
Matt Arsenault
876f3d6c91 ValueTracking: Add test for isKnownNeverInfinity for fptrunc 2022-12-22 09:38:14 -05:00
Matt Arsenault
2c52c811ee ValueTracking: Document some difficult isKnownNeverInfinity cases
Add a comment and some negative tests. I'd like to have test coverage
and explicit handling of all the math operations for clarity.
2022-12-20 13:22:22 -05:00
Matt Arsenault
2bf17cc048 ValueTracking: Teach isKnownNeverInfinity about llvm.sin/llvm.cos 2022-12-20 13:17:03 -05:00
Matt Arsenault
9a21475651 ValueTracking: Teach isKnownNeverInfinity about sqrt 2022-12-20 13:03:07 -05:00
Matt Arsenault
41dd02e857 ValueTracking: Teach isKnownNeverInfinity about min/max functions 2022-12-20 12:52:59 -05:00
Matt Arsenault
4e37d00b9d ValueTracking: Teach isKnownNeverInfinity about rounding intrinsics 2022-12-20 12:45:07 -05: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
Kazu Hirata
6eb0b0a045 Don't include Optional.h
These files no longer use llvm::Optional.
2022-12-14 21:16:22 -08:00
Fangrui Song
d4b6fcb32e [Analysis] llvm::Optional => std::optional 2022-12-14 07:32:24 +00:00
Sanjay Patel
6e6fe27689 [ValueTracking] peek through extends in haveNoCommonBitsSet (2nd try)
The 1st try was not clean because a portion of the code diff
made it into the pre-commit patch to add tests. This should
be the same end result without the muddied code diff.

Original commit message:

In cases with matching extends, this allows changing an 'add'
into an 'or' and narrowing the 'or' which then simplifies to
a constant.

In cases with opposite extends, we just convert to an 'or'
currently, but that could be reduced too.

https://alive2.llvm.org/ce/z/fTHzdb
2022-12-13 16:57:45 -05:00
Sanjay Patel
41513bc7a2 Revert "[InstCombine] add tests for add-of-extends; NFC"
This reverts commit c8cba0bc4a8c9f4f3f10e17f601ed924dfb82bef.
An unintended code change snuck into this (was supposed to just add tests).
2022-12-13 16:12:09 -05:00
Sanjay Patel
3ed6143e81 Revert "[ValueTracking] peek through extends in haveNoCommonBitsSet"
This reverts commit 7520d187cf0dedcf5085f71bc1a5472c75cc8dbb.

The pre-commit patch that was supposed to NFC add tests for this
patch picked up some code that should not be here. I'll clean up
and re-commit.
2022-12-13 16:12:09 -05:00
Sanjay Patel
7520d187cf [ValueTracking] peek through extends in haveNoCommonBitsSet
In cases with matching extends, this allows changing an 'add'
into an 'or' and narrowing the 'or' which then simplifies to
a constant.

In cases with opposite extends, we just convert to an 'or'
currently, but that could be reduced too.

https://alive2.llvm.org/ce/z/fTHzdb
2022-12-13 15:53:20 -05:00
Sanjay Patel
c8cba0bc4a [InstCombine] add tests for add-of-extends; NFC 2022-12-13 15:53:20 -05:00
Matt Arsenault
28e3220a5c ValueTracking: Teach canCreateUndefOrPoison about FP ops
Probably could replace the switch by marking the intrinsic definitions
with NoUndef<RetIndex>.
2022-12-12 22:57:44 -05:00
Manuel Brito
45a892d012 Use poison instead of undef where its used as a placeholder [NFC]
Differential Revision: https://reviews.llvm.org/D139789
2022-12-11 17:18:00 +00:00
Kazu Hirata
405fc404bf [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
2022-12-06 20:14:51 -08:00
Matt Arsenault
7f4429c0e4 ValueTracking: Teach CannotBeOrderedLessThanZero about copysign 2022-12-06 09:01:39 -05:00
Matt Arsenault
51af4ddfc2 ValueTracking: Teach canCreateUndefOrPoison about more intrinsics
I tried to test the fallthrough to noundef callsite return attribute
case, but it seems that folds out as-is.
2022-12-05 10:04:13 -05:00
Matt Arsenault
dbca874faa ValueTracking: Teach CannotBeOrderedLessThanZero about trivial ops
Handle canonicalize and arithmetic.fence
2022-12-05 08:39:07 -05:00
Matt Arsenault
db0f258479 ValueTracking: Teach isKnownNeverNaN about arithmetic_fence 2022-12-05 08:39:07 -05:00
Matt Arsenault
dac496fb1f ValueTracking: Teach isKnownNeverInfinity about arithmetic.fence 2022-12-05 08:39:07 -05:00
Kazu Hirata
3c09ed006a [llvm] Use std::nullopt instead of None in comments (NFC)
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
2022-12-04 17:12:44 -08:00
Kazu Hirata
19aff0f37d [Analysis] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

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
2022-12-02 19:43:04 -08:00
Krzysztof Parzyszek
26424c96c0 Attributes: convert Optional to std::optional 2022-12-02 08:15:45 -06:00
Kazu Hirata
5ea708375f [Analysis] Use std::optional in ValueTracking.cpp (NFC)
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
2022-11-25 11:30:34 -08:00
Kazu Hirata
5fef791cb9 [Analysis] Remove getInverseMinMaxPred
The last uses of getInverseMinMaxPred were removed on February 24,
2022 in commit 5423b0a52567b2fba8cbae3afee760f53c3f14d2.
2022-11-20 13:30:19 -08:00
Matt Arsenault
af7e80b7cb ValueTracking: Look through copysign in isKnownNeverInfinity 2022-11-17 08:52:09 -08:00
Matt Arsenault
29e4363dda ValueTracking: Look through fneg in isKnownNeverNaN 2022-11-17 08:35:49 -08:00
Matt Arsenault
ba1669c81f ValueTracking: Look through fabs and fneg in isKnownNeverInfinity 2022-11-17 00:06:15 -08:00
Matt Arsenault
d24fe812ec ValueTracking: Look through canonicalize in isKnownNeverInfinity 2022-11-17 00:06:15 -08:00
Philip Reames
9472a810ed Address post commit review feedback from D137046
It was pointed out the verifier rejects inttoptr and ptrtoint casts with inputs and outputs whose scalability doesn't match.  As such, checking the input type separately from the type of the cast itself is redundant.
2022-11-01 13:36:13 -07:00
Philip Reames
2e999b7dd1 Allow scalable vectors in ComputeNumSignBits and isKnownNonNull
This is a follow up to D136470 which extends the same scheme used there to ComputeNumSignBits and isKnownNonNull. As a reminder, for scalable vectors we track a single bit which is implicitly broadcast to all lanes. We do not know how many lanes there are statically, and thus have to be conservative along paths which require exact sizes.

Differential Revision: https://reviews.llvm.org/D137046
2022-11-01 09:29:42 -07:00
Philip Reames
93798fb740 Address post commit style comment from 087bb0f 2022-10-31 11:16:14 -07:00
Geza Lore
d5e59e99f4 [ValueTracking] Improve performance of programUndefinedIfUndefOrPoison (NFC)
programUndefinedIfUndefOrPoison used to eagerly propagate the fact that
a value is poison to the users of the value. The problem is that if the
value has a lot of uses (orders of magnitude more than the scanning
limit we use in this function), then we spend the bulk of our time in
eagerly propagating the poison property, which we will mostly never use
later anyway due to the scanning limit.

I have a test case (of ~50k lines of machine generated C++), where this
results in ~60% of 35s compilation time being spent doing just this
eager propagation.

This patch changes programUndefinedIfUndefOrPoison to only propagate to
instructions actually visited, looking back to see if their operands are
poison. This should be equivalent and no functional change is intended,
but we regain virtually all of the 60% compilation time spent in this
function in my test case (i.e.: a 2.5x total compilation speedup).

Differential Revision: https://reviews.llvm.org/D137027
2022-10-31 10:20:11 +01:00
Philip Reames
35a1161c24 [ValueTracking] Assert known bits sanity in isKnownNonZero
These are the same asserts we have in other query routines; cover this interface too.
2022-10-30 10:53:52 -07:00