aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
AgeCommit message (Collapse)AuthorFilesLines
2020-03-21[ValueTracking] Short-circuit computeKnownBitsAddSub(); NFCINikita Popov1-7/+7
If one operand is unknown (and we don't have nowrap), don't compute the second operand. Also don't create an unnecessary extra KnownBits variable, it's okay to reuse KnownOut. This reduces instructions on libclamav_md5.c by 40%.
2020-03-20[ValueTracking] Fix usage of DataLayout::getTypeStoreSize()Huihui Zhang1-3/+3
Summary: DataLayout::getTypeStoreSize() returns TypeSize. For cases where it can not be scalable vector (e.g., GlobalVariable), explicitly call TypeSize::getFixedSize(). For cases where scalable property doesn't matter, (e.g., check for zero-sized type), use TypeSize::isNonZero(). Reviewers: sdesmalen, efriedma, apazos, reames Reviewed By: efriedma Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D76454
2020-03-20[ValueTracking][SVE] Fix getOffsetFromIndex for scalable vector.Huihui Zhang1-4/+6
Summary: Return None if GEP index type is scalable vector. Size of scalable vectors are multiplied by a runtime constant. Avoid transforming: %a = bitcast i8* %p to <vscale x 16 x i8>* %tmp0 = getelementptr <vscale x 16 x i8>, <vscale x 16 x i8>* %a, i64 0 store <vscale x 16 x i8> zeroinitializer, <vscale x 16 x i8>* %tmp0 %tmp1 = getelementptr <vscale x 16 x i8>, <vscale x 16 x i8>* %a, i64 1 store <vscale x 16 x i8> zeroinitializer, <vscale x 16 x i8>* %tmp1 into: %a = bitcast i8* %p to <vscale x 16 x i8>* %tmp0 = getelementptr <vscale x 16 x i8>, <vscale x 16 x i8>* %a, i64 0 %1 = bitcast <vscale x 16 x i8>* %tmp0 to i8* call void @llvm.memset.p0i8.i64(i8* align 16 %1, i8 0, i64 32, i1 false) Reviewers: sdesmalen, efriedma, apazos, reames Reviewed By: sdesmalen Subscribers: tschuett, hiraditya, rkruppe, arphaman, psnobl, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D76464
2020-03-20[InstCombine][X86] simplifyX86immShift - convert variable in-range vector ↵Simon Pilgrim1-0/+20
shift by scalar amounts to generic shifts (PR40391) The sll/srl/sra scalar vector shifts can be replaced with generic shifts if the shift amount is known to be in range. This also required public DemandedElts variants of llvm::computeKnownBits to be exposed (PR36319).
2020-03-20[ValueTracking] Add some initial isKnownNonZero DemandedElts support (PR36319)Simon Pilgrim1-16/+57
2020-03-20[ValueTracking] Add computeKnownBits DemandedElts support to shift ↵Simon Pilgrim1-12/+15
instructions (PR36319)
2020-03-19[ValueTracking] Add computeKnownBits DemandedElts support to ADD/SUB/MUL ↵Simon Pilgrim1-16/+17
instructions (PR36319)
2020-03-18[ValueTracking] Add computeKnownBits DemandedElts support to masked add ↵Simon Pilgrim1-1/+1
instructions (PR36319)
2020-03-18[ValueTracking] Add computeKnownBits DemandedElts support to XOR ↵Simon Pilgrim1-2/+2
instructions (PR36319)
2020-03-18[ValueTracking] Add computeKnownBits DemandedElts support to ↵Simon Pilgrim1-10/+17
EXTRACTELEMENT/OR/BSWAP/BITREVERSE instructions (PR36319) These are all covered by the bswap/bitreverse vector tests.
2020-03-18[ValueTracking] Add computeKnownBits DemandedElts support to AND ↵Simon Pilgrim1-2/+2
instructions (PR36319)
2020-03-17[ValueTracking][SVE] Fix isGEPKnownNonNull for scalable vector.Huihui Zhang1-1/+1
Summary: DataLayout::getTypeAllocSize() return TypeSize. For cases where the scalable property doesn't matter, we should explicitly call getKnownMinSize() to avoid implicit type conversion to uint64_t, which is not valid for scalable vector type. Reviewers: sdesmalen, efriedma, apazos, reames Reviewed By: efriedma Subscribers: tschuett, hiraditya, rkruppe, psnobl, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D76260
2020-03-13[SCEV] Add support for GEPs over scalable vectors.Eli Friedman1-1/+1
Because we have to use a ConstantExpr at some point, the canonical form isn't set in stone, but this seems reasonable. The pretty sizeof(<vscale x 4 x i32>) dumping is a relic of ancient LLVM; I didn't have to touch that code. :) Differential Revision: https://reviews.llvm.org/D75887
2020-03-06[APFloat] Make use of new overloaded comparison operators. NFC.Jay Foad1-2/+2
Reviewers: ekatz, spatel, jfb, tlively, craig.topper, RKSimon, nikic, scanon Subscribers: arsenm, jvesely, nhaehnle, hiraditya, dexonsmith, kerbowa, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75744
2020-03-06[ValueTracking] Let isGuaranteedNotToBeUndefOrPoison look into branch ↵Juneyoung Lee1-1/+27
conditions of dominating blocks' terminators Summary: ``` br i1 c, BB1, BB2: BB1: use1(c) BB2: use2(c) ``` In BB1 and BB2, c is never undef or poison because otherwise the branch would have triggered UB. This is a resubmission of 952ad47 with crash fix of llvm/test/Transforms/LoopRotate/freeze-crash.ll. Checked with Alive2 Reviewers: xbolva00, spatel, lebedev.ri, reames, jdoerfert, nlopes, sanjoy Reviewed By: reames Subscribers: jdoerfert, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75401
2020-03-05Revert "[ValueTracking] Let isGuaranteedNotToBeUndefOrPoison look into ↵Daniil Suchkov1-26/+1
branch conditions of dominating blocks' terminators" That commit causes SIGSEGV on some simple tests. This reverts commit 952ad4701cf0d8da79789f6b83ddaa386c60d535.
2020-03-04[ValueTracking] Let isGuaranteedNotToBeUndefOrPoison look into branch ↵Juneyoung Lee1-1/+26
conditions of dominating blocks' terminators Summary: ``` br i1 c, BB1, BB2: BB1: use1(c) BB2: use2(c) ``` In BB1 and BB2, c is never undef or poison because otherwise the branch would have triggered UB. Checked with Alive2 Reviewers: xbolva00, spatel, lebedev.ri, reames, jdoerfert, nlopes, sanjoy Reviewed By: reames Subscribers: jdoerfert, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75401
2020-03-01[ValueTracking] Let getGuaranteedNonFullPoisonOp consider assume, remove ↵Juneyoung Lee1-4/+11
mentioning about br Summary: This patch helps getGuaranteedNonFullPoisonOp handle llvm.assume call. Also, a comment about the semantics of branch is removed to prevent confusion. As llvm.assume does, branching on poison directly raises UB (as LangRef says), and this allows transformations such as introduction of llvm.assume on branch condition at each successor, or freely replacing values after conditional branch (such as at loop exit). Handling br is not addressed in this patch. It makes SCEV more accurate, causing existing LoopVectorize/IndVar/etc tests to fail. Reviewers: spatel, lebedev.ri, nlopes Reviewed By: nlopes Subscribers: hiraditya, javed.absar, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75397
2020-03-01[ValueTracking] A value is never undef or poison if it must raise UBJuneyoung Lee1-0/+7
Summary: This patch helps isGuaranteedNotToBeUndefOrPoison return true if the value makes the program always undefined. According to value tracking functions' comments, it is not still in consensus whether a poison value can be bitwise or not, so conservatively only the case with i1 is considered. Reviewers: spatel, lebedev.ri, reames, nlopes, regehr Reviewed By: nlopes Subscribers: uenoku, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75396
2020-02-19[ValueTracking] Improve isKnownNonNaN() to recognize zero splats.Jonas Paulsson1-0/+3
isKnownNonNaN() could not recognize a zero splat because that is a ConstantAggregateZero which is-a ConstantData but not a ConstantDataVector. Patch makes a ConstantAggregateZero return true. Review: Thomas Lively Differential Revision: https://reviews.llvm.org/D74263
2020-02-12[KnownBits] Introduce anyext instead of passing a flag into zextJay Foad1-2/+2
Summary: This was a very odd API, where you had to pass a flag into a zext function to say whether the extended bits really were zero or not. All callers passed in a literal true or false. I think it's much clearer to make the function name reflect the operation being performed on the value we're tracking (rather than on the KnownBits Zero and One fields), so zext means the value is being zero extended and new function anyext means the value is being extended with unknown bits. NFC. Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D74482
2020-02-07[ValueTracking] usub(a, b) cannot overflow if a >= b.Florian Hahn1-0/+10
If we know that a >= b (unsigned), usub.with.overflow(a, b) cannot overflow. Similarly, if b > a, the same expression overflows. Reviewers: nikic, RKSimon, lebedev.ri, spatel Reviewed By: nikic, Gerolf Differential Revision: https://reviews.llvm.org/D74066
2020-02-07[ValueTracking] Update implied reasoning to accept expanded cmp (NFC).Florian Hahn1-39/+71
This patch adds versions of isImpliedCondition and isImpliedByDomCondition that take a predicate, LHS and RHS operands as instead of a Value representing the condition. This allows using those functions to check conditions without having a concrete ICmp instruction. Reviewers: nikic, RKSimon, lebedev.ri, spatel Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D74065
2020-02-05Reapply: [SVE] Fix bug in simplification of scalable vector instructionsChristopher Tetreault1-0/+5
This reverts commit a05441038a3a4a011b9421751367c5c797d57137, reapplying commit 31574d38ac5fa4646cf01dd252a23e682402134f
2020-02-04[ValueTracking] Let isGuaranteedToBeUndefOrPoison look into operands of icmpJuneyoung Lee1-0/+7
2020-02-04Let isGuaranteedNotToBeUndefOrPoison consider PHINode with constant valuesJuneyoung Lee1-0/+7
2020-02-01Remove unused function. NFCI.Simon Pilgrim1-9/+0
2020-02-01[ValueTracking] Add DemandedElts support to ↵Simon Pilgrim1-46/+184
computeKnownBits/ComputeNumSignBits (PR36319) This patch adds initial support for a DemandedElts mask to the internal computeKnownBits/ComputeNumSignBits methods, matching the SelectionDAG and GlobalISel equivalents. So far only a couple of instructions have been setup to handle the DemandedElts, the remainder still using the existing 'all elements' default. The plan is to extend support as we have test coverage. Differential Revision: https://reviews.llvm.org/D73435
2020-01-22[PatternMatch] Make m_c_ICmp swap the predicate (PR42801)Nikita Popov1-4/+0
This addresses https://bugs.llvm.org/show_bug.cgi?id=42801. The m_c_ICmp() matcher is changed to provide the swapped predicate if the operands are swapped. Existing uses of m_c_ICmp() fall in one of two categories: Working on equality predicates only, where swapping is irrelevant. Or performing a manual swap, in which case this patch removes it. The only exception is the foldICmpWithLowBitMaskedVal() fold, which does not swap the predicate, and instead reasons about whether a swap occurred or not for each predicate. Getting the swapped predicate allows us to merge the logic for pairs of predicates, instead of duplicating it. Differential Revision: https://reviews.llvm.org/D72976
2019-12-20[ValueTracking] isKnownNonZero() should take non-null-ness assumptions into ↵Roman Lebedev1-0/+70
consideration (PR43267) Summary: It is pretty common to assume that something is not zero. Even optimizer itself sometimes emits such assumptions (e.g. `addAssumeNonNull()` in `PromoteMemoryToRegister.cpp`). But we currently don't deal with such assumptions :) The only way `isKnownNonZero()` handles assumptions is by calling `computeKnownBits()` which calls `computeKnownBitsFromAssume()`. But `x != 0` does not tell us anything about set bits, it only says that there are *some* set bits. So naturally, `KnownBits` does not get populated, and we fail to make use of this assumption. I propose to deal with this special case by special-casing it via adding a `isKnownNonZeroFromAssume()` that returns boolean when there is an applicable assumption. While there, we also deal with other predicates, mainly if the comparison is with constant. Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=43267 | PR43267 ]]. Differential Revision: https://reviews.llvm.org/D71660
2019-12-20[ValueTracking] isValidAssumeForContext(): CxtI itself also must transfer ↵Roman Lebedev1-5/+4
execution to successor This is a pretty rare case, when CxtI and assume are in the same basic block, with assume being located later. We were already checking that assumption was guaranteed to be executed, but we omitted CxtI itself from consideration, and as the test (miscompile) shows, that is incorrect. As noted in D71660 review by @nikic.
2019-12-13Reland [DataLayout] Fix occurrences that size and range of pointers are ↵Nicola Zaghen1-4/+4
assumed to be the same. GEP index size can be specified in the DataLayout, introduced in D42123. However, there were still places in which getIndexSizeInBits was used interchangeably with getPointerSizeInBits. This notably caused issues with Instcombine's visitPtrToInt; but the unit tests was incorrect, so this remained undiscovered. This fixes the buildbot failures. Differential Revision: https://reviews.llvm.org/D68328 Patch by Joseph Faulls!
2019-12-12Temporarily Revert "[DataLayout] Fix occurrences that size and range of ↵Nicola Zaghen1-4/+4
pointers are assumed to be the same." This reverts commit 5f6208778ff92567c57d7c1e2e740c284d7e69a5. This caused failures in Transforms/PhaseOrdering/scev-custom-dl.ll const: Assertion `getBitWidth() == CR.getBitWidth() && "ConstantRange types don't agree!"' failed.
2019-12-12[DataLayout] Fix occurrences that size and range of pointers are assumed to ↵Nicola Zaghen1-4/+4
be the same. GEP index size can be specified in the DataLayout, introduced in D42123. However, there were still places in which getIndexSizeInBits was used interchangeably with getPointerSizeInBits. This notably caused issues with Instcombine's visitPtrToInt; but the unit tests was incorrect, so this remained undiscovered. Differential Revision: https://reviews.llvm.org/D68328 Patch by Joseph Faulls!
2019-12-11[IR] Split out target specific intrinsic enums into separate headersReid Kleckner1-0/+2
This has two main effects: - Optimizes debug info size by saving 221.86 MB of obj file size in a Windows optimized+debug build of 'all'. This is 3.03% of 7,332.7MB of object file size. - Incremental step towards decoupling target intrinsics. The enums are still compact, so adding and removing a single target-specific intrinsic will trigger a rebuild of all of LLVM. Assigning distinct target id spaces is potential future work. Part of PR34259 Reviewers: efriedma, echristo, MaskRay Reviewed By: echristo, MaskRay Differential Revision: https://reviews.llvm.org/D71320
2019-12-11[ValueTracking] Pointer is known nonnull after load/storeDanila Kutenin1-0/+9
If the pointer was loaded/stored before the null check, the check is redundant and can be removed. For now the optimizers do not remove the nullptr check, see https://gcc.godbolt.org/z/H2r5GG. The patch allows to use more nonnull constraints. Also, it found one more optimization in some PowerPC test. This is my first llvm review, I am free to any comments. Differential Revision: https://reviews.llvm.org/D71177
2019-12-09[ValueTracking] Allow context-sensitive nullness check for non-pointersJohannes Doerfert1-9/+27
Summary: Same as D60846 and D69571 but with a fix for the problem encountered after them. Both times it was a missing context adjustment in the handling of PHI nodes. The reproducers created from the bugs that caused the old commits to be reverted are included. Reviewers: nikic, nlopes, mkazantsev, spatel, dlrobertson, uabelho, hakzsam, hans Subscribers: hiraditya, bollu, asbirlea, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D71181
2019-12-03[NFC][KnownBits] Add getMinValue() / getMaxValue() methodsRoman Lebedev1-1/+1
As it can be seen from accompanying cleanup, it is not unheard of to write `~Known.Zero` meaning "what maximal value can this KnownBits produce". But i think `~Known.Zero` isn't *that* self-explanatory, as compared to a method with a name. Note that not all `~Known.Zero` places were cleaned up, only those where this arguably improves things.
2019-11-19[ValueTracking] Add a basic version of isKnownNonInfinity and use it to ↵Benjamin Kramer1-4/+69
detect more NoNaNs
2019-11-13Revert 57dd4b0 "[ValueTracking] Allow context-sensitive nullness check for ↵Hans Wennborg1-4/+5
non-pointers" This caused miscompiles of Chromium (https://crbug.com/1023818). The reduced repro is small enough to fit here: $ cat /tmp/a.c unsigned char f(unsigned char *p) { unsigned char result = 0; for (int shift = 0; shift < 1; ++shift) result |= p[0] << (shift * 8); return result; } $ bin/clang -O2 -S -o - /tmp/a.c | grep -A4 f: f: # @f .cfi_startproc # %bb.0: # %entry xorl %eax, %eax retq That's nicely optimized, but I don't think it's the right result :-) > Same as D60846 but with a fix for the problem encountered there which > was a missing context adjustment in the handling of PHI nodes. > > The test that caused D60846 to be reverted was added in e15ab8f277c7. > > Reviewers: nikic, nlopes, mkazantsev,spatel, dlrobertson, uabelho, hakzsam > > Subscribers: hiraditya, bollu, llvm-commits > > Tags: #llvm > > Differential Revision: https://reviews.llvm.org/D69571 This reverts commit 57dd4b03e4806bbb4760ab6150940150d884df20.
2019-11-12Add InstCombine/InstructionSimplify support for Freeze Instructionaqjune1-0/+14
Summary: - Add llvm::SimplifyFreezeInst - Add InstCombiner::visitFreeze - Add llvm tests Reviewers: majnemer, sanjoy, reames, lebedev.ri, spatel Reviewed By: reames, lebedev.ri Subscribers: reames, lebedev.ri, filcab, regehr, trentxintong, llvm-commits Differential Revision: https://reviews.llvm.org/D29013
2019-10-31[ValueTracking] Allow context-sensitive nullness check for non-pointersJohannes Doerfert1-5/+4
Same as D60846 but with a fix for the problem encountered there which was a missing context adjustment in the handling of PHI nodes. The test that caused D60846 to be reverted was added in e15ab8f277c7. Reviewers: nikic, nlopes, mkazantsev,spatel, dlrobertson, uabelho, hakzsam Subscribers: hiraditya, bollu, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69571
2019-10-21[Alignment][NFC] Finish transition for `Loads`Guillaume Chatelet1-3/+3
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: hiraditya, asbirlea, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69253 llvm-svn: 375419
2019-10-15[Alignment][NFC] Value::getPointerAlignment returns MaybeAlignGuillaume Chatelet1-2/+2
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet, jdoerfert Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68398 llvm-svn: 374889
2019-10-10[ValueTracking] Improve pointer offset computation for cases of same baseRong Xu1-9/+39
This patch improves the handling of pointer offset in GEP expressions where one argument is the base pointer. isPointerOffset() is being used by memcpyopt where current code synthesizes consecutive 32 bytes stores to one store and two memset intrinsic calls. With this patch, we convert the stores to one memset intrinsic. Differential Revision: https://reviews.llvm.org/D67989 llvm-svn: 374454
2019-09-26Remove local shadow constant. NFCI.Simon Pilgrim1-2/+0
ValueTracking.cpp already has a local static MaxDepth = 6 constant - this one seems to have been missed when rL124183 landed. llvm-svn: 372964
2019-09-26[ValueTracking] Silence static analyzer dyn_cast<Operator> null dereference ↵Simon Pilgrim1-225/+228
warnings. NFCI. The static analyzer is warning about a potential null dereferences, but since the pointer is only used in a switch statement for Operator::getOpcode() (with an empty default) then its easiest just to wrap this in a null test as the dyn_cast might return null here. llvm-svn: 372962
2019-09-23[ValueTracking] Fix uninitialized variable warnings in matchSelectPattern ↵Simon Pilgrim1-5/+6
const wrapper. NFCI. Static analyzer complains about const_cast uninitialized variables, we should explicitly set these to null. Ideally that const wrapper would go away though....... llvm-svn: 372603
2019-09-10[ValueTracking] Factor our common speculation suppression logic [NFC]Philip Reames1-6/+13
Expose a utility function so that all places which want to suppress speculation (when otherwise legal) due to ordering and/or sanitizer interaction can do so. llvm-svn: 371556
2019-08-19Refactor isPointerOffset (NFC).Evgeniy Stepanov1-24/+19
Summary: Simplify the API using Optional<> and address comments in https://reviews.llvm.org/D66165 Reviewers: vitalybuka Subscribers: hiraditya, llvm-commits, ostannard, pcc Tags: #llvm Differential Revision: https://reviews.llvm.org/D66317 llvm-svn: 369300