summaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
AgeCommit message (Collapse)Author
2025-06-27[ValueTracking] Add `matchSimpleBinaryIntrinsicRecurrence` helperAntonio Frighetto
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-24[InstCombine] KnownBits::isNonNegative should recognize `b - a` after `a <= ↵Ross Kirsling
b` (#145105) Alive2: https://alive2.llvm.org/ce/z/an9npN Fixes #142283.
2025-06-24[ValueTracking] Return true for AddrSpaceCast in canCreateUndefOrPoison ↵Wenju He
(#144686) In our downstream GPU target, following IR is valid before instcombine although the second addrspacecast causes UB. define i1 @test(ptr addrspace(1) noundef %v) { %0 = addrspacecast ptr addrspace(1) %v to ptr addrspace(4) %1 = call i32 @llvm.xxxx.isaddr.shared(ptr addrspace(4) %0) %2 = icmp eq i32 %1, 0 %3 = addrspacecast ptr addrspace(4) %0 to ptr addrspace(3) %4 = select i1 %2, ptr addrspace(3) null, ptr addrspace(3) %3 %5 = icmp eq ptr addrspace(3) %4, null ret i1 %5 } We have a custom optimization that replaces invalid addrspacecast with poison, and IR is still valid since `select` stops poison propagation. However, instcombine pass optimizes `select` to `or`: %0 = addrspacecast ptr addrspace(1) %v to ptr addrspace(4) %1 = call i32 @llvm.xxxx.isaddr.shared(ptr addrspace(4) %0) %2 = icmp eq i32 %1, 0 %3 = addrspacecast ptr addrspace(1) %v to ptr addrspace(3) %4 = icmp eq ptr addrspace(3) %3, null %5 = or i1 %2, %4 ret i1 %5 The transform is invalid for our target. --------- Co-authored-by: Nikita Popov <github@npopov.com>
2025-06-23[InstCombine] Fold `ceil(X / (2 ^ C)) == 0` -> `X == 0` (#143683)Iris Shi
Co-authored-by: Yingwei Zheng <dtcxzyw2333@gmail.com>
2025-06-21Revert "[ValueTracking] Improve `Bitcast` handling to match SDAG" (#145191)Arthur Eubanks
Reverts llvm/llvm-project#125935 Causes miscompiles, see comments in #125935
2025-06-19[ValueTracking] Improve `Bitcast` handling to match SDAG (#125935)Abhishek Kaushik
Closes #125228
2025-06-17[DebugInfo][RemoveDIs] Remove a swathe of debug-intrinsic code (#144389)Jeremy Morse
Seeing how we can't generate any debug intrinsics any more: delete a variety of codepaths where they're handled. For the most part these are plain deletions, in others I've tweaked comments to remain coherent, or added a type to (what was) type-generic-lambdas. This isn't all the DbgInfoIntrinsic call sites but it's most of the simple scenarios. Co-authored-by: Nikita Popov <github@npopov.com>
2025-06-16[ValueTracking] Remove unused variable in matchSimpleRecurrence (NFC). (#144316)Ricardo Jesus
2025-06-16[ValueTracking] Remove opcode whitelist from matchSimpleRecurrence. (#144031)Ricardo Jesus
This also patches HashRecognize to avoid it mishandling some opcodes.
2025-06-15[ValueTracking] Add subtraction support for setLimitsForBinOp (#143618)AZero13
We can determine the range from a subtraction if it has nsw or nuw. https://alive2.llvm.org/ce/z/tXAKVV
2025-06-15[ValueTracking] Infer `X | Y != 0` from `X != Y` (#117443)Yingwei Zheng
Alive2: https://alive2.llvm.org/ce/z/cJ75Ya Closes https://github.com/llvm/llvm-project/issues/117436.
2025-06-09[ValueTracking] Update `Ordered` when both operands are non-NaN. (#143349)Yingwei Zheng
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-05[ValueTracking] Support scalable vector splats of ConstantInt/ConstantFP in ↵Craig Topper
isGuaranteedNotToBeUndefOrPoison. (#142894) Scalable vectors use insertelt+shufflevector ConstantExpr to represent a splat.
2025-06-05[ValueTracking] Support scalable vectors for ExtractElement in ↵Craig Topper
computeKnownFPClass. (#143051) We can support scalable vectors by setting the demanded mask to APInt(1, 1) to demand the whole vector.
2025-06-03[ValueTracking] Make Depth last default arg (NFC) (#142384)Ramkumar Ramachandra
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][NFC]: Use injected condition to compute known FPClass (#139832)Hassnaa Hamdi
2025-06-02[ValueTracking] Do not use FMF from fcmp (#142266)Yingwei Zheng
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-06-02[ValueTracking][NFC] Simplify binops in canCreateUndefOrPoison switch (#139906)Cullen Rhodes
Already handled by default case.
2025-05-28[ValueTracking][InstCombine] Generalize ignoreSignBitOfZero/NaN to handle ↵Yingwei Zheng
more cases (#141015) This patch was originally part of https://github.com/llvm/llvm-project/pull/139861. It generalizes `ignoreSignBitOfZero/NaN` to handle more instructions/intrinsics. BTW, I find it mitigates performance regressions caused by https://github.com/llvm/llvm-project/pull/141010 (IR diff https://github.com/dtcxzyw/llvm-opt-benchmark/pull/2365/files). We don't need to propagate FMF from fcmp into select, since we can infer demanded properties from the user of select.
2025-05-27[ValueTracking] Support trunc nuw condition in isImpliedCondition (#141528)Andreas Jonson
Proof: https://alive2.llvm.org/ce/z/oqQyxC
2025-05-22Reland [llvm] add GenericFloatingPointPredicateUtils #140254 (#141065)Tim Gymnich
#140254 was previously missing 2 files in the bazel build config.
2025-05-21Revert "[llvm] add GenericFloatingPointPredicateUtils (#140254)" (#140968)Kewen12
This reverts commit d00d74bb2564103ae3cb5ac6b6ffecf7e1cc2238. The PR breaks our buildbots and blocks downstream merge.
2025-05-21[llvm] add GenericFloatingPointPredicateUtils (#140254)Tim Gymnich
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-15[ValueTracking][NFC] Drop outdated TODO in canCreateUndefOrPoison (#139915)Cullen Rhodes
The inrange constexpr GEP case is handled since 425cbbc602c9.
2025-05-09Analysis: Remove no-AssumptionCache path in getKnowledgeForValue (#139232)Matt Arsenault
As requested in https://github.com/llvm/llvm-project/pull/138961#discussion_r2078483175
2025-05-07ValueTracking: Handle minimumnum and maximumnum in computeKnownFPClass (#138737)Matt Arsenault
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-05-06ValueTracking: Handle minimumnum/maximumnum in canCreateUndefOrPoison (#138729)Matt Arsenault
2025-04-30[LVI][ValueTracking] Take UB-implying attributes into account in ↵Yingwei Zheng
`isSafeToSpeculativelyExecute` (#137604) Closes https://github.com/llvm/llvm-project/issues/137582. In the original case, LVI uses the edge information in `%entry -> %if.end` to get a more precise result. However, since the call to `smin` has an `noundef` return attribute, an immediate UB will be triggered after optimization. Currently, `isSafeToSpeculativelyExecuteWithOpcode(%min)` returns true because https://github.com/llvm/llvm-project/commit/6a288c1e32351d4be3b7630841af078fa1c3bb8b only checks whether the function is speculatable. However, it is not enough in this case. This patch takes UB-implying attributes into account if `IgnoreUBImplyingAttrs` is set to false. If it is set to true, the caller is responsible for correctly propagating UB-implying attributes.
2025-04-22Reapply [ValueTracking] Drop ucmp/scmp from getIntrinsicRange() (NFCI)Nikita Popov
Reapply after d51b2785abf77978d9218a7b6fb5b8ec6c770c31, which should fix optimization regressions. After #135642 we have a range attribute on the intrinsic declaration, so we should not need the special handling here.
2025-04-22Revert "[ValueTracking] Drop ucmp/scmp from getIntrinsicRange() (NFCI)"Hans Wennborg
This does seem to cause some functionality to change, see comment on https://github.com/llvm/llvm-project/commit/278c429d11e63bc709ea8c537b23c4e350ce2a07 This reverts commit 278c429d11e63bc709ea8c537b23c4e350ce2a07.
2025-04-22[ValueTracking] Drop ucmp/scmp from getIntrinsicRange() (NFCI)Nikita Popov
After #135642 we have a range attribute on the intrinsic declaration, so we should not need the special handling here.
2025-04-18[ValueTracking] Refactor `isKnownNonEqualFromContext` (#127388)Yingwei Zheng
This patch avoids adding RHS for comparisons with two variable operands (https://github.com/llvm/llvm-project/pull/118493#discussion_r1949397482). Instead, we iterate over related dominating conditions of both V1 and V2 in `isKnownNonEqualFromContext`, as suggested by goldsteinn (https://github.com/llvm/llvm-project/pull/117442#discussion_r1944058002). Compile-time improvement: https://llvm-compile-time-tracker.com/compare.php?from=c6d95c441a29a45782ff72d6cb82839b86fd0e4a&to=88464baedd7b1731281eaa0ce4438122b4d218a7&stat=instructions:u
2025-04-10[ValueTracking] Handle assume(trunc x to i1) in ComputeKnownBits (#118406)Andreas Jonson
proof: https://alive2.llvm.org/ce/z/zAspzb
2025-04-09ValueTracking: Do not look at users of constants for ephemeral values (#134618)Matt Arsenault
2025-04-03Ensure KnownBits passed when calculating from range md has right size (#132985)LU-JOHN
KnownBits passed to computeKnownBitsFromRangeMetadata must have the same bit width as the range metadata bit width. Otherwise the calculated results will be incorrect. --------- Signed-off-by: John Lu <John.Lu@amd.com>
2025-03-28[Analysis][NFC] Extract KnownFPClass (#133457)Tim Gymnich
- extract KnownFPClass for future use inside of GISelKnownBits --------- Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-03-21[llvm:ir] Add support for constant data exceeding 4GiB (#126481)pzzp
The test file is over 4GiB, which is too big, so I didn’t submit it.
2025-03-09[ValueTracking] Bail out on x86_fp80 when computing fpclass with knownbits ↵Yingwei Zheng
(#130477) In https://github.com/llvm/llvm-project/pull/97762, we assume the minimum possible value of X is NaN implies X is NaN. But it doesn't hold for x86_fp80 format. If the knownbits of X are `?'011111111111110'????????????????????????????????????????????????????????????????`, the minimum possible value of X is NaN/unnormal. However, it can be a normal value. Closes https://github.com/llvm/llvm-project/issues/130408.
2025-03-07[ValueTracking] Skip incoming values that are the same as the phi in ↵DianQK
`isGuaranteedNotToBeUndefOrPoison` (#130111) Fixes (keep it open) #130110. If the incoming value is PHI itself, we can skip this. If we can guarantee that the other incoming values are neither undef nor poison, then we can also guarantee that the value isn't either. If we cannot guarantee that, it makes no sense in calculating it.
2025-03-06[ValueTracking] ComputeNumSignBitsImpl - add basic handling of BITCAST nodes ↵Narayan
(#127218) When a wider scalar/vector type containing all sign bits is bitcast to a narrower vector type, we can deduce that the resulting narrow elements will also be all sign bits. This matches existing behavior in SelectionDAG and helps optimize cases involving SSE intrinsics where sign-extended values are bitcast between different vector types. The current implementation fails to recognize that an arithmetic right shift is redundant when applied to elements that are already known to be all sign bits. This PR improves ComputeNumSignBitsImpl to track this information through bitcasts, enabling the optimization of such cases. ``` %ext = sext <1 x i1> %cmp to <1 x i8> %sub = bitcast <1 x i8> %ext to <4 x i2> %sra = ashr <4 x i2> %sub, <i2 1, i2 1, i2 1, i2 1> ; Can be simplified to just: %sub = bitcast <1 x i8> %ext to <4 x i2> ``` Closes #87624
2025-02-18[RISCV] Move the RISCVII namespaced enums into RISCVVType namespace in ↵Craig Topper
RISCVTargetParser.h. NFC (#127585) The VLMUL and policy enums originally lived in RISCVBaseInfo.h in the backend which is where everything else in the RISCVII namespace is defined. RISCVTargetParser.h is used by much more of the compiler and it doesn't really make sense to have 2 different namespaces exposed. These enums are both associated with VTYPE so using the RISCVVType namespace seems like a good home for them.
2025-02-17[Analysis] Remove getGuaranteedNonPoisonOps (#127461)Kazu Hirata
commit 0517772b4ac20c5d3a0de0d4703354a179833248 Author: Philip Reames <preames@rivosinc.com> Date: Thu Dec 19 14:14:11 2024 -0800
2025-02-17[Analysis] Remove getGuaranteedWellDefinedOps (#127453)Kazu Hirata
The last use was removed in: commit ac9e67756e0157793d565c2cceaf82e4403f58ba Author: Yingwei Zheng <dtcxzyw2333@gmail.com> Date: Mon Feb 26 01:53:16 2024 +0800
2025-02-12[ValueTracking] Infer NonEqual from dominating conditions/assumptions (#117442)Yingwei Zheng
This patch adds context-sensitive analysis support for `isKnownNonEqual`. It is required for https://github.com/llvm/llvm-project/issues/117436.
2025-02-11[ValueTracking] Handle trunc to i1 as condition in dominating condition. ↵Andreas Jonson
(#126414) proof: https://alive2.llvm.org/ce/z/gALGmv
2025-02-10[ValueTracking] Handle not in dominating condition. (#126423)Andreas Jonson
General handling of not in dominating condition. proof: https://alive2.llvm.org/ce/z/FjJN8q
2025-02-07ValueTracking: modernize isKnownInversion (NFC) (#126234)Ramkumar Ramachandra
2025-02-05[NFC][ValueTracking] Hoist the matching of RHS constant (#125818)Yingwei Zheng
2025-02-05[ValueTracking] Remove unused `V ^ Mask == C` from ↵Yingwei Zheng
`computeKnownBitsFromCmp`. NFCI. (#125666) I believe it is unused since we always convert it into `V == Mask ^ C`. Code coverage: https://dtcxzyw.github.io/llvm-opt-benchmark/coverage/data/zyw/opt-ci/actions-runner/_work/llvm-opt-benchmark/llvm-opt-benchmark/llvm/llvm-project/llvm/lib/Analysis/ValueTracking.cpp.html#L706
2025-02-04[ValueTracking] Fix bit width handling in computeKnownBits() for GEPs (#125532)Nikita Popov
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.