summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Constants.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* IR: Properly return nullptr when getAggregateElement is out-of-boundsDavid Majnemer2015-02-161-4/+19
| | | | | | | | | | | We didn't properly handle the out-of-bounds case for ConstantAggregateZero and UndefValue. This would manifest as a crash when the constant folder was asked to fold a load of a constant global whose struct type has no operands. This fixes PR22595. llvm-svn: 229352
* Reapply "LLVMContext: Store APInt/APFloat directly into the ConstantInt/FP ↵Benjamin Kramer2014-12-061-10/+8
| | | | | | | | DenseMaps." This reapplies r223478 with a fix for 32 bit targets. llvm-svn: 223586
* Reformat.NAKAMURA Takumi2014-12-061-3/+3
| | | | llvm-svn: 223580
* Revert "LLVMContext: Store APInt/APFloat directly into the ConstantInt/FP ↵Benjamin Kramer2014-12-061-9/+10
| | | | | | | | | DenseMaps." Somehow made DenseMap probe on forever on 32 bit machines. This reverts commit r223478. llvm-svn: 223546
* LLVMContext: Store APInt/APFloat directly into the ConstantInt/FP DenseMaps.Benjamin Kramer2014-12-051-10/+9
| | | | | | | | Required some APInt massaging to get proper empty/tombstone values. Apart from making the code a bit simpler this also reduces the bucket size of the ConstantInt map from 32 to 24 bytes. llvm-svn: 223478
* Revert "unique_ptrify LLVMContextImpl::CAZConstants"David Blaikie2014-11-251-4/+4
| | | | | | | | Missed the complexities of how these elements are destroyed. This reverts commit r222714. llvm-svn: 222715
* unique_ptrify LLVMContextImpl::CAZConstantsDavid Blaikie2014-11-251-4/+4
| | | | llvm-svn: 222714
* Update SetVector to rely on the underlying set's insert to return a ↵David Blaikie2014-11-191-2/+2
| | | | | | | | | | | | | pair<iterator, bool> This is to be consistent with StringSet and ultimately with the standard library's associative container insert function. This lead to updating SmallSet::insert to return pair<iterator, bool>, and then to update SmallPtrSet::insert to return pair<iterator, bool>, and then to update all the existing users of those functions... llvm-svn: 222334
* Remove StringMap::GetOrCreateValue in favor of StringMap::insertDavid Blaikie2014-11-191-5/+7
| | | | | | | | | | | | | | Having two ways to do this doesn't seem terribly helpful and consistently using the insert version (which we already has) seems like it'll make the code easier to understand to anyone working with standard data structures. (I also updated many references to the Entry's key and value to use first() and second instead of getKey{Data,Length,} and get/setValue - for similar consistency) Also removes the GetOrCreateValue functions so there's less surface area to StringMap to fix/improve/change/accommodate move semantics, etc. llvm-svn: 222319
* Use nullptr instead of NULL for variadic sentinelsReid Kleckner2014-11-131-2/+2
| | | | | | | | | | Windows defines NULL to 0, which when used as an argument to a variadic function, is not a null pointer constant. As a result, Clang's -Wsentinel fires on this code. Using '0' would be wrong on most 64-bit platforms, but both MSVC and Clang make it work on Windows. Sidestep the issue with nullptr. llvm-svn: 221940
* Simplify creation of a bunch of ArrayRefs by using None, makeArrayRef or ↵Craig Topper2014-08-271-1/+1
| | | | | | just letting them be implicitly created. llvm-svn: 216525
* InstCombine: sub nsw %x, C -> add nsw %x, -C if C isn't INT_MINDavid Majnemer2014-08-221-0/+23
| | | | | | We can preserve nsw during this transform if -C won't overflow. llvm-svn: 216269
* Repace SmallPtrSet with SmallPtrSetImpl in function arguments to avoid ↵Craig Topper2014-08-211-1/+1
| | | | | | needing to mention the size. llvm-svn: 216158
* IR: Fix ConstantExpr::replaceUsesOfWithOnConstant()Duncan P. N. Exon Smith2014-08-191-50/+13
| | | | | | | | | | | | | Change `ConstantExpr` to follow the model the other constants are using: only malloc a replacement if it's going to be used. This fixes a subtle bug where if an API user had used `ConstantExpr::get()` already to create the replacement but hadn't given it any users, we'd delete the replacement. This relies on r216015 to thread `OnlyIfReduced` through `ConstantExpr::getWithOperands()`. llvm-svn: 216016
* IR: Thread OnlyIfReduced through ConstantExpr::getWithOperands()Duncan P. N. Exon Smith2014-08-191-74/+136
| | | | | | | | | | | | | | In order to change `ConstantExpr::replaceUsesOfWithOnConstant()` to work like other constants (e.g., using `ConstantArray::getImpl()`), thread `OnlyIfReduced` through as necessary. When `OnlyIfReduced` is false, there's no functionality change. When it's true, if there's no constant folding or type changes `nullptr` is returned instead of the new constant. `ConstantExpr::replaceUsesOfWithOnConstant()` will be updated to use the "true" version in a follow-up commit. llvm-svn: 216015
* IR: De-duplicate code for replacing operands in placeDuncan P. N. Exon Smith2014-08-191-69/+11
| | | | | | | This is non-trivial and sits in three places. Move it to ConstantUniqueMap. llvm-svn: 216007
* Reapply r215966, r215965, r215964, r215963, r215960, r215959, r215958, and ↵Duncan P. N. Exon Smith2014-08-191-110/+179
| | | | | | | | | | | | r215957 This reverts commit r215981, which reverted the above commits because MSVC std::equal asserts on nullptr iterators, and thes commits introduced an `ArrayRef::equals()` on empty ArrayRefs. ArrayRef was changed not to use std::equal in r215986. llvm-svn: 215987
* Reverting r215966, r215965, r215964, r215963, r215960, r215959, r215958, and ↵Aaron Ballman2014-08-191-179/+110
| | | | | | r215957 (these commits all rely on previous commits) due to build breakage. These commits cause failed assertions when testing Clang using MSVC 2013. The asserts are triggered from the std::equal call within ArrayRef::equals due to being passed invalid input (ArrayRef.begin() is returning a nullptr which is problematic). llvm-svn: 215981
* IR: Reduce RAUW traffic in ConstantVectorDuncan P. N. Exon Smith2014-08-191-3/+27
| | | | | | | | | Avoid creating a new `ConstantVector` on an RAUW of one of its members. This reduces RAUW traffic on any containing constant. This is part of PR20515. llvm-svn: 215966
* IR: Fix ConstantArray::replaceUsesOfWithOnConstant()Duncan P. N. Exon Smith2014-08-191-0/+6
| | | | | | | | Previously, `ConstantArray::replaceUsesOfWithOnConstant()` neglected to check whether it becomes a `ConstantDataArray`. Call `ConstantArray::getImpl()` to check for that. llvm-svn: 215965
* IR: Factor out replaceUsesOfWithOnConstantImpl(), NFCDuncan P. N. Exon Smith2014-08-191-94/+80
| | | | | | | Factor out common code, and take advantage of the new function to add early returns to the callers. llvm-svn: 215964
* IR: Split up Constant{Array,Vector}::get(), NFCDuncan P. N. Exon Smith2014-08-191-4/+13
| | | | | | | | Introduce `getImpl()` that tries the simplification logic from `get()` and then gives up. This allows the logic to be reused elsewhere in a follow-up commit. llvm-svn: 215963
* IR: Reduce RAUW traffic in ConstantExprDuncan P. N. Exon Smith2014-08-191-0/+44
| | | | | | | | | | | | | Avoid RAUW-ing `ConstantExpr` when an operand changes unless the new `ConstantExpr` already has users. This prevents the RAUW from rippling up the expression tree unnecessarily. This commit indirectly adds test coverage for r215953 (this is how I came across the bug). This is part of PR20515. llvm-svn: 215960
* IR: Rewrite ConstantUniqueMapDuncan P. N. Exon Smith2014-08-191-12/+12
| | | | | | | | | | | | | | | | | | | | | Rewrite `ConstantUniqueMap` to be more similar to `ConstantAggrUniqueMap`. - Use a `DenseMap` with custom MapInfo instead of a `std::map` with linear lookups and deletion. - Don't waste memory explicitly storing (heavyweight) keys. Only `ConstantExpr` and `InlineAsm` actually use this data structure, so I also updated them to use it. This code cleanup is a precursor to reducing RAUW traffic on `ConstantExpr` -- I felt badly adding a new (linear) call to `ConstantUniqueMap::FindExistingKey`, so this designs away the concern. A follow-up commit will transition the users of `ConstantAggrUniqueMap` over. llvm-svn: 215957
* IR: Declare LookupKey right before its use, NFCDuncan P. N. Exon Smith2014-08-191-6/+4
| | | | llvm-svn: 215956
* Revert "Repace SmallPtrSet with SmallPtrSetImpl in function arguments to ↵Craig Topper2014-08-181-1/+1
| | | | | | | | avoid needing to mention the size." Getting a weird buildbot failure that I need to investigate. llvm-svn: 215870
* Repace SmallPtrSet with SmallPtrSetImpl in function arguments to avoid ↵Craig Topper2014-08-171-1/+1
| | | | | | needing to mention the size. llvm-svn: 215868
* InstCombine: Fix a potential bug in 0 - (X sdiv C) -> (X sdiv -C)David Majnemer2014-08-161-0/+22
| | | | | | | | | | | | | | | While *most* (X sdiv 1) operations will get caught by InstSimplify, it is still possible for a sdiv to appear in the worklist which hasn't been simplified yet. This means that it is possible for 0 - (X sdiv 1) to get transformed into (X sdiv -1); dividing by -1 can make the transform produce undef values instead of the proper result. Sorry for the lack of testcase, it's a bit problematic because it relies on the exact order of operations in the worklist. llvm-svn: 215818
* InstCombine: Don't turn -(x/INT_MIN) -> x/INT_MINDavid Majnemer2014-07-021-0/+22
| | | | | | | | | It is not safe to negate the smallest signed integer, doing so yields the same number back. This fixes PR20186. llvm-svn: 212164
* Don't build switch lookup tables for dllimport or TLS variablesHans Wennborg2014-06-201-20/+33
| | | | | | | | | | | | | We would previously put dllimport variables in switch lookup tables, which doesn't work because the address cannot be used in a constant initializer. This is basically the same problem that we have in PR19955. Putting TLS variables in switch tables also desn't work, because the address of such a variable is not constant. Differential Revision: http://reviews.llvm.org/D4220 llvm-svn: 211331
* Canonicalize addrspacecast ConstExpr between different pointer typesJingyue Wu2014-06-151-0/+13
| | | | | | | | | | | | | | | | | | As a follow-up to r210375 which canonicalizes addrspacecast instructions, this patch canonicalizes addrspacecast constant expressions. Given clang uses ConstantExpr::getAddrSpaceCast to emit addrspacecast cosntant expressions, this patch is also a step towards having the frontend emit canonicalized addrspacecasts. Piggyback a minor refactor in InstCombineCasts.cpp Update three affected tests in addrspacecast-alias.ll, access-non-generic.ll and constant-fold-gep.ll and added one new test in constant-fold-address-space-pointer.ll llvm-svn: 211004
* [IR] Make {extract,insert}element accept an index of any integer type.Michael J. Spencer2014-05-011-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Given the following C code llvm currently generates suboptimal code for x86-64: __m128 bss4( const __m128 *ptr, size_t i, size_t j ) { float f = ptr[i][j]; return (__m128) { f, f, f, f }; } ================================================= define <4 x float> @_Z4bss4PKDv4_fmm(<4 x float>* nocapture readonly %ptr, i64 %i, i64 %j) #0 { %a1 = getelementptr inbounds <4 x float>* %ptr, i64 %i %a2 = load <4 x float>* %a1, align 16, !tbaa !1 %a3 = trunc i64 %j to i32 %a4 = extractelement <4 x float> %a2, i32 %a3 %a5 = insertelement <4 x float> undef, float %a4, i32 0 %a6 = insertelement <4 x float> %a5, float %a4, i32 1 %a7 = insertelement <4 x float> %a6, float %a4, i32 2 %a8 = insertelement <4 x float> %a7, float %a4, i32 3 ret <4 x float> %a8 } ================================================= shlq $4, %rsi addq %rdi, %rsi movslq %edx, %rax vbroadcastss (%rsi,%rax,4), %xmm0 retq ================================================= The movslq is uneeded, but is present because of the trunc to i32 and then sext back to i64 that the backend adds for vbroadcastss. We can't remove it because it changes the meaning. The IR that clang generates is already suboptimal. What clang really should emit is: %a4 = extractelement <4 x float> %a2, i64 %j This patch makes that legal. A separate patch will teach clang to do it. Differential Revision: http://reviews.llvm.org/D3519 llvm-svn: 207801
* Remove more default address space argument usage.Matt Arsenault2014-04-231-1/+1
| | | | | | These places are inconsequential in practice. llvm-svn: 207021
* [C++11] More 'nullptr' conversion. In some cases just using a boolean check ↵Craig Topper2014-04-151-2/+2
| | | | | | instead of comparing to nullptr. llvm-svn: 206252
* [C++11] More 'nullptr' conversion or in some cases just using a boolean ↵Craig Topper2014-04-091-26/+27
| | | | | | check instead of comparing to nullptr. llvm-svn: 205831
* [C++11] Add range based accessors for the Use-Def chain of a Value.Chandler Carruth2014-03-091-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This requires a number of steps. 1) Move value_use_iterator into the Value class as an implementation detail 2) Change it to actually be a *Use* iterator rather than a *User* iterator. 3) Add an adaptor which is a User iterator that always looks through the Use to the User. 4) Wrap these in Value::use_iterator and Value::user_iterator typedefs. 5) Add the range adaptors as Value::uses() and Value::users(). 6) Update *all* of the callers to correctly distinguish between whether they wanted a use_iterator (and to explicitly dig out the User when needed), or a user_iterator which makes the Use itself totally opaque. Because #6 requires churning essentially everything that walked the Use-Def chains, I went ahead and added all of the range adaptors and switched them to range-based loops where appropriate. Also because the renaming requires at least churning every line of code, it didn't make any sense to split these up into multiple commits -- all of which would touch all of the same lies of code. The result is still not quite optimal. The Value::use_iterator is a nice regular iterator, but Value::user_iterator is an iterator over User*s rather than over the User objects themselves. As a consequence, it fits a bit awkwardly into the range-based world and it has the weird extra-dereferencing 'operator->' that so many of our iterators have. I think this could be fixed by providing something which transforms a range of T&s into a range of T*s, but that *can* be separated into another patch, and it isn't yet 100% clear whether this is the right move. However, this change gets us most of the benefit and cleans up a substantial amount of code around Use and User. =] llvm-svn: 203364
* [Modules] Move GetElementPtrTypeIterator into the IR library. As itsChandler Carruth2014-03-041-1/+1
| | | | | | | | | name might indicate, it is an iterator over the types in an instruction in the IR.... You see where this is going. Another step of modularizing the support library. llvm-svn: 202815
* [C++11] Replace llvm::next and llvm::prior with std::next and std::prev.Benjamin Kramer2014-03-021-1/+1
| | | | | | Remove the old functions. llvm-svn: 202636
* Add a const lookup routine to get a BlockAddress constant if there isChandler Carruth2014-01-191-0/+11
| | | | | | | | one, but not create one. This is useful in the verifier when we want to query the constant if it exists but not create one. To be used in an upcoming commit. llvm-svn: 199568
* Support AddrSpaceCast in ConstantExpr::getAsInstruction.Eli Bendersky2014-01-181-0/+1
| | | | | | | It's handled similarly to the other casts. CastInst::Create already knows how to handle it. llvm-svn: 199565
* Upgrade ConstantFP's negative zero and infinity getters to handle vector types.Benjamin Kramer2014-01-181-16/+18
| | | | | | Will be used soon. llvm-svn: 199552
* Add getBitCastOrAddrSpaceCastMatt Arsenault2013-12-071-1/+12
| | | | llvm-svn: 196637
* Add addrspacecast instruction.Matt Arsenault2013-11-151-0/+14
| | | | | | Patch by Michele Scandale! llvm-svn: 194760
* Don't assert if we can't constant fold extract/insertvalueHal Finkel2013-07-101-8/+21
| | | | | | | | | | | | | | | A non-constant-foldable static initializer expression containing insertvalue or extractvalue had been causing an assert: Constants.cpp:1971: Assertion `FC && "ExtractValue constant expr couldn't be folded!"' failed. Now we report a more-sensible "Unsupported expression in static initializer" error instead. Fixes PR15417. llvm-svn: 186044
* Fix DeleteDeadVarargs not to crash on functions referenced by BlockAddressesDerek Schuff2013-06-131-1/+1
| | | | | | | | | | | | | | | This pass was assuming that if hasAddressTaken() returns false for a function, the function's only uses are call sites. That's not true because there can be references by BlockAddresses too. Fix the pass to handle this case. Fix BlockAddress::replaceUsesOfWithOnConstant() to allow a function's type to be changed by RAUW'ing the function with a bitcast of the recreated function. Patch by Mark Seaborn. llvm-svn: 183933
* Move object construction into [] so the temporary can be moved.Benjamin Kramer2013-06-011-5/+3
| | | | | | No functionality change. llvm-svn: 183075
* Fix a scalability issue with complex ConstantExprs.Benjamin Kramer2013-04-131-9/+19
| | | | | | | | | | | | | | | This is basically the same fix in three different places. We use a set to avoid walking the whole tree of a big ConstantExprs multiple times. For example: (select cmp, (add big_expr 1), (add big_expr 2)) We don't want to visit big_expr twice here, it may consist of thousands of nodes. The testcase exercises this by creating an insanely large ConstantExprs out of a loop. It's questionable if the optimizer should ever create those, but this can be triggered with real C code. Fixes PR15714. llvm-svn: 179458
* The testing to ensure a vector of zeros of type floating point isn't ↵David Tweed2013-03-191-6/+3
| | | | | | misclassified as negative zero can be simplified, as pointed out by Duncan Sands. llvm-svn: 177386
* The optimization a + (-0.0f) -> a was being misapplied to a + (+0.0f) in ↵David Tweed2013-03-181-0/+13
| | | | | | | | | | the vector case (because we weren't differntiating floating-point zeroinitializers from other zero-initializers) which was causing problems for code relying upon a + (+0.0f) to, eg, flush denormals to 0. Make the scalar and vector cases have the same behaviour. llvm-svn: 177279
* Replace temporary vectors with arrays.Benjamin Kramer2013-03-071-24/+12
| | | | llvm-svn: 176651
OpenPOWER on IntegriCloud