aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-05-17ValueTracking: Handle sign bit for fptrunc in computeKnownFPClassMatt Arsenault1-4/+9
2023-05-17ValueTracking: Implement computeKnownFPClass for various rounding intrinsicsMatt Arsenault1-28/+27
2023-05-17[ValueTracking] Fix i1 abs range (PR62760)Nikita Popov1-5/+6
For i1 operations, we may end up returning an empty range instead of a full one. Make sure to use the getNonEmpty constructor. Fixes https://github.com/llvm/llvm-project/issues/62760.
2023-05-16[ValueTracking] Use `KnownBits::sdiv` for `sdiv` opcode in `computeKnownBits`Noah Goldstein1-0/+7
We now of an implementation of `KnownBits::sdiv` so we can implement this case. Differential Revision: https://reviews.llvm.org/D150096
2023-05-16[ValueTracking] Pass `exact` flag to `KnownBits::udiv` in `computeKnownBits`Noah Goldstein1-1/+2
This information was previously missing but we can use it for determining the low-bits. Differential Revision: https://reviews.llvm.org/D150095
2023-05-16[ValueTracking] deduce `X * Y != 0` if `LowestKnownBit(X) * ↵Noah Goldstein1-1/+7
LowestKnownBit(Y) != 0` For `X * Y`, if there exists a subset of `X` and subset of `Y` s.t `sX * sY != 0`, then `X * Y != 0`. - See first proof: https://alive2.llvm.org/ce/z/28C9CG - NB: This is why the previous Odd case works. In knownbits we could exhaustively hunt for such a subset, but `LSB(X)` and `LSB(Y)` actually works. If `LSB(X) * LSB(Y) != 0`, then `X * Y != 0` - See proof: https://alive2.llvm.org/ce/z/p5wWid In `isKnownNonZero` we can use this as if the `LowestKnownOne(X) * LowestKnownOne(Y) != 0`, then `X * Y != 0`, and we don't need to try and other subsets. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D150425
2023-05-16ValueTracking: Expand signature of isKnownNeverInfinity/NaNMatt Arsenault1-66/+75
This is in preparation for replacing the implementation with a wrapper around computeKnownFPClass.
2023-05-16ValueTracking: Restore ordered negative handling for fremMatt Arsenault1-0/+6
In D148674, the negative condition was weakened to only checking isKnownNever(fcNegative), instead of cannotBeOrderedLessThanZero(). This avoids a regression when CannotBeOrderedLessThanZero is replaced with computeKnownFPClass.
2023-05-16ValueTracking: fadd/fsub +0 cannot return -0Matt Arsenault1-2/+53
Copied from CannotBeNegativeZero and extended to cover fsub.
2023-05-16ValueTracking: Implement computeKnownFPClass for sqrtMatt Arsenault1-0/+46
Could be slightly smarter in cases that are probably uninteresting.
2023-05-16[KnownBits] Define and use intersectWith and unionWithJay Foad1-12/+9
Define intersectWith and unionWith as two complementary ways of combining KnownBits. The names are chosen for consistency with ConstantRange. Deprecate commonBits as a synonym for intersectWith. Differential Revision: https://reviews.llvm.org/D150443
2023-05-16[KnownBits] Make use of KnownBits.isUnknown. NFC.Jay Foad1-1/+1
2023-05-15[ValueTracking] Fix computeKnownFPClass with canonicalizePiotr Sobczak1-1/+2
Update code that assumes llvm.canonicalize only handles scalars, by adding a call to getScalarType(). This is fine, as the intrinsic is trivially vectorizable. Introduced in D147870, and uncovered by D148065. Differential Revision: https://reviews.llvm.org/D150556
2023-05-10Revert "Revert "[ValutTracking] Use isGuaranteedNotToBePoison in impliesPoison""luxufan1-1/+1
This reverts commit 706e8110573c83f140a63b40803d6370c86c1414.
2023-05-09Re-revert "[ValueTracking] Use knownbits interface for determining if ↵Noah Goldstein1-23/+20
`div`/`rem` are safe to speculate" Seems to be causing a bug in CorrelatedValuePropegation. Reverting while the issue is investigated. This reverts commit 6c667abf3294d61e4fbe1238e1755c79f7547f1b.
2023-05-09Revert "[ValutTracking] Use isGuaranteedNotToBePoison in impliesPoison"Hans Wennborg1-1/+1
This broke two lit tests: LLVM :: Transforms/LoopSimplify/merge-exits.ll LLVM :: Transforms/PhaseOrdering/X86/vector-reductions.ll see comment on the code review. > Differential Revision: https://reviews.llvm.org/D149934 This reverts commit 2ba4cfd56769ab50c9c6f432f93265d7793bd1f2.
2023-05-09[ValutTracking] Use isGuaranteedNotToBePoison in impliesPoisonluxufan1-1/+1
Differential Revision: https://reviews.llvm.org/D149934
2023-05-05[Analysis] Fix a warningKazu Hirata1-0/+2
This patch fixes: llvm/lib/Analysis/ValueTracking.cpp:895:12: error: unused variable 'BitWidth' [-Werror,-Wunused-variable]
2023-05-05[ValueTracking][NFC] Factor out computeKnownBitsFromCmpMax Kazantsev1-239/+246
Separate the part which is specific for assume intrinsic from the part which only requires an icmp, so that the latter could be reused for other purposes (e.g. in dominating conditions). Differential Revision: https://reviews.llvm.org/D149940 Reviewed By: nikic
2023-05-05[NFC][ValueTracking] Hoist isValidAssumeForContext out of switchMax Kazantsev1-32/+21
There is a lot of copy-paste-ish checks while this can be done once. Differential Revision: https://reviews.llvm.org/D149939 Reviewed By: nikic
2023-05-04[ValueTracking] add UGT/UGE and SGT/SGE in `isImpliedCondOperands`Siyuan Zhu1-0/+14
Partially `fix` https://github.com/llvm/llvm-project/issues/62441. Extend isImpliedCondOperands() to handle ugt/uge and sgt/sge predicates. alive2 proof: https://alive2.llvm.org/ce/z/jLFDAv and https://alive2.llvm.org/ce/z/Z8idUd Differential Revision: https://reviews.llvm.org/D149510
2023-05-02ValueTracking: Sign handling for minnum/maxnumMatt Arsenault1-8/+40
If we know one operand is positive for maxnum, or one is negative for minnum, the result will have the same sign.
2023-05-02ValueTracking: Handle minimum/maximum in computeKnownFPClassMatt Arsenault1-2/+4
2023-05-02ValueTracking: Implement computeKnownFPClass for minnum/maxnumMatt Arsenault1-0/+34
2023-05-01Recommit "[ValueTracking] Use knownbits interface for determining if ↵Noah Goldstein1-20/+23
`div`/`rem` are safe to speculate" (2nd Try) Add `poison` checks that where missing. Reviewed By: nikic
2023-05-01Revert "[ValueTracking] Use knownbits interface for determining if ↵Noah Goldstein1-13/+14
`div`/`rem` are safe to speculate" Appears to be causing out-of-tree test failures. Reverting while the issue is investigated. This reverts commit fbc7fcf5ae26fad7db3e7c861fc6447e02b39cf0.
2023-04-30[ValueTracking] Use knownbits interface for determining if `div`/`rem` are ↵Noah Goldstein1-14/+13
safe to speculate This just replaces the exact constant requirements with known-bits which can prove better results. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149423
2023-04-30[ValueTracking] Slight refactor to avoid unnecessary work; NFCNoah Goldstein1-11/+7
Two changes: 1) Make some cases that conditionally returned unconditional. 2) In cases of `Op0 != 0 || Op1 != 0` its better check `Op1` first as its more likely to be a constant due to canonicalization (so faster to get knownbits of). Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149419
2023-04-30[ValueTracking] Add additional cases for `isKnownNonZero(mul X, Y)`Noah Goldstein1-5/+18
If either `X` or `Y` is odd and the other is non-zero, the result is non-zero. Alive2 Link: https://alive2.llvm.org/ce/z/9V7-es Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149418
2023-04-30[ValueTracking] Add logic for `isKnownNonZero(smin/smax X, Y)`Noah Goldstein1-0/+20
For `smin` if either `X` or `Y` is negative, the result is non-zero. For `smax` if either `X` or `Y` is strictly positive, the result is non-zero. For both if `X != 0` and `Y != 0` the result is non-zero. Alive2 Link: https://alive2.llvm.org/ce/z/7yvbgN https://alive2.llvm.org/ce/z/zizbvq Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149417
2023-04-30[ValueTracking] Add logic for `isKnownNonZero(umin X, Y)`Noah Goldstein1-0/+3
`(umin X, Y) != 0` -> `X != 0 && Y != 0` Alive2 Link: https://alive2.llvm.org/ce/z/AQh67i Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149416
2023-04-30[ValueTracking] Add logic for `isKnownNonZero(umax X, Y)`Noah Goldstein1-0/+1
`(umax X, Y) != 0` -> `X != 0 || Y != 0` Alive2 Link: https://alive2.llvm.org/ce/z/_Z9AUT Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149415
2023-04-30[ValueTracking] Add logic for `isKnownNonZero(sadd.sat X, Y)`Noah Goldstein1-0/+4
The logic here is the same for `add` so reuse the existing helper `isNonZeroAdd` Alive2 Link: https://alive2.llvm.org/ce/z/mhKvC5 Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149414
2023-04-30[ValueTracking] Add logic for `isKnownNonZero(ssub.sat X, Y)`Noah Goldstein1-0/+3
The logic here is the same for normal `(sub X, Y)`, so just reused `isNonZeroSub`. Alive2 Link: https://alive2.llvm.org/ce/z/9kSkMv Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149412
2023-04-30[ValueTracking] Add logic for `isKnownNonZero(sshl.sat/ushl.sat X, Y)`Noah Goldstein1-0/+2
`(sshl/ushl X, Y) != 0` -> `X != 0` Alive2 Links https://alive2.llvm.org/ce/z/4WLM2p https://alive2.llvm.org/ce/z/BHFng4 Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149411
2023-04-30[ValueTracking] Add logic for `isKnownNonZero(ctlz/cttz X)`Noah Goldstein1-0/+6
for `cttz` if `X[0]` is non-zero, then the expression is non-zero. for `ctlz` if `X[SignBit]` is non-zero, then the expression in non-zero. Alive2 Links: cttz (false): https://alive2.llvm.org/ce/z/ySQzbg cttz (true): https://alive2.llvm.org/ce/z/auiTCJ ctlz (false): https://alive2.llvm.org/ce/z/yk3sTJ ctlz (true): https://alive2.llvm.org/ce/z/-JuDty Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149410
2023-04-30[ValueTracking] Handle bitcasts between vec-int-ptr in `isKnownNonZero`Noah Goldstein1-3/+32
We where missing these cases so something like: `(bitcast to i32 (or v216 x, <2, 1>))` would not be found to be non-zero. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149409
2023-04-30[ValueTracking] Pull out logic for detecting if `(add X, Y)` is non-zero; NFCNoah Goldstein1-34/+41
Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149407
2023-04-30[ValueTracking] Pull out logic for detecting if `(sub X, Y)` is non-zero; NFCNoah Goldstein1-19/+21
Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149406
2023-04-28Handle `select` in programUndefinedIfPoison.Justin Lebar1-1/+10
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[ValueTracking] Add logic for `fshl/fshr(A, B, C) != 0` if `A == B && A ! = 0`Noah Goldstein1-0/+6
Having `A == B` is quite common for rotate patterns. Alive2 Links: - https://alive2.llvm.org/ce/z/mPXi9c - https://alive2.llvm.org/ce/z/UfDHoI Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149372
2023-04-27[ValueTracking] Add logic for `udiv x,y != 0` if `y u<= x`Noah Goldstein1-0/+15
Alive2 Link: https://alive2.llvm.org/ce/z/2DKh46 Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149203
2023-04-27[IR][NFC] Change UndefMaskElem to PoisonMaskElemManuelJBrito1-1/+1
Following the change in shufflevector semantics, poison will be used to represent undefined elements in shufflevector masks. Differential Revision: https://reviews.llvm.org/D149256
2023-04-26[ValueTracking] Add logic for `add nuw x,y != 0` -> `x != 0 || y != 0`Noah Goldstein1-0/+8
Alive2 Link: https://alive2.llvm.org/ce/z/TKpqxc Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149204
2023-04-26[ValueTracking] Add logic for `(sub x, y) != 0` if we know `KnownX != KnownY`Noah Goldstein1-2/+15
Alive2 Link: https://alive2.llvm.org/ce/z/TAFcjF Differential Revision: https://reviews.llvm.org/D149202
2023-04-27[InstSimplify] Extend handlng of fp min/max.Serguei Katkov1-0/+6
Add support the cases like m(m(X,Y),m'(X,Y)) => m(X,Y) where m is one of maxnum, minnum, maximum, minimum and m' is m or inverse of m. alive2 correctness check: maxnum(maxnum,maxnum) https://alive2.llvm.org/ce/z/kSyAzo maxnum(maxnum,minnum) https://alive2.llvm.org/ce/z/Vra8j2 minnum(minnum,minnum) https://alive2.llvm.org/ce/z/B6h-hW minnum(minnum,maxnum) https://alive2.llvm.org/ce/z/rG2u_b maximum(maximum,maximum) https://alive2.llvm.org/ce/z/N2nevY maximum(maximum,minimum) https://alive2.llvm.org/ce/z/23RFcP minimum(minimum,minimum) https://alive2.llvm.org/ce/z/spHZ-U minimum(minimum,maximum) https://alive2.llvm.org/ce/z/Aa-VE8 Reviewed By: dantrushin, RKSimon Differential Revision: https://reviews.llvm.org/D147137
2023-04-27[ValueTracking] Guaranteed not to be undef if has dereferenceable attributeluxufan1-1/+3
As LangRef says, "dereferenceable<n> implies noundef". `isGuaranteedNotToBeUndefOrPoison` should return true if the parameter has dereferenceable attribute. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149035
2023-04-26ValueTracking: Handle frem in computeKnownFPClassMatt Arsenault1-19/+48
I barely understand what this does, but try to handle the last case required to delete cannotBeOrderedLessThanZeroImpl. Also improve by following fdiv handling for nans and identical operand case.
2023-04-26ValueTracking: fdiv sign handling in computeKnownFPClassMatt Arsenault1-9/+21
Copy what cannotBeOrderedLessThanZeroImpl checks for fdiv.
2023-04-26ValueTracking: Improve trunc handling in computeKnownFPClassMatt Arsenault1-3/+23