summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Constants.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [IR] fix potential crash in Constant::isElementWiseEqual()Sanjay Patel2020-01-141-4/+9
| | | | | | | | | | | | There's only one user of this API currently, and it seems impossible that it would compare values with different types. But that's not true in general, so we need to make sure the types are the same. As denoted by the FIXME comments, we will also crash on FP values. That's what brought me here, but we can make that a follow-up patch.
* [IR] allow undefined elements when checking for splat constantsSanjay Patel2019-12-101-5/+22
| | | | | This mimics the related call in SDAG. The caller is responsible for ensuring that undef values are propagated safely.
* [ConstantFold][SVE] Fix constant folding for shufflevector.Eli Friedman2019-12-091-1/+1
| | | | | | | Don't try to fold away shuffles which can't be folded. Fix creation of shufflevector constant expressions. Differential Revision: https://reviews.llvm.org/D71147
* [InstCombine] Extend `0 - (X sdiv C) -> (X sdiv -C)` fold to non-splat vectorsRoman Lebedev2019-12-051-0/+24
| | | | Split off from https://reviews.llvm.org/D68408
* Mark llvm::ConstantExpr::getAsInstruction as constAlex Denisov2019-11-121-1/+1
| | | | | | | | | | | | | | | | Summary: getAsInstruction is the only non-const member method. It is impossible to enforce const-correctness because of it. Reviewers: jmolloy, majnemer Reviewed By: jmolloy Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D70113
* [IR] adjust assert when replacing undef elements in vector constantSanjay Patel2019-11-041-1/+1
| | | | | | | | | | As noted in follow-up to: rGa1e8ad4f2fa7 It's not safe to assume that an element of the constant is always non-null. It's definitely not an expected case for the current instcombine user, but that may not hold if this function is eventually called from arbitrary places.
* [IR] move/change null-check to assertSanjay Patel2019-10-291-1/+2
| | | | | | | This should trigger a dereference before null-check warning, but I don't see it when building with clang. In any case, the current and known future users of this helper require non-null args, so I'm converting the 'if' to an assert.
* [IR] move helper function to replace undef constant (elements) with fixed ↵Sanjay Patel2019-10-291-4/+25
| | | | | | | | constants This is the NFC part of D69519. We had this functionality locally in instcombine, but it can be used elsewhere, so hoisting it to Constant class.
* [Constant] Add 'isElementWiseEqual()' methodRoman Lebedev2019-08-241-0/+15
| | | | | | | | | | | Promoting it from InstCombine's tryToReuseConstantFromSelectInComparison(). Return true if this constant and a constant 'Y' are element-wise equal. This is identical to just comparing the pointers, with the exception that for vectors, if only one of the constants has an `undef` element in some lane, the constants still match. llvm-svn: 369842
* IR. Change strip* family of functions to not look through aliases.Peter Collingbourne2019-08-221-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | I noticed another instance of the issue where references to aliases were being replaced with aliasees, this time in InstCombine. In the instance that I saw it turned out to be only a QoI issue (a symbol ended up being missing from the symbol table due to the last reference to the alias being removed, preventing HWASAN from symbolizing a global reference), but it could easily have manifested as incorrect behaviour. Since this is the third such issue encountered (previously: D65118, D65314) it seems to be time to address this common error/QoI issue once and for all and make the strip* family of functions not look through aliases. Includes a test for the specific issue that I saw, but no doubt there are other similar bugs fixed here. As with D65118 this has been tested to make sure that the optimization isn't load bearing. I built Clang, Chromium for Linux, Android and Windows as well as the test-suite and there were no size regressions. Differential Revision: https://reviews.llvm.org/D66606 llvm-svn: 369697
* [IR] Simplify removeDeadConstantUsers. NFCFangrui Song2019-08-141-6/+3
| | | | llvm-svn: 368833
* Fix typo in r366494. Spotted by Yuanfang Chen.Peter Collingbourne2019-07-181-1/+1
| | | | llvm-svn: 366497
* IR: Teach Constant::needsRelocation() that relative pointers don't need to ↵Peter Collingbourne2019-07-181-11/+23
| | | | | | | | | | | be relocated. This causes sections with relative pointers to be marked as read only, which means that they won't end up sharing pages with writable data. Differential Revision: https://reviews.llvm.org/D64948 llvm-svn: 366494
* [Constants] Simplify type checking switch in ConstantExpr::get.Craig Topper2019-05-051-26/+6
| | | | | | | | | | | | | | | | | | | | | | Summary: Remove duplicate checks that both operands have the same type. This is checked before the switch. Use 'integer' or 'floating-point' instead of 'arithmetic' type. I think this might be a leftover to the days when floating point and integer operations shared the same opcodes. Reviewers: spatel, RKSimon, dblaikie Reviewed By: RKSimon Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D61558 llvm-svn: 359985
* Add FNeg IR constant folding supportCameron McInally2019-05-051-4/+6
| | | | llvm-svn: 359982
* Change some StringRef::data() reinterpret_cast to bytes_begin() or ↵Fangrui Song2019-04-071-1/+1
| | | | | | arrayRefFromStringRef() llvm-svn: 357852
* [InstCombine] canonicalize funnel shift constant shift amount to be modulo ↵Sanjay Patel2019-03-141-0/+10
| | | | | | | | | | | | | | | bitwidth The shift argument is defined to be modulo the bitwidth, so if that argument is a constant, we can always reduce the constant to its minimal form to allow better CSE and other follow-on transforms. We need to be careful to ignore constant expressions here, or we will likely infinite loop. I'm adding a general vector constant query for that case. Differential Revision: https://reviews.llvm.org/D59374 llvm-svn: 356192
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [opaque pointer types] Remove some calls to generic Type subtype accessors.James Y Knight2019-01-101-3/+2
| | | | | | | | | | | | That is, remove many of the calls to Type::getNumContainedTypes(), Type::subtypes(), and Type::getContainedType(N). I'm not intending to remove these accessors -- they are useful/necessary in some cases. However, removing the pointee type from pointers would potentially break some uses, and reducing the number of calls makes it easier to audit. llvm-svn: 350835
* [ConstantInt] Check active bits before calling getZExtValue.Florian Hahn2018-12-121-1/+5
| | | | | | | | | | | | | | | | | | Without this check, we hit an assertion in getZExtValue, if the constant value does not fit into an uint64_t. As getZExtValue returns an uint64_t, should we update getAggregateElement to take an uin64_t as well? This fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=6109. Reviewers: efriedma, craig.topper, spatel Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D55547 llvm-svn: 348906
* APFloat: allow 64-bit of payloadJF Bastien2018-12-101-2/+24
| | | | | | | | | | | | | | | | | | | | Summary: The APFloat and Constant APIs taking an APInt allow arbitrary payloads, and that's great. There's a convenience API which takes an unsigned, and that's silly because it then directly creates a 64-bit APInt. Just change it to 64-bits directly. At the same time, add ConstantFP NaN getters which match the APFloat ones (with getQNaN / getSNaN and APInt parameters). Improve the APFloat testing to set more payload bits. Reviewers: scanon, rjmccall Subscribers: jkorous, dexonsmith, kristina, llvm-commits Differential Revision: https://reviews.llvm.org/D55460 llvm-svn: 348791
* [InstCombine] Support ssub.sat canonicalization for non-splatsNikita Popov2018-12-011-11/+8
| | | | | | | | | | | | Extend ssub.sat(X, C) -> sadd.sat(X, -C) canonicalization to also support non-splat vector constants. This is done by generalizing the implementation of the isNotMinSignedValue() helper to return true for constants that are non-splat, but don't contain any signed min elements. Differential Revision: https://reviews.llvm.org/D55011 llvm-svn: 348072
* Use llvm::copy. NFCFangrui Song2018-11-171-1/+1
| | | | llvm-svn: 347126
* [IR] Add a dedicated FNeg IR InstructionCameron McInally2018-11-131-0/+30
| | | | | | | | | | | The IEEE-754 Standard makes it clear that fneg(x) and fsub(-0.0, x) are two different operations. The former is a bitwise operation, while the latter is an arithmetic operation. This patch creates a dedicated FNeg IR Instruction to model that behavior. Differential Revision: https://reviews.llvm.org/D53877 llvm-svn: 346774
* [Constants] extend getBinOpIdentity(); NFCSanjay Patel2018-07-061-24/+41
| | | | | | | | The enhanced version will be used in D48893 and related patches and an almost identical (fadd is different) version is proposed in D28907, so adding this as a preliminary step. llvm-svn: 336444
* [Constant] add undef element query for vector constants; NFCSanjay Patel2018-07-061-0/+10
| | | | | | | This is likely to be used in D48987 and similar patches, so adding it as an NFC preliminary step. llvm-svn: 336442
* [Constants] add identity constants for fadd/fmulSanjay Patel2018-07-031-1/+6
| | | | | | | | | | | | | | | | As the test diffs show, the current users of getBinOpIdentity() are InstCombine and Reassociate. SLP vectorizer is a candidate for using this functionality too (D28907). The InstCombine shuffle improvements are part of the planned enhancements noted in D48830. InstCombine actually has several other uses of getBinOpIdentity() via SimplifyUsingDistributiveLaws(), but we don't call that for any FP ops. Fixing that might be another part of removing the custom reassociation in InstCombine that is only done for fadd+fmul. llvm-svn: 336215
* [InstCombine] fold shuffle-with-binop and common valueSanjay Patel2018-07-031-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | This is the last significant change suggested in PR37806: https://bugs.llvm.org/show_bug.cgi?id=37806#c5 ...though there are several follow-ups noted in the code comments in this patch to complete this transform. It's possible that a binop feeding a select-shuffle has been eliminated by earlier transforms (or the code was just written like this in the 1st place), so we'll fail to match the patterns that have 2 binops from: D48401, D48678, D48662, D48485. In that case, we can try to materialize identity constants for the remaining binop to fill in the "ghost" lanes of the vector (where we just want to pass through the original values of the source operand). I added comments to ConstantExpr::getBinOpIdentity() to show planned follow-ups. For now, we only handle the 5 commutative integer binops (add/mul/and/or/xor). Differential Revision: https://reviews.llvm.org/D48830 llvm-svn: 336196
* [IR] Strip trailing whitespace. NFCBjorn Pettersson2018-07-031-13/+13
| | | | llvm-svn: 336194
* [IR] Use Instruction::isBinaryOp helper instead of raw enum range tests. NFCI.Simon Pilgrim2018-06-221-2/+1
| | | | llvm-svn: 335335
* Make ConstantDataArray::get constructor templated. Will support signed integers.Alina Sbirlea2018-03-191-34/+0
| | | | | | | | | | | | Summary: Make ConstantDataArray::get() constructors a single templated one. Reviewers: timshen, rsmith Subscribers: sanjoy, llvm-commits, jlebar Differential Revision: https://reviews.llvm.org/D44337 llvm-svn: 327894
* [PatternMatch, InstSimplify] fix m_NaN to work with vector constants and use itSanjay Patel2018-03-021-0/+13
| | | | | | | | | This is NFC for the moment (and independent of any potential NaN semantic controversy). Besides making the code in InstSimplify easier to read, the motivation is to eventually allow undef elements in vector constants to match too. A proposal to add the base logic for that is in D43792. llvm-svn: 326600
* [InstCombine] fold fdiv with non-splat divisor to fmul: X/C --> X * (1/C)Sanjay Patel2018-02-201-0/+13
| | | | llvm-svn: 325590
* [Constant] add floating-point helpers for normal/finite-nz; NFCSanjay Patel2018-02-161-0/+26
| | | | | | | | | ...and delete the equivalent local functiona from InstCombine. These might be useful to other InstCombine files or other passes and makes FP queries more similar to integer constant queries. llvm-svn: 325398
* [InstCombine] allow X / C -> X * (1.0/C) for vector splat FP constantsSanjay Patel2018-02-151-0/+11
| | | | llvm-svn: 325237
* Remove redundant includes from lib/IR.Michael Zolotukhin2017-12-131-1/+0
| | | | llvm-svn: 320622
* [IR] Implement ↵Craig Topper2017-07-151-19/+67
| | | | | | | | | | | | | | | | | | | Constant::isNegativeZeroValue/isZeroValue/isAllOnesValue/isOneValue/isMinSignedValue for ConstantDataVector without going through getElementAsConstant Summary: Currently these methods call ConstantDataVector::getSplatValue which uses getElementsAsConstant to create a Constant object representing the element value. This method incurs a map lookup to see if we already have created such a Constant before and if not allocates a new Constant object. This patch changes these methods to use getElementAsAPFloat and getElementAsInteger so we can just examine the data values directly. Reviewers: spatel, pcc, dexonsmith, bogner, craig.topper Reviewed By: craig.topper Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D35040 llvm-svn: 308112
* [IR] Remove unnecessary const_casts from ConstantDataSequential and it's ↵Craig Topper2017-07-111-29/+25
| | | | | | subclasses. llvm-svn: 307666
* [IR] Add Type::isIntOrIntVectorTy(unsigned) similar to the existing ↵Craig Topper2017-07-091-2/+2
| | | | | | isIntegerTy(unsigned), but also works for vectors. llvm-svn: 307492
* [IR] Make use of ↵Craig Topper2017-07-091-4/+4
| | | | | | Type::isPtrOrPtrVectorTy/isIntOrIntVectorTy/isFPOrFPVectorTy to shorten code. NFC llvm-svn: 307491
* [IR] Use CmpInst::isFPPredicate/isIntPredicate in a few other places. NFCCraig Topper2017-07-051-3/+4
| | | | llvm-svn: 307224
* [Constants] Fix copy-pasto in llvm_unreachable message. NFCCraig Topper2017-06-271-1/+1
| | | | llvm-svn: 306456
* [Constants] Use isUIntN/isIntN from MathExtras instead of reimplementing the ↵Craig Topper2017-06-071-9/+2
| | | | | | same code. NFC llvm-svn: 304856
* [Constants] Use APInt::isNullValue/isOneValue/uge to simplify some code and ↵Craig Topper2017-06-071-1/+1
| | | | | | take advantage of APInt optimizations. NFC llvm-svn: 304855
* SimplifyLibCalls: Optimize wcslenMatthias Braun2017-05-191-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Refactor the strlen optimization code to work for both strlen and wcslen. This especially helps with programs in the wild where people pass L"string"s to const std::wstring& function parameters and the wstring constructor gets inlined. This also fixes a lingerind API problem/bug in getConstantStringInfo() where zeroinitializers would always give you an empty string (without a length) back regardless of the actual length of the initializer which did not work well in the TrimAtNul==false causing the PR mentioned below. Note that the fixed getConstantStringInfo() needed fixes to SelectionDAG memcpy lowering and may lead to some cases for out-of-bounds zeroinitializer accesses not getting optimized anymore. So some code with UB may produce out of bound memory reads now instead of just producing zeros. The refactoring "accidentally" fixes http://llvm.org/PR32124 Differential Revision: https://reviews.llvm.org/D32839 llvm-svn: 303461
* [IR] De-virtualize ~Value to save a vptrReid Kleckner2017-05-181-11/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Implements PR889 Removing the virtual table pointer from Value saves 1% of RSS when doing LTO of llc on Linux. The impact on time was positive, but too noisy to conclusively say that performance improved. Here is a link to the spreadsheet with the original data: https://docs.google.com/spreadsheets/d/1F4FHir0qYnV0MEp2sYYp_BuvnJgWlWPhWOwZ6LbW7W4/edit?usp=sharing This change makes it invalid to directly delete a Value, User, or Instruction pointer. Instead, such code can be rewritten to a null check and a call Value::deleteValue(). Value objects tend to have their lifetimes managed through iplist, so for the most part, this isn't a big deal. However, there are some places where LLVM deletes values, and those places had to be migrated to deleteValue. I have also created llvm::unique_value, which has a custom deleter, so it can be used in place of std::unique_ptr<Value>. I had to add the "DerivedUser" Deleter escape hatch for MemorySSA, which derives from User outside of lib/IR. Code in IR cannot include MemorySSA headers or call the MemoryAccess object destructors without introducing a circular dependency, so we need some level of indirection. Unfortunately, no class derived from User may have any virtual methods, because adding a virtual method would break User::getHungOffOperands(), which assumes that it can find the use list immediately prior to the User object. I've added a static_assert to the appropriate OperandTraits templates to help people avoid this trap. Reviewers: chandlerc, mehdi_amini, pete, dberlin, george.burgess.iv Reviewed By: chandlerc Subscribers: krytarowski, eraman, george.burgess.iv, mzolotukhin, Prazek, nlewycky, hans, inglorion, pcc, tejohnson, dberlin, llvm-commits Differential Revision: https://reviews.llvm.org/D31261 llvm-svn: 303362
* Suppress all uses of LLVM_END_WITH_NULL. NFC.Serge Guelton2017-05-091-13/+2
| | | | | | | | | Use variadic templates instead of relying on <cstdarg> + sentinel. This enforces better type checking and makes code more readable. Differential Revision: https://reviews.llvm.org/D32541 llvm-svn: 302571
* [Constants] simplify get true/false code; NFCISanjay Patel2017-04-161-18/+10
| | | | llvm-svn: 300424
* [IR] Fix a typo in a comment. NFCCraig Topper2017-04-111-1/+1
| | | | llvm-svn: 299918
* Replace APFloatBase static fltSemantics data members with getter functionsStephan Bergmann2016-12-141-41/+41
| | | | | | | | | | | | | At least the plugin used by the LibreOffice build (<https://wiki.documentfoundation.org/Development/Clang_plugins>) indirectly uses those members (through inline functions in LLVM/Clang include files in turn using them), but they are not exported by utils/extract_symbols.py on Windows, and accessing data across DLL/EXE boundaries on Windows is generally problematic. Differential Revision: https://reviews.llvm.org/D26671 llvm-svn: 289647
OpenPOWER on IntegriCloud