124 Commits

Author SHA1 Message Date
JOE1994
52b48a70d3 [llvm][unittests] Strip unneeded use of raw_string_ostream::str() (NFC)
Avoid excess layer of indirection.
2024-09-13 19:01:08 -04:00
Sergei Barannikov
4bffbba7e9
[UnitTests] Convert a test to use opaque pointers (#102668) 2024-08-10 00:54:29 +03:00
Yingwei Zheng
04ae6e600a
[ValueTracking] Fix incorrect inferrence about the signbit of sqrt (#92510)
According to IEEE Std 754-2019, `sqrt` returns nan when the input is
negative (except for -0). In this case, we cannot make assumptions about
sign bit of the result.

Fixes https://github.com/llvm/llvm-project/issues/92217
2024-05-20 21:52:38 +08:00
Harald van Dijk
60de56c743
[ValueTracking] Restore isKnownNonZero parameter order. (#88873)
Prior to #85863, the required parameters of llvm::isKnownNonZero were
Value and DataLayout. After, they are Value, Depth, and SimplifyQuery,
where SimplifyQuery is implicitly constructible from DataLayout. The
change to move Depth before SimplifyQuery needed callers to be updated
unnecessarily, and as commented in #85863, we actually want Depth to be
after SimplifyQuery anyway so that it can be defaulted and the caller
does not need to specify it.
2024-04-16 15:21:09 +01:00
Matt Arsenault
f78b3466ca
ValueTracking: Treat poison more aggressively in computeKnownFPClass (#87990)
Assume no valid values, and the sign bit is 0.
2024-04-15 12:51:29 +02:00
Yingwei Zheng
e0a628715a
[ValueTracking] Convert isKnownNonZero to use SimplifyQuery (#85863)
This patch converts `isKnownNonZero` to use SimplifyQuery. Then we can
use the context information from `DomCondCache`.

Fixes https://github.com/llvm/llvm-project/issues/85823.
Alive2: https://alive2.llvm.org/ce/z/QUvHVj
2024-04-12 23:47:20 +08:00
Matt Arsenault
2bc637b1ce ValueTracking: Handle ConstantAggregateZero in computeKnownFPClass 2024-04-08 09:26:12 -04:00
Björn Pettersson
a41226b055
[ValueTracking] Fix KnownBits conflict for calls (range vs returned) (#84353)
If a function only exits for certain input values we can still derive
that an argument is "returned". We can also derive range metadata that
describe the possible value range returned by the function. However, it
turns out that those two analyses can result in conflicting information.

Example:
  declare i16 @foo(i16 returned)
  ...
  %A = call i16 @foo(i16 4095), !range !{i16 32, i16 33}

To avoid "Bits known to be one AND zero?" assertion failures we know
make sure to discard the known bits for this kind of scenario.
2024-03-07 21:32:49 +01:00
Yingwei Zheng
3b70387c54
[ValueTracking] Handle more integer intrinsics in propagatesPoison (#82749)
This patch extends `propagatesPoison` to handle more integer intrinsics.
It will turn more logical ands/ors into bitwise ands/ors.

See also https://reviews.llvm.org/D99671.
2024-02-23 20:57:56 +08:00
Matt Arsenault
55f12299d8
ValueTracking: Recognize fcmp ole/ugt with inf as a class test (#79095)
These were missed and hopefully avoids assertions when
dc3faf0ed0e3f1ea9e435a006167d9649f865da1 is recommitted.
2024-01-23 20:20:40 +07:00
Nikita Popov
e414ba33b4 [ValueTracking] Shufflevector produces poison rather than undef
Shufflevector semantics have changed so that poison mask elements
return poison rather than undef. Reflect this in the
canCreateUndefOrPoison() implementation.
2023-12-21 15:21:23 +01:00
Craig Topper
5c3496ff33
[InstCombine] Check isGuaranteedNotToBeUndef in haveNoCommonBitsSetSpecialCases. (#74390)
It's not safe for InstCombine to add disjoint metadata when converting
Add to Or otherwise.

I've added noundef attribute to preserve existing test behavior.
2023-12-05 10:33:44 -08:00
Matt Arsenault
0e1a52f556
ValueTracking: Handle compare gt to -inf in class identification (#72086)
This apparently shows up somewhere in chromium. We also are missing a
canonicalization to an equality compare with inf.
2023-11-14 10:05:38 +09:00
Matt Arsenault
7a46baa465
ValueTracking: Use fcAllFlags for unknown value (#66393)
In the failure case we return null, which callers are checking. We were
also returning an fcNone which was unused. It's more consistent to
return fcAllFlags as any possible value, such that the value is always
directly usable without checking the returned value.
2023-10-05 13:10:28 -07:00
Nikita Popov
8d3856836c [ValueTracking] Don't handle ptrtoint with mismatches sizes
When processing assumes, we also handle assumes on ptrtoint of the
value. In canonical IR, these will have the same size as the value.
However, in non-canonical IR there may be an implicit zext or
trunc, which results in a bit width mismatch. We currently handle
this by adjusting bitwidth everywhere, but this is fragile and I'm
pretty sure that the way we do this is incorrect for some predicates,
because we effectively end up commuting an ext/trunc and an icmp.

Instead, add an m_PtrToIntSameSize() matcher that will only handle
bitwidth preserving cases. For the bitwidth-changing cases, wait
until they have been canonicalized.

The original handling for this was added purely to prevent crashes
in an earlier implementation which failed to account for this
entirely.
2023-07-05 12:18:00 +02:00
Matt Arsenault
19a35041c0 ValueTracking: Handle !absolute_symbol in computeKnownBits
Use a unit test since I don't see any existing uses try to make use of
the high bits of a pointer.

This will also assert if the metadata type doesn't match the pointer
width, but I consider that a defect in the verifier and shouldn't be
handled.

AMDGPU allocates LDS globals by assigning !absolute_symbol with the
final fixed address. Tracking the high bits are 0 may help with
addressing mode matching.
2023-06-28 07:33:27 -04:00
Matt Arsenault
06f942016b ValueTracking: Ignore -0 for nsz sqrt with UseInstrInfo in computeKnownFPClass
This avoids a regression when SignBitMustBeZero is moved to computeKnownFPClass.
2023-06-20 21:30:09 -04:00
Matt Arsenault
cb9b01f910 ValueTracking: Handle compare to nan and -inf constants in fcmpToClassTest
This will help enable a cleanup of simplifyFCmpInst
2023-06-19 11:31:58 -04:00
Nikita Popov
f7d1baa414 [KnownBits] Return zero instead of unknown for always poison shifts
For always poison shifts, any KnownBits return value is valid.
Currently we return unknown, but returning zero is generally more
profitable. We had some code in ValueTracking that tried to do this,
but was actually dead code.

Differential Revision: https://reviews.llvm.org/D150648
2023-05-23 14:41:22 +02:00
Matt Arsenault
5b18d84380 Reapply "ValueTracking: Handle phi in computeKnownFPClass"
This reverts commit e13f88d1ff5234946af6349a9a7cf56fcb6c040e.

Fix off by one recursion limit check.
2023-05-18 12:58:09 +01:00
Matt Arsenault
e13f88d1ff Revert "ValueTracking: Handle phi in computeKnownFPClass"
This reverts commit cac9e427eb1ff3dabda8ac08968b998c3bc5ab47.

Causing crashes in lencod
2023-05-18 09:43:46 +01:00
Matt Arsenault
cac9e427eb ValueTracking: Handle phi in computeKnownFPClass
Doesn't try the all the tricks computeKnownBits does.
2023-05-18 08:04:38 +01:00
Matt Arsenault
fe5786d416 ValueTracking: Implement computeKnownFPClass for sqrt
Could be slightly smarter in cases that are probably uninteresting.
2023-05-16 12:41:43 +01:00
Justin Lebar
6f01cb91d7
Handle select in programUndefinedIfPoison.
If both the true and false operands of a `select` are poison, then the `select`
is poison.

Differential Revision: https://reviews.llvm.org/D149427
2023-04-28 09:09:31 -07:00
Matt Arsenault
0125b8d2ec ValueTracking: Fix computeKnownFPClass handling for copysign
We need to expand the set of possible classes to the opposite
sign for the first operand if we don't know the sign of the second
operand.
2023-04-26 12:49:01 -04:00
Matt Arsenault
f40d186d4a ValueTracking: Add ordered negative handling for fmul to computeKnownFPClass
Port from the existing handling in cannotBeOrderedLessThanZero
2023-04-24 22:31:20 -04:00
Matt Arsenault
b0aa6d76eb ValueTracking: Fix computeKnownFPClass for fabs
The fabs utility functions have the opposite purpose and
probably should not be a general utility.
2023-04-24 14:25:06 -04:00
Matt Arsenault
83adfc91e8 ValueTracking: uitofp/sitofp cannot return denormal results 2023-04-19 20:11:34 -04:00
Matt Arsenault
0d448783c3 ValueTracking: sitofp cannot return -0 2023-04-19 08:18:37 -04:00
Matt Arsenault
fc7c706e3f ValueTracking: Add cannotBeOrderedLessThanZero to KnownFPClass
Eventually we should be able to replace the existing
CannotBeOrderedLessThanZero.
2023-04-13 14:44:34 -04:00
Matt Arsenault
054cac104f ValueTracking: Address todo for nan fmul handling in computeKnownFPClass
If both operands can't be zero or nan, the result can't be nan.
2023-04-13 14:44:34 -04:00
Matt Arsenault
4d044bfb33 ValueTracking: Handle no-nan check for computeKnownFPClass for fmul
Copy the logic from isKnownNeverNaN for fadd/fsub. Leave the
extension to handle the zero case for a future change.
2023-04-13 14:44:34 -04:00
Matt Arsenault
94adb39b85 unittests: Use opaque pointers in a test 2023-04-12 06:48:58 -04:00
Matt Arsenault
6aca400986 ValueTracking: Handle no-nan check for computeKnownFPClass for fadd/fsub
Copy the logic from isKnownNeverNaN for fadd/fsub.
2023-04-12 06:48:58 -04:00
Matt Arsenault
b39deda3e1 ValueTracking: Handle nofpclass in computeKnownFPClass 2023-03-16 23:14:40 -04:00
Matt Arsenault
931d4098a2 ValueTracking: Add start of computeKnownFPClass API
Add a new compute-known-bits like function to compute all
the interesting floating point properties at once.

Eventually this should absorb all the various floating point
queries we already have.
2023-03-16 23:14:40 -04:00
Nikita Popov
bbfb13a5ff [ConstExpr] Remove select constant expression
This removes the select constant expression, as part of
https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179.
Uses of this expressions have already been removed in advance,
so this just removes related infrastructure and updates tests.

Differential Revision: https://reviews.llvm.org/D145382
2023-03-16 10:32:08 +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
Vasileios Porpodas
32b38d248f [NFC] Rename Instruction::insertAt() to Instruction::insertInto(), to be consistent with BasicBlock::insertInto()
Differential Revision: https://reviews.llvm.org/D140085
2022-12-15 12:27:45 -08:00
Vasileios Porpodas
06911ba6ea [NFC] Cleanup: Replaces BB->getInstList().insert() with I->insertAt().
This is part of a series of cleanup patches towards making BasicBlock::getInstList() private.

Differential Revision: https://reviews.llvm.org/D138877
2022-12-12 13:33:05 -08:00
Kazu Hirata
b6a01caa64 [llvm/unittests] 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 22:10:37 -08:00
Sanjay Patel
4e44c22c97 [ValueTracking][InstCombine] restrict FP min/max matching to avoid miscompile
This is a long-standing FIXME with a non-FMF test that exposes
the bug as shown in issue #57357.

It's possible that there's still a way to miscompile by
mis-identifying/mis-folding FP min/max patterns, but
this patch only exposes a couple of seemingly minor
regressions while preventing the broken transform.
2022-08-25 16:52:40 -04:00
Sanjay Patel
a925bef70c [ValueTracking] allow vector types in isImpliedCondition()
The matching of constants assumed integers, but we can handle
splat vector constants seamlessly with m_APInt.
2022-07-24 17:46:48 -04:00
Sanjay Patel
4da47bee48 [ValueTracking] add test for isImpliedCondition with vector types; NFC 2022-07-24 17:07:17 -04:00
Nikita Popov
11950efe06 [ConstExpr] Remove div/rem constant expressions
D128820 stopped creating div/rem constant expressions by default;
this patch removes support for them entirely.

The getUDiv(), getExactUDiv(), getSDiv(), getExactSDiv(), getURem()
and getSRem() on ConstantExpr are removed, and ConstantExpr::get()
now only accepts binary operators for which
ConstantExpr::isSupportedBinOp() returns true. Uses of these methods
may be replaced either by corresponding IRBuilder methods, or
ConstantFoldBinaryOpOperands (if a constant result is required).

On the C API side, LLVMConstUDiv, LLVMConstExactUDiv, LLVMConstSDiv,
LLVMConstExactSDiv, LLVMConstURem and LLVMConstSRem are removed and
corresponding LLVMBuild methods should be used.

Importantly, this also means that constant expressions can no longer
trap! This patch still keeps the canTrap() method to minimize diff --
I plan to drop it in a separate NFC patch.

Differential Revision: https://reviews.llvm.org/D129148
2022-07-06 10:11:34 +02:00
Chuanqi Xu
a2609be0b2 [ValueTracking] Checking haveNoCommonBitsSet for (x & y) and ~(x | y)
This one tries to fix:
https://github.com/llvm/llvm-project/issues/53357.

Simply, this one would check (x & y) and ~(x | y) in
haveNoCommonBitsSet. Since they shouldn't have common bits (we could
traverse the case by enumerating), and we could convert this one to (x &
y) | ~(x | y) . Then the compiler could handle it in
InstCombineAndOrXor.
Further more, since ((x & y) + (~x & ~y)) would be converted to ((x & y)
+ ~(x | y)), this patch would fix it too.

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

Reviewed By: spatel, xbolva00, RKSimon, lebedev.ri

Differential Revision: https://reviews.llvm.org/D118094
2022-02-16 13:42:52 +08:00
Chuanqi Xu
e59d6dc063 [NFC] Precommit for PR53357
Due to there are other required changes in
https://reviews.llvm.org/D118094, precommit these changes to ease
reviewing. Including:
- Remove *_thwart tests.
- Remove test for (x & y) + (~x & ~y)
- Fix incorrect uniitest committeed before
2022-02-14 14:37:12 +08:00
Chuanqi Xu
4ee240b860 [NFC] [ValueTracking] Add unittest for haveNoCommonBitsSet 2022-02-14 14:10:30 +08:00
Sanjay Patel
0edf99950e [Analysis] allow caller to choose signed/unsigned when computing constant range
We should not lose analysis precision if an 'add' has both no-wrap
flags (nsw and nuw) compared to just one or the other.

This patch is modeled on a similar construct that was added with
D59386.

I don't think it is possible to expose a problem with an unsigned
compare because of the way this was coded (nuw is handled first).

InstCombine has an assert that fires with the example from:
https://github.com/llvm/llvm-project/issues/52884
...because it was expecting InstSimplify to handle this kind of
pattern with an smax.

Fixes #52884

Differential Revision: https://reviews.llvm.org/D116322
2021-12-28 09:45:37 -05:00
Sanjay Patel
a56803b8f8 [Analysis] fix cast in ValueTracking to allow constant expression
The test would crash because a non-instruction negate op made it in here.

Fixes #51506
2021-12-20 17:16:47 -05:00