aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/ConstantsTest.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-05-27IR: Make Module::getOrInsertGlobal() return a GlobalVariable.Peter Collingbourne1-2/+2
After pointer element types were removed this function can only return a GlobalVariable, so reflect that in the type and comments and clean up callers. Reviewers: nikic Reviewed By: nikic Pull Request: https://github.com/llvm/llvm-project/pull/141323
2025-05-08Reapply "IR: Remove reference counts from ConstantData (#137314)" (#138962)Matt Arsenault1-0/+38
This reverts commit 0274232b87177779e5c985eca06df22bf140f6cb.
2025-05-07Revert "IR: Remove reference counts from ConstantData (#137314)"Kirill Stoimenov1-38/+0
This reverts commit 51a3bd919d68a8fb1b026377d6e86b1523d37433. Possible breaks the build: https://lab.llvm.org/buildbot/#/builders/24/builds/8119/steps/9/logs/stdio
2025-05-06IR: Remove reference counts from ConstantData (#137314)Matt Arsenault1-0/+38
This is a follow up change to eliminating uselists for ConstantData. In the previous revision, ConstantData had a replacement reference count instead of a uselist. This reference count was misleading, and not useful in the same way as it would be for another value. The references may not have even been in the current module, since these are shared throughout the LLVMContext. This doesn't space leak any more than we previously did; nothing was attempting to garbage collect unused constants. Previously the use_empty, and hasNUses type of APIs were supported through the reference count. These now behave as if the uses are always empty. Ideally it would be illegal to inspect these, but this forces API complexity into quite a few places. It may be doable to make it illegal to check these counts, but I would like there to be a targeted fuzzing effort to make sure every transform properly deals with a constant in every operand position. All tests pass if I turn the hasNUses* and getNumUses queries into assertions, only hasOneUse in particular appears to hit in some set of contexts. I've added unit tests to ensure logical consistency between these cases
2025-02-14[IR] Remove mul constant expression (#127046)Nikita Popov1-2/+1
Remove support for the mul constant expression, which has previously already been marked as undesirable. This removes the APIs to create mul expressions and updates tests to stop using mul expressions. Part of: https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179
2025-01-22[IR][unittests] Replace of PointerType::getUnqual(Type) with opaque version ↵Mats Jun Larsen1-5/+5
(NFC) (#123901) Follow up to https://github.com/llvm/llvm-project/issues/123569
2025-01-21[IR][unittests] Replace of PointerType::get(Type) with opaque version (NFC) ↵Mats Jun Larsen1-3/+3
(#123621) In accordance with https://github.com/llvm/llvm-project/issues/123569
2024-09-13[llvm][unittests] Don't call raw_string_ostream::flush() (NFC)JOE19941-1/+0
raw_string_ostream::flush() is essentially a no-op (also specified in docs). Don't call it in tests that aren't meant to test 'raw_string_ostream' itself. p.s. remove a few redundant calls to raw_string_ostream::str()
2024-06-20[IR] Remove support for shl constant expressions (#96037)Nikita Popov1-6/+2
Remove support for shl constant expressions, as part of: https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179
2024-06-04[IR] Remove support for icmp and fcmp constant expressions (#93038)Nikita Popov1-3/+0
Remove support for the icmp and fcmp constant expressions. This is part of: https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179 As usual, many of the updated tests will no longer test what they were originally intended to -- this is hard to preserve when constant expressions get removed, and in many cases just impossible as the existence of a specific kind of constant expression was the cause of the issue in the first place.
2024-04-17[PatternMatch] Do not accept undef elements in m_AllOnes() and friends (#88217)Nikita Popov1-6/+33
Change all the cstval_pred_ty based PatternMatch helpers (things like m_AllOnes and m_Zero) to only allow poison elements inside vector splats, not undef elements. Historically, we used to represent non-demanded elements in vectors using undef. Nowadays, we use poison instead. As such, I believe that support for undef in vector splats is no longer useful. At the same time, while poison splat elements are pretty much always safe to ignore, this is not generally the case for undef elements. We have existing miscompiles in our tests due to this (see the masked-merge-*.ll tests changed here) and it's easy to miss such cases in the future, now that we write tests using poison instead of undef elements. I think overall, keeping support for undef elements no longer makes sense, and we should drop it. Once this is done consistently, I think we may also consider allowing poison in m_APInt by default, as doing that change is much less risky than doing the same with undef. This change involves a substantial amount of test changes. For most tests, I've just replaced undef with poison, as I don't think there is value in retaining both. For some tests (where the distinction between undef and poison is important), I've duplicated tests.
2024-02-12[C API] Add blockaddress getters to C API (#81382)Benji Smith1-0/+39
This allows for accessing the function/basic block that a blockaddress constant refers to Due to the difficulties of fully supporting cloning BlockAddress values in echo.cpp, tests are instead done using a unit test. This previously was up for review at https://github.com/llvm/llvm-project/pull/77390.
2023-11-14[IR] Remove support for lshr/ashr constant expressions (#71955)Nikita Popov1-14/+0
Remove support for the lshr and ashr constant expressions. All places creating them have been removed beforehand, so this just removes the APIs and uses of these constant expressions in tests. This is part of https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179.
2023-11-07[IR] Remove FP cast constant expressions (#71408)Nikita Popov1-25/+0
Remove support for the fptrunc, fpext, fptoui, fptosi, uitofp and sitofp constant expressions. All places creating them have been removed beforehand, so this just removes the APIs and uses of these constant expressions in tests. With this, the only remaining FP operation that still has constant expression support is fcmp. This is part of https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179.
2023-11-03[IR] Remove zext and sext constant expressions (#71040)Nikita Popov1-2/+0
Remove support for zext and sext constant expressions. All places creating them have been removed beforehand, so this just removes the APIs and uses of these constant expressions in tests. There is some additional cleanup that can be done on top of this, e.g. we can remove the ZExtInst vs ZExtOperator footgun. This is part of https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179.
2023-08-22[IR] Remove support for and/or constant expressionsNikita Popov1-6/+5
As part of https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179, this removes support for and and or constant expressions. Places creating such expressions have been migrated in advance, so this is mostly API removal and test updates. Differential Revision: https://reviews.llvm.org/D155924
2023-08-02Stop using legacy helpers indicating typed pointer types. NFCBjorn Pettersson1-38/+32
Since we no longer support typed LLVM IR pointer types, the code can be simplified into for example using PointerType::get directly instead of using Type::getInt8PtrTy and Type::getInt32PtrTy etc. Differential Revision: https://reviews.llvm.org/D156733
2023-07-12[IR] Remove unit tests for typed pointers (NFC)Nikita Popov1-13/+3
2023-03-16[ConstantsTest] Fix unused variable warning (NFC)Nikita Popov1-2/+0
2023-03-16[ConstExpr] Remove select constant expressionNikita Popov1-2/+0
This removes the select constant expression, as part of https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179. Uses of this expressions have already been removed in advance, so this just removes related infrastructure and updates tests. Differential Revision: https://reviews.llvm.org/D145382
2022-12-02[llvm/unittests] Use std::nullopt instead of None (NFC)Kazu Hirata1-1/+1
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-09-08[ConstantExpr] Remove fneg expressionNikita Popov1-1/+0
As part of https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179, this removes the fneg constant expression (which is, incidentally, the only unary operator expression). Differential Revision: https://reviews.llvm.org/D133418
2022-07-12[IR] Remove support for float binop constant expressionsNikita Popov1-5/+0
As part of https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179, this removes support for the floating-point binop constant expressions fadd, fsub, fmul, fdiv and frem. As part of this change, the C APIs LLVMConstFAdd, LLVMConstFSub, LLVMConstFMul, LLVMConstFDiv and LLVMConstFRem are removed. The LLVMBuild APIs should be used instead. Differential Revision: https://reviews.llvm.org/D129478
2022-07-06[ConstExpr] Remove div/rem constant expressionsNikita Popov1-16/+9
D128820 stopped creating div/rem constant expressions by default; this patch removes support for them entirely. The getUDiv(), getExactUDiv(), getSDiv(), getExactSDiv(), getURem() and getSRem() on ConstantExpr are removed, and ConstantExpr::get() now only accepts binary operators for which ConstantExpr::isSupportedBinOp() returns true. Uses of these methods may be replaced either by corresponding IRBuilder methods, or ConstantFoldBinaryOpOperands (if a constant result is required). On the C API side, LLVMConstUDiv, LLVMConstExactUDiv, LLVMConstSDiv, LLVMConstExactSDiv, LLVMConstURem and LLVMConstSRem are removed and corresponding LLVMBuild methods should be used. Importantly, this also means that constant expressions can no longer trap! This patch still keeps the canTrap() method to minimize diff -- I plan to drop it in a separate NFC patch. Differential Revision: https://reviews.llvm.org/D129148
2022-06-02[IR] Enable opaque pointers by defaultNikita Popov1-8/+8
This enabled opaque pointers by default in LLVM. The effect of this is twofold: * If IR that contains *neither* explicit ptr nor %T* types is passed to tools, we will now use opaque pointer mode, unless -opaque-pointers=0 has been explicitly passed. * Users of LLVM as a library will now default to opaque pointers. It is possible to opt-out by calling setOpaquePointers(false) on LLVMContext. A cmake option to toggle this default will not be provided. Frontends or other tools that want to (temporarily) keep using typed pointers should disable opaque pointers via LLVMContext. Differential Revision: https://reviews.llvm.org/D126689
2022-05-25[LLVM][IR] Fix assert in ConstantExpr::getPtrToInt so all vector types are ↵Paul Walker1-0/+15
supported. Fixes: #55410
2022-04-05[LLVMContext] Replace enableOpaquePointers() with setOpaquePointers()Nikita Popov1-2/+1
This allows both explicitly enabling and explicitly disabling opaque pointers, in anticipation of the default switching at some point. This also slightly changes the rules by allowing calls if either the opaque pointer mode has not yet been set (explicitly or implicitly) or if the value remains unchanged.
2022-02-11[RGT] Exercise both paths through a testPaul Robinson1-1/+8
BitcastToGEP had an opaque/typed pointer decision point, make sure it exercises both sides. Found by the Rotten Green Tests project.
2022-01-06[IR] Track users of comdatsNikita Popov1-0/+27
Track all GlobalObjects that reference a given comdat, which allows determining whether a function in a comdat is dead without scanning the whole module. In particular, this makes filterDeadComdatFunctions() have complexity O(#DeadFunctions) rather than O(#SymbolsInModule), which addresses half of the compile-time issue exposed by D115545. Differential Revision: https://reviews.llvm.org/D115864
2021-12-13[ConstantsTest] Avoid crash with opaque pointersNikita Popov1-1/+6
With opaque pointers there will be no bitcast, so don't assume that.
2021-12-02[llvm-c] Make LLVMAddAlias opaque pointer compatibleNikita Popov1-1/+1
Deprecate LLVMAddAlias in favor of LLVMAddAlias2, which accepts a value type and an address space. Previously these were extracted from the pointer type. Differential Revision: https://reviews.llvm.org/D114860
2021-10-20[IR] Refactor GlobalIFunc to inherit from GlobalObject, Remove ↵Itay Bookstein1-1/+1
GlobalIndirectSymbol As discussed in: * https://reviews.llvm.org/D94166 * https://lists.llvm.org/pipermail/llvm-dev/2020-September/145031.html The GlobalIndirectSymbol class lost most of its meaning in https://reviews.llvm.org/D109792, which disambiguated getBaseObject (now getAliaseeObject) between GlobalIFunc and everything else. In addition, as long as GlobalIFunc is not a GlobalObject and getAliaseeObject returns GlobalObjects, a GlobalAlias whose aliasee is a GlobalIFunc cannot currently be modeled properly. Creating aliases for GlobalIFuncs does happen in the wild (e.g. glibc). In addition, calling getAliaseeObject on a GlobalIFunc will currently return nullptr, which is undesirable because it should return the object itself for non-aliases. This patch refactors the GlobalIFunc class to inherit directly from GlobalObject, and removes GlobalIndirectSymbol (while inlining the relevant parts into GlobalAlias and GlobalIFunc). This allows for calling getAliaseeObject() on a GlobalIFunc to return the GlobalIFunc itself, making getAliaseeObject() more consistent and enabling alias-to-ifunc to be properly modeled in the IR. I exercised some judgement in the API clients of GlobalIndirectSymbol: some were 'monomorphized' for GlobalAlias and GlobalIFunc, and some remained shared (with the type adapted to become GlobalValue). Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D108872
2021-05-13Reapply [ConstantFold] Fold more operations to poisonJuneyoung Lee1-14/+13
This was reverted to mitigate mitigate miscompiles caused by the logical and/or to bitwise and/or fold. Reapply it now that the underlying issue has been fixed by D101191. ----- This patch folds more operations to poison. Alive2 proof: https://alive2.llvm.org/ce/z/mxcb9G (it does not contain tests about div/rem because they fold to poison when raising UB) Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D92270
2021-04-08[Constant] Remove unused variableJuneyoung Lee1-1/+0
2021-04-08[Constant] ConstantStruct/Array should not lower poison to undefJuneyoung Lee1-7/+46
This is a (late) follow-up patch of 8871a4b4cab8a56fd6ff12fd024002c3c79128b3 and c95f39891a282ebf36199c73b705d4a2c78a46ce to make ConstantStruct::get/ConstantArray::getImpl correctly return PoisonValue if all elements are poison. This was found while discussing about the elements of a vector-typed UndefValue (D99853)
2021-03-16Add ConstantDataVector::getRaw() to create a constant data vector from raw data.Nick Lewycky1-18/+28
This parallels ConstantDataArray::getRaw() and can be used with ConstantDataSequential::getRawDataValues() in the base class for both types. Update BuildConstantData{Array,Vector} tests to test the getRaw API. Also removes its unused Module. In passing, update some comments to include the support for half and bfloat. Update tests to include testing for bfloat. Differential Revision: https://reviews.llvm.org/D98302
2021-03-15NFC: Formatting changes.Nick Lewycky1-73/+71
Run clang-format over these files. Capitalize some variable names per clang-tidy's request. Pulled out to simplify review of D98302.
2021-02-04Revert "[ConstantFold] Fold more operations to poison"Juneyoung Lee1-12/+13
This reverts commit 53040a968dc2ff20931661e55f05da2ef8b964a0 due to its bad interaction with select i1 -> and/or i1 transformation. This fixes: https://bugs.llvm.org/show_bug.cgi?id=49005 https://bugs.llvm.org/show_bug.cgi?id=48435
2021-01-07[Constant] Add tests for ConstantVector::get (NFC)Juneyoung Lee1-0/+8
2021-01-06[Constant] Add containsPoisonElementJuneyoung Lee1-0/+37
This patch - Adds containsPoisonElement that checks existence of poison in constant vector elements, - Renames containsUndefElement to containsUndefOrPoisonElement to clarify its behavior & updates its uses properly With this patch, isGuaranteedNotToBeUndefOrPoison's tests w.r.t constant vectors are added because its analysis is improved. Thanks! Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D94053
2020-11-29[ConstantFold] Fold more operations to poisonJuneyoung Lee1-13/+12
This patch folds more operations to poison. Alive2 proof: https://alive2.llvm.org/ce/z/mxcb9G (it does not contain tests about div/rem because they fold to poison when raising UB) Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D92270
2020-11-29[ConstantFold] Fold operations to poison if possibleJuneyoung Lee1-5/+6
This patch updates ConstantFold, so operations are folded into poison if possible. <alive2 proofs> casts: https://alive2.llvm.org/ce/z/WSj7rw binary operations (arithmetic): https://alive2.llvm.org/ce/z/_7dEyJ binary operations (bitwise): https://alive2.llvm.org/ce/z/cezjVN vector/aggregate operations: https://alive2.llvm.org/ce/z/BQ7hWz unary ops: https://alive2.llvm.org/ce/z/yBRs4q other ops: https://alive2.llvm.org/ce/z/iXbcFD Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D92203
2020-08-19Revert "Revert "[NFC][llvm] Make the contructors of `ElementCount` private.""Mehdi Amini1-2/+2
Was reverted because MLIR/Flang builds were broken, these APIs have been fixed in the meantime.
2020-08-19Revert "[NFC][llvm] Make the contructors of `ElementCount` private."Mehdi Amini1-2/+2
This reverts commit 264afb9e6aebc98c353644dd0700bec808501cab. (and dependent 6b742cc48 and fc53bd610f) MLIR/Flang are broken.
2020-08-19[NFC][llvm] Make the contructors of `ElementCount` private.Francesco Petrogalli1-2/+2
Differential Revision: https://reviews.llvm.org/D86120
2020-07-08[Solaris] Fix Solaris build botsChristopher Tetreault1-3/+3
Reviewers: ro Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D83415
2020-07-07[SVE] Make Constant::getSplatValue work for scalable vector splatsChristopher Tetreault1-0/+29
Summary: Make Constant::getSplatValue recognize scalable vector splats of the form created by ConstantVector::getSplat. Add unit test to verify that C == ConstantVector::getSplat(C)->getSplatValue() for fixed width and scalable vector splats Reviewers: efriedma, spatel, fpetrogalli, c-rhodes Reviewed By: efriedma Subscribers: sdesmalen, tschuett, hiraditya, rkruppe, psnobl, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D82416
2020-06-16[SVE] Deprecate default false variant of VectorType::getChristopher Tetreault1-4/+4
Reviewers: efriedma, fpetrogalli, kmclaughlin, huntergr Reviewed By: fpetrogalli Subscribers: cfe-commits, tschuett, rkruppe, psnobl, llvm-commits Tags: #llvm, #clang Differential Revision: https://reviews.llvm.org/D80342
2020-01-17[IR] fix Constant::isElementWiseEqual() to allow for all undef elements compareSanjay Patel1-1/+1
We could argue that match() should be more flexible here, but I'm not sure what impact that would have on existing code.
2020-01-17[IR] add unit test for Constant::isElementWiseEqual() for undef corner case; NFCSanjay Patel1-0/+2