aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-02-18[ValueTracking] Add cases for additional ops in `isKnownNonZero`Noah Goldstein1-2/+26
Add cases for the following ops: - 0-X -- https://alive2.llvm.org/ce/z/6C75Li - bitreverse(X) -- https://alive2.llvm.org/ce/z/SGG1q9 - bswap(X) -- https://alive2.llvm.org/ce/z/p7pzwh - ctpop(X) -- https://alive2.llvm.org/ce/z/c5y3BC - abs(X) -- https://alive2.llvm.org/ce/z/yxXGz_ https://alive2.llvm.org/ce/z/rSRg4K - uadd_sat(X, Y) -- https://alive2.llvm.org/ce/z/Zw-y4W https://alive2.llvm.org/ce/z/2NRqRz https://alive2.llvm.org/ce/z/M1OpF8 Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D142828
2023-02-18[ValueTracking] Add KnownBits patterns `xor(x, x - 1)` and `and(x, -x)` for ↵Noah Goldstein1-4/+33
knowing upper bits to be zero These two BMI pattern will clear the upper bits of result past the first set bit. So if we know a single bit in `x` is set, we know that `results[bitwidth - 1, log2(x) + 1] = 0`. Alive2: blsmsk: https://alive2.llvm.org/ce/z/a397BS blsi: https://alive2.llvm.org/ce/z/tsbQhC Differential Revision: https://reviews.llvm.org/D142271
2023-02-09[ValueTracking] Replace an always false condition with an assert. NFCCraig Topper1-2/+1
The one caller of this function already checked that V isn't a Constant. Alternatively, we could remove the check from the caller if reviewers prefer. Reviewed By: spatel Differential Revision: https://reviews.llvm.org/D143677
2023-02-03[RISCV] Remove side effects from vsetvli intrinsics.Craig Topper1-2/+0
Delete the opt intrinsics since they are now identical. I left the side effects due to user expectations about how these interact with things like inline assembly or function calls. Or that they wouldn't be hoisted. I think we should look at other ways to address thoughs. If I could, I'd rename them these somehow to distance them from the vsetvli instruction. In some sense they only query the VL for a particular SEW and LMUL. They don't guarantee a vsetvli instruction will be emitted. Fixes https://github.com/llvm/llvm-project/issues/59359 Reviewed By: rogfer01, kito-cheng Differential Revision: https://reviews.llvm.org/D143220
2023-01-28Use llvm::count{lr}_{zero,one} (NFC)Kazu Hirata1-1/+1
2023-01-27[RISCV] Teach computeKnownBits that vsetvli returns <= 65536.Craig Topper1-4/+4
Resolves a FIXME. We could do even better taking into account SEW/LMUL.
2023-01-27[ValueTracking] Teach computeKnownBits about riscv.vsetvli.opt and ↵Craig Topper1-0/+2
riscv.vsetvlimax.opt intrinsics. These are like the intrinsic without opt, but don't have side effects. Add missing test cases for riscv.vsetvlimax.
2023-01-27Lift EHPersonalities from Analysis to IR (NFC)Stefan Gränitz1-1/+1
Computing EH-related information was only relevant for analysis passes so far. Lifting it to IR will allow the IR Verifier to calculate EH funclet coloring and validate funclet operand bundles in a follow-up step. Reviewed By: rnk, compnerd Differential Revision: https://reviews.llvm.org/D138122
2023-01-24[AssumptionCache] caches @llvm.experimental.guard'sJoshua Cao1-11/+3
As discussed in https://github.com/llvm/llvm-project/issues/59901 This change is not NFC. There is one SCEV and EarlyCSE test that have an improved analysis/optimization case. Rest of the tests are not failing. I've mostly only added cleanup to SCEV since that is where this issue started. As a follow up, I believe there is more cleanup opportunity in SCEV and other affected passes. There could be cases where there are missed registerAssumption of guards, but this case is not so bad because there will be no miscompilation. AssumptionCacheTracker should take care of deleted guards. Differential Revision: https://reviews.llvm.org/D142330
2023-01-21[llvm] Use llvm::bit_width (NFC)Kazu Hirata1-1/+1
2023-01-21[llvm] Use llvm::bit_width (NFC)Kazu Hirata1-3/+3
2023-01-20[ValueTracking] Take poison-generating metadata into account (PR59888)Nikita Popov1-6/+9
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-15ValueTracking: Teach CannotBeOrderedLessThanZero about rounding intrinsicsMatt Arsenault1-0/+8
These should obviously preserve the sign although the variety of these always confuses me.
2023-01-11[NFC] Use TypeSize::geFixedValue() instead of TypeSize::getFixedSize()Guillaume Chatelet1-6/+6
This change is one of a series to implement the discussion from https://reviews.llvm.org/D141134.
2023-01-11[NFC] Use TypeSize::getKnownMinValue() instead of TypeSize::getKnownMinSize()Guillaume Chatelet1-1/+1
This change is one of a series to implement the discussion from https://reviews.llvm.org/D141134.
2023-01-11[InstCombine] Handle assume(X & Pow2 != 0) in computeKnownBits()Noah Goldstein1-0/+8
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-05Move from llvm::makeArrayRef to ArrayRef deduction guides - llvm/ partserge-sans-paille1-5/+4
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-03[ValueTracking] Improve ComputeNumSignBits to handle TruncOwen Anderson1-4/+11
Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D140796
2023-01-02[ValueTracking] Use SmallVector for non-undef/poison opsNikita Popov1-15/+15
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[ValueTracking] Treat branch on undef as UB as wellNikita Popov1-9/+9
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[ValueTracking] Remove branch-on-poison-as-ub flag (NFC)Nikita Popov1-12/+2
This has been enabled by default without issue for a while now, remove the flag.
2022-12-30ValueTracking: Fix canCreateUndefOrPoison for saturating shiftsMatt Arsenault1-21/+29
These need to consider the shift amount.
2022-12-23ValueTracking: Teach canCreateUndefOrPoison about saturating intrinsicsMatt Arsenault1-0/+6
2022-12-22ValueTracking: Add test for isKnownNeverInfinity for fptruncMatt Arsenault1-0/+4
2022-12-20ValueTracking: Document some difficult isKnownNeverInfinity casesMatt Arsenault1-0/+18
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-20ValueTracking: Teach isKnownNeverInfinity about llvm.sin/llvm.cosMatt Arsenault1-0/+4
2022-12-20ValueTracking: Teach isKnownNeverInfinity about sqrtMatt Arsenault1-0/+1
2022-12-20ValueTracking: Teach isKnownNeverInfinity about min/max functionsMatt Arsenault1-0/+6
2022-12-20ValueTracking: Teach isKnownNeverInfinity about rounding intrinsicsMatt Arsenault1-0/+14
2022-12-19[ValueTracking] Consider single poison operands in propgatesPoison.Florian Hahn1-19/+16
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-14Don't include Optional.hKazu Hirata1-1/+0
These files no longer use llvm::Optional.
2022-12-14[Analysis] llvm::Optional => std::optionalFangrui Song1-30/+32
2022-12-13[ValueTracking] peek through extends in haveNoCommonBitsSet (2nd try)Sanjay Patel1-0/+9
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-13Revert "[InstCombine] add tests for add-of-extends; NFC"Sanjay Patel1-6/+0
This reverts commit c8cba0bc4a8c9f4f3f10e17f601ed924dfb82bef. An unintended code change snuck into this (was supposed to just add tests).
2022-12-13Revert "[ValueTracking] peek through extends in haveNoCommonBitsSet"Sanjay Patel1-6/+3
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[ValueTracking] peek through extends in haveNoCommonBitsSetSanjay Patel1-3/+6
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[InstCombine] add tests for add-of-extends; NFCSanjay Patel1-0/+6
2022-12-12ValueTracking: Teach canCreateUndefOrPoison about FP opsMatt Arsenault1-0/+41
Probably could replace the switch by marking the intrinsic definitions with NoUndef<RetIndex>.
2022-12-11Use poison instead of undef where its used as a placeholder [NFC]Manuel Brito1-1/+1
Differential Revision: https://reviews.llvm.org/D139789
2022-12-06[ADT] Don't including None.h (NFC)Kazu Hirata1-1/+0
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-06ValueTracking: Teach CannotBeOrderedLessThanZero about copysignMatt Arsenault1-1/+4
2022-12-05ValueTracking: Teach canCreateUndefOrPoison about more intrinsicsMatt Arsenault1-0/+17
I tried to test the fallthrough to noundef callsite return attribute case, but it seems that folds out as-is.
2022-12-05ValueTracking: Teach CannotBeOrderedLessThanZero about trivial opsMatt Arsenault1-0/+3
Handle canonicalize and arithmetic.fence
2022-12-05ValueTracking: Teach isKnownNeverNaN about arithmetic_fenceMatt Arsenault1-0/+1
2022-12-05ValueTracking: Teach isKnownNeverInfinity about arithmetic.fenceMatt Arsenault1-0/+1
2022-12-04[llvm] Use std::nullopt instead of None in comments (NFC)Kazu Hirata1-8/+9
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[Analysis] Use std::nullopt instead of None (NFC)Kazu Hirata1-21/+21
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-02Attributes: convert Optional to std::optionalKrzysztof Parzyszek1-1/+1
2022-11-25[Analysis] Use std::optional in ValueTracking.cpp (NFC)Kazu Hirata1-3/+4
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-20[Analysis] Remove getInverseMinMaxPredKazu Hirata1-4/+0
The last uses of getInverseMinMaxPred were removed on February 24, 2022 in commit 5423b0a52567b2fba8cbae3afee760f53c3f14d2.