aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Analysis/ValueTrackingTest.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-10[IR] Handle fabs LHS in `fcmpImpliesClass` (#152913)Yingwei Zheng1-0/+36
Closes https://github.com/llvm/llvm-project/issues/152824.
2025-07-19[InstSimplify] Add poison propagation for trivially vectorizable intrinsics ↵Jasmine Tang1-14/+14
(#149243) Fixes https://github.com/llvm/llvm-project/issues/146769 Test cases added to `llvm/test/Transforms/InstSimplify/fold-intrinsics.ll`
2025-07-16[InstSimplify] Fold trig functions call of poison to poison (#148969)jjasmine1-2/+2
Fold trig functions call of poison to poison. This includes sin, cos, asin, acos, atan, atan2, sinh, cosh, sincos, sincospi. Test cases are fixed and also added to llvm/test/Transforms/InstSimplify/fold-intrinsics.ll just like in https://github.com/llvm/llvm-project/pull/146750
2025-07-04[InstCombine] Propagate poison pow[i], [us]add, [us]sub and [us]mul (#146750)jjasmine1-2/+2
Fixes #146560 as well as propagate poison for [us]add, [us]sub and [us]mul
2025-07-04[ConstantFolding] Consolidate poison propagation for intrinsics (#146878)Nikita Popov1-1/+1
This consolidates the "fold poison arg to poison result" constant folding logic for intrinsics, based on a common intrinsicPropagatesPoison() helper, which is also used for poison propagation reasoning in ValueTracking. This ensures that the set of supported intrinsics is consistent. This add ucmp, scmp, smul.fix, smul.fix.sat, canonicalize and sqrt to the intrinsicPropagatesPoison list, as these were handled by ConstantFolding but not ValueTracking. The ctpop test is an example of the converse, where it was handled by ValueTracking but not ConstantFolding.
2025-06-28[ValueTracking] Forward-declare class instead of including header (NFC)Antonio Frighetto1-0/+1
The header inclusion was previously causing a build time regression.
2025-06-27[ValueTracking] Add `matchSimpleBinaryIntrinsicRecurrence` helperAntonio Frighetto1-0/+52
Similarly to what it is being done to match simple recurrence cycle relations, attempt to match value-accumulating recurrences of kind: ``` %umax.acc = phi i8 [ %umax, %backedge ], [ %a, %entry ] %umax = call i8 @llvm.umax.i8(i8 %umax.acc, i8 %b) ``` Preliminary work to let InstCombine avoid folding such recurrences, so that simple loop-invariant computation may get hoisted. Minor opportunity to refactor out code as well.
2025-06-09[ValueTracking] Update `Ordered` when both operands are non-NaN. (#143349)Yingwei Zheng1-0/+9
When the original predicate is ordered and both operands are non-NaN, `Ordered` should be set to true. This variable still matters even if both operands are non-NaN because FMF only applies to select, not fcmp. Closes https://github.com/llvm/llvm-project/issues/143123.
2025-06-03[ValueTracking] Make Depth last default arg (NFC) (#142384)Ramkumar Ramachandra1-47/+44
Having a finite Depth (or recursion limit) for computeKnownBits is very limiting, but is currently a load-bearing necessity, as all KnownBits are recomputed on each call and there is no caching. As a prerequisite for an effort to remove the recursion limit altogether, either using a clever caching technique, or writing a easily-invalidable KnownBits analysis, make the Depth argument in APIs in ValueTracking uniformly the last argument with a default value. This would aid in removing the argument when the time comes, as many callers that currently pass 0 explicitly are now updated to omit the argument altogether.
2025-06-02[ValueTracking] Do not use FMF from fcmp (#142266)Yingwei Zheng1-6/+5
This patch introduces an FMF parameter for `matchDecomposedSelectPattern` to pass FMF flags from select, instead of fcmp. Closes https://github.com/llvm/llvm-project/issues/137998. Closes https://github.com/llvm/llvm-project/issues/141017.
2025-05-22Reland [llvm] add GenericFloatingPointPredicateUtils #140254 (#141065)Tim Gymnich1-0/+1
#140254 was previously missing 2 files in the bazel build config.
2025-05-21Revert "[llvm] add GenericFloatingPointPredicateUtils (#140254)" (#140968)Kewen121-1/+0
This reverts commit d00d74bb2564103ae3cb5ac6b6ffecf7e1cc2238. The PR breaks our buildbots and blocks downstream merge.
2025-05-21[llvm] add GenericFloatingPointPredicateUtils (#140254)Tim Gymnich1-0/+1
add `GenericFloatingPointPredicateUtils` in order to generalize effects of floating point comparisons on `KnownFPClass` for both IR and MIR. --------- Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-05-07ValueTracking: Handle minimumnum and maximumnum in computeKnownFPClass (#138737)Matt Arsenault1-0/+56
For now use the same treatment as minnum/maxnum, but these should diverge. alive2 seems happy with this, except for some preexisting bugs with weird denormal modes.
2025-03-28[Analysis][NFC] Extract KnownFPClass (#133457)Tim Gymnich1-0/+1
- extract KnownFPClass for future use inside of GISelKnownBits --------- Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-02-04[ValueTracking] Fix bit width handling in computeKnownBits() for GEPs (#125532)Nikita Popov1-6/+6
For GEPs, we have three bit widths involved: The pointer bit width, the index bit width, and the bit width of the GEP operands. The correct behavior here is: * We need to sextOrTrunc the GEP operand to the index width *before* multiplying by the scale. * If the index width and pointer width differ, GEP only ever modifies the low bits. Adds should not overflow into the high bits. I'm testing this via unit tests because it's a bit tricky to test in IR with InstCombine canonicalization getting in the way.
2025-02-03[ValueTracking] Add additional tests for computeKnownBits on GEPs (NFC)Nikita Popov1-0/+35
These demonstrate miscompiles in the existing code.
2025-01-16[ValueTracking] Return `poison` for zero-sized types (#122647)Pedro Lobo1-4/+4
Return `poison` for zero-sized types in `isBitwiseValue`.
2024-10-11[NFC] Rename `Intrinsic::getDeclaration` to `getOrInsertDeclaration` (#111752)Rahul Joshi1-2/+2
Rename the function to reflect its correct behavior and to be consistent with `Module::getOrInsertFunction`. This is also in preparation of adding a new `Intrinsic::getDeclaration` that will have behavior similar to `Module::getFunction` (i.e, just lookup, no creation).
2024-09-13[llvm][unittests] Strip unneeded use of raw_string_ostream::str() (NFC)JOE19941-2/+2
Avoid excess layer of indirection.
2024-08-10[UnitTests] Convert a test to use opaque pointers (#102668)Sergei Barannikov1-15/+11
2024-05-20[ValueTracking] Fix incorrect inferrence about the signbit of sqrt (#92510)Yingwei Zheng1-1/+1
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-04-16[ValueTracking] Restore isKnownNonZero parameter order. (#88873)Harald van Dijk1-8/+5
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-15ValueTracking: Treat poison more aggressively in computeKnownFPClass (#87990)Matt Arsenault1-0/+55
Assume no valid values, and the sign bit is 0.
2024-04-12[ValueTracking] Convert `isKnownNonZero` to use SimplifyQuery (#85863)Yingwei Zheng1-5/+10
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-08ValueTracking: Handle ConstantAggregateZero in computeKnownFPClassMatt Arsenault1-0/+21
2024-03-07[ValueTracking] Fix KnownBits conflict for calls (range vs returned) (#84353)Björn Pettersson1-0/+14
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-02-23[ValueTracking] Handle more integer intrinsics in `propagatesPoison` (#82749)Yingwei Zheng1-36/+23
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-01-23ValueTracking: Recognize fcmp ole/ugt with inf as a class test (#79095)Matt Arsenault1-4/+4
These were missed and hopefully avoids assertions when dc3faf0ed0e3f1ea9e435a006167d9649f865da1 is recommitted.
2023-12-21[ValueTracking] Shufflevector produces poison rather than undefNikita Popov1-4/+4
Shufflevector semantics have changed so that poison mask elements return poison rather than undef. Reflect this in the canCreateUndefOrPoison() implementation.
2023-12-05[InstCombine] Check isGuaranteedNotToBeUndef in ↵Craig Topper1-3/+3
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-11-14ValueTracking: Handle compare gt to -inf in class identification (#72086)Matt Arsenault1-4/+69
This apparently shows up somewhere in chromium. We also are missing a canonicalization to an equality compare with inf.
2023-10-05ValueTracking: Use fcAllFlags for unknown value (#66393)Matt Arsenault1-4/+4
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-07-05[ValueTracking] Don't handle ptrtoint with mismatches sizesNikita Popov1-6/+4
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-06-28ValueTracking: Handle !absolute_symbol in computeKnownBitsMatt Arsenault1-0/+88
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-20ValueTracking: Ignore -0 for nsz sqrt with UseInstrInfo in computeKnownFPClassMatt Arsenault1-0/+74
This avoids a regression when SignBitMustBeZero is moved to computeKnownFPClass.
2023-06-19ValueTracking: Handle compare to nan and -inf constants in fcmpToClassTestMatt Arsenault1-0/+99
This will help enable a cleanup of simplifyFCmpInst
2023-05-23[KnownBits] Return zero instead of unknown for always poison shiftsNikita Popov1-1/+1
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-18Reapply "ValueTracking: Handle phi in computeKnownFPClass"Matt Arsenault1-0/+108
This reverts commit e13f88d1ff5234946af6349a9a7cf56fcb6c040e. Fix off by one recursion limit check.
2023-05-18Revert "ValueTracking: Handle phi in computeKnownFPClass"Matt Arsenault1-108/+0
This reverts commit cac9e427eb1ff3dabda8ac08968b998c3bc5ab47. Causing crashes in lencod
2023-05-18ValueTracking: Handle phi in computeKnownFPClassMatt Arsenault1-0/+108
Doesn't try the all the tricks computeKnownBits does.
2023-05-16ValueTracking: Implement computeKnownFPClass for sqrtMatt Arsenault1-2/+2
Could be slightly smarter in cases that are probably uninteresting.
2023-04-28Handle `select` in programUndefinedIfPoison.Justin Lebar1-0/+14
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-26ValueTracking: Fix computeKnownFPClass handling for copysignMatt Arsenault1-3/+3
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-24ValueTracking: Add ordered negative handling for fmul to computeKnownFPClassMatt Arsenault1-12/+12
Port from the existing handling in cannotBeOrderedLessThanZero
2023-04-24ValueTracking: Fix computeKnownFPClass for fabsMatt Arsenault1-5/+5
The fabs utility functions have the opposite purpose and probably should not be a general utility.
2023-04-19ValueTracking: uitofp/sitofp cannot return denormal resultsMatt Arsenault1-5/+5
2023-04-19ValueTracking: sitofp cannot return -0Matt Arsenault1-3/+3
2023-04-13ValueTracking: Add cannotBeOrderedLessThanZero to KnownFPClassMatt Arsenault1-0/+53
Eventually we should be able to replace the existing CannotBeOrderedLessThanZero.
2023-04-13ValueTracking: Address todo for nan fmul handling in computeKnownFPClassMatt Arsenault1-1/+25
If both operands can't be zero or nan, the result can't be nan.