aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-04-26ValueTracking: Handle powi in computeKnownFPClassMatt Arsenault1-0/+30
Extract the handling from cannotBeOrderedLessThanZeroImpl and avoid the mentioned -0 bug.
2023-04-26ValueTracking: Implement computeKnownFPClass for logMatt Arsenault1-0/+35
2023-04-24ValueTracking: Add ordered negative handling for fmul to computeKnownFPClassMatt Arsenault1-0/+7
Port from the existing handling in cannotBeOrderedLessThanZero
2023-04-24ValueTracking: Handle fptrunc_round in computeKnownFPClassMatt Arsenault1-10/+27
2023-04-24ValueTracking: Implement computeKnownFPClass for fma/fmuladdMatt Arsenault1-0/+21
Copy handling from CannotBeOrderedLessThanZero
2023-04-24ValueTracking: Handle exp/exp2 in computeKnownFPClassMatt Arsenault1-0/+16
2023-04-24ValueTracking: Fix computeKnownFPClass for fabsMatt Arsenault1-3/+9
The fabs utility functions have the opposite purpose and probably should not be a general utility.
2023-04-21ValueTracking: Recognize >=, <= compares with 0 as is.fpclass masksMatt Arsenault1-3/+21
Leave DAZ handling for a future change.
2023-04-21ValueTracking: Implement computeKnownFPClass for fpextMatt Arsenault1-0/+19
2023-04-19ValueTracking: uitofp/sitofp cannot return denormal resultsMatt Arsenault1-0/+7
2023-04-19ValueTracking: Handle sign bit of constrained sitofp/uitofpMatt Arsenault1-1/+14
This is for parity with CannotBeNegativeZero which is close to droppable.
2023-04-19ValueTracking: Implement computeKnownFPClass for fdiv for nan handlingMatt Arsenault1-0/+34
2023-04-19ValueTracking: Fix backwards handling of fpclass assumesMatt Arsenault1-6/+8
This was a bit confused because nofpclass expresses the opposite from what an assume of class expresses. We need to assume the intersection of assumed classes, which also needs to be inverted to convert to nofpclass.
2023-04-19ValueTracking: Handle shufflevector in computeKnownFPClassMatt Arsenault1-0/+30
2023-04-19ValueTracking: Handle insertelement in computeKnownFPClassMatt Arsenault1-4/+52
2023-04-19ValueTracking: sitofp cannot return -0Matt Arsenault1-0/+3
2023-04-19[NFC] Rename isPointerOffset to getPointerOffsetFrom and move to Value.hOCHyams1-71/+0
Linking LLVMCore failed when building D148536 with shared libs enabled: https://lab.llvm.org/buildbot/#/builders/121/builds/29766 Make isPointerOffset a Value method and rename it to getPointerOffsetFrom. Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D148698
2023-04-18Recommit "[ValueTracking] Apply the isKnownNonZero techniques in ↵Noah Goldstein1-23/+53
`ashr`/`lshl` to `shl` and vice-versa" (2nd Try) Wasn't related to the bug it was original thought to be causing.
2023-04-18[ValueTracking] Use SmallPtrSetImpl (NFC)Nikita Popov1-1/+1
Don't hardcode set size in function signature.
2023-04-18Revert "[ValueTracking] Apply the isKnownNonZero techniques in `ashr`/`lshl` ↵Noah Goldstein1-53/+23
to `shl` and vice-versa" May be related to PR62175 This reverts commit 57590d1dd47bbe9aa4b79a0f93cc3ec62cc5d060.
2023-04-17[ValueTracking] Apply the isKnownNonZero techniques in `ashr`/`lshl` to ↵Noah Goldstein1-23/+53
`shl` and vice-versa For all shifts we can apply the same two optimizations. 1) `ShiftOp(KnownVal.One, Max(KnownCnt)) != 0` -> result is non-zero 2) If already known `Val != 0` and we only shift out zeros (based on `Max(KnownCnt)`) -> result is non-zero The former exists for `shl` and the latter (for constant `Cnt`) exists for `ashr`/`lshr`. This patch improves the latter to use `Max(KnownCnt)` instead of relying on a constant shift `Cnt` and applies both techniques for all shift ops. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D148404
2023-04-17Revert "ValueTracking: Handle freeze in computeKnownFPClass"Nikita Popov1-2/+1
This reverts commit 2c8d0048f03d054f13909a26f959ef95b2a0a4de. This is incorrect: computeKnownFPClass() is only known up to poison, and freeze poison may have any FP class.
2023-04-14[ValueTracking] Add `shl nsw %val, %cnt != 0` if `%val != 0`.Noah Goldstein1-2/+2
Alive2 Link: https://alive2.llvm.org/ce/z/mxZLJn Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D147898
2023-04-14[ValueTracking] Use maximum shift count in `shl` when determining if `shl` ↵Noah Goldstein1-0/+10
can be zero. Previously only return `shl` non-zero if the shift value was `1`. We can expand this if we have some bounds on the shift count. For example: ``` %cnt = and %c, 16 ; Max cnt == 16 %val = or %v, 4 ; val[2] is known one %shl = shl %val, %cnt ; (val.known.one << cnt.maxval) != 0 ``` Differential Revision: https://reviews.llvm.org/D147897
2023-04-14ValueTracking: Handle freeze in computeKnownFPClassMatt Arsenault1-1/+2
2023-04-14ValueTracking: Implement computeKnownFPClass for arithmetic.fenceMatt Arsenault1-0/+5
2023-04-14ValueTracking: Implement computeKnownFPClass for llvm.truncMatt Arsenault1-0/+19
2023-04-14ValueTracking: Handle non-splat vectors in computeKnownFPClassMatt Arsenault1-6/+32
Avoids some regressions when the implementation of isKnownNeverNaN is replaced with computeKnownFPClass.
2023-04-14ValueTracking: Implement computeKnownFPClass for canonicalizeMatt Arsenault1-0/+20
2023-04-14ValueTracking: Handle fptrunc in computeKnownFPClassMatt Arsenault1-0/+13
Handle nan.
2023-04-14ValueTracking: Handle extractelement and extractvalue in computeKnownFPClassMatt Arsenault1-0/+23
2023-04-14ValueTracking: Implement computeKnownFPClass for sin/cosMatt Arsenault1-0/+11
2023-04-13ValueTracking: Address todo for nan fmul handling in computeKnownFPClassMatt Arsenault1-11/+26
If both operands can't be zero or nan, the result can't be nan.
2023-04-13ValueTracking: Handle no-nan check for computeKnownFPClass for fmulMatt Arsenault1-0/+16
Copy the logic from isKnownNeverNaN for fadd/fsub. Leave the extension to handle the zero case for a future change.
2023-04-12ValueTracking: Handle no-nan check for computeKnownFPClass for fadd/fsubMatt Arsenault1-0/+19
Copy the logic from isKnownNeverNaN for fadd/fsub.
2023-04-12ValueTracking: Remove outdated todoMatt Arsenault1-2/+0
2023-03-31[ValueTracking] Fix incorrect computeConstantRange() argumentsNikita Popov1-1/+1
The second argument is ForSigned, not UseInstrInfo.
2023-03-20[LSR/LFTR] Move two utilities to common code for reuse [nfc]Philip Reames1-0/+44
We're working on a transform in LSR which is essentiall an inverse of LFTR (in certain sub-cases). Move utilties so that they can be reused.
2023-03-17Attributor: Assume handling for nofpclassMatt Arsenault1-2/+53
2023-03-17[SCEV] Recognize vscale intrinsicsNikita Popov1-1/+1
Now that SCEV has a dedicated vscale node type, we should also map vscale intrinsics to it. To make sure this does not regress ranges (which were KnownBits based previously), add support for vscale to getRangeRef() as well. Differential Revision: https://reviews.llvm.org/D146226
2023-03-17[ValueTracking] Support vscale in computeConstantRange()Nikita Popov1-23/+25
Add support for vscale in computeConstantRange(), based on vscale_range attributes. This allows simplifying based on the precise range, rather than a KnownBits approximation (which will be off by a factor of two for the usual case of a power of two upper bound). Differential Revision: https://reviews.llvm.org/D146217
2023-03-16ValueTracking: Extract fcmpToClassTest out of InstCombineMatt Arsenault1-0/+172
Also update unsigned to FPClassTest
2023-03-16ValueTracking: Handle nofpclass in computeKnownFPClassMatt Arsenault1-9/+14
2023-03-16ValueTracking: Add start of computeKnownFPClass APIMatt Arsenault1-0/+148
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[ValueTracking] Return ConstantRange for intrinsic ranges (NFC)Nikita Popov1-57/+65
Instead of setting Lower and Upper, return a ConstantRange. Should do this for the others as well.
2023-02-24IR: Add nofpclass parameter attributeMatt Arsenault1-0/+25
This carries a bitmask indicating forbidden floating-point value kinds in the argument or return value. This will enable interprocedural -ffinite-math-only optimizations. This is primarily to cover the no-nans and no-infinities cases, but also covers the other floating point classes for free. Textually, this provides a number of names corresponding to bits in FPClassTest, e.g. call nofpclass(nan inf) @must_be_finite() call nofpclass(snan) @cannot_be_snan() This is more expressive than the existing nnan and ninf fast math flags. As an added bonus, you can represent fun things like nanf: declare nofpclass(inf zero sub norm) float @only_nans() Compared to nnan/ninf: - Can be applied to individual call operands as well as the return value - Can distinguish signaling and quiet nans - Distinguishes the sign of infinities - Can be safely propagated since it doesn't imply anything about other operands. - Does not apply to FP instructions; it's not a flag This is one step closer to being able to retire "no-nans-fp-math" and "no-infs-fp-math". The one remaining situation where we have no way to represent no-nans/infs is for loads (if we wanted to solve this we could introduce !nofpclass metadata, following along with noundef/!noundef). This is to help simplify the GPU builtin math library distribution. Currently the library code has explicit finite math only checks, read from global constants the compiler driver needs to set based on the compiler flags during linking. We end up having to internalize the library into each translation unit in case different linked modules have different math flags. By propagating known-not-nan and known-not-infinity information, we can automatically prune the edge case handling in most functions if the function is only reached from fast math uses.
2023-02-23Add logic for tracking lowbit of (and/xor/or X, (add/sub X, Odd))Noah Goldstein1-5/+12
Any case of logicop + add/sub(Odd) we can prove the low bit is either zero/non-zero. Alive2 Links: xor: sub x, C: https://alive2.llvm.org/ce/z/aaABdS sub C, x: https://alive2.llvm.org/ce/z/2W-ZJ7 add C, x: https://alive2.llvm.org/ce/z/pzDkte or: sub x, C: https://alive2.llvm.org/ce/z/xd-bcP sub C, x: https://alive2.llvm.org/ce/z/p8hXJF add C, x: https://alive2.llvm.org/ce/z/osmkB6 and: sub x, C: https://alive2.llvm.org/ce/z/D_NNxR sub C, x: https://alive2.llvm.org/ce/z/N_5C62 add C, x: https://alive2.llvm.org/ce/z/4cy7a4 Differential Revision: https://reviews.llvm.org/D142427
2023-02-23Add helper for handling `computeKnownBits` for and/xor/or; NFCNoah Goldstein1-51/+86
This change just factors out the existing logic for and/xor/or and puts them in a publicly available helper. functionality is the same. Differential Revision: https://reviews.llvm.org/D142849
2023-02-20Revert "[AssumptionCache] caches @llvm.experimental.guard's"Max Kazantsev1-3/+11
This reverts commit f9599bbc7a3f831e1793a549d8a7a19265f3e504. For some reason it caused us a huge compile time regression in downstream workloads. Not sure whether the source of it is in upstream code ir not. Temporarily reverting until investigated. Differential Revision: https://reviews.llvm.org/D142330
2023-02-19Use APInt::count{l,r}_{zero,one} (NFC)Kazu Hirata1-11/+11