summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Scalar/Float2Int.cpp
AgeCommit message (Collapse)Author
2025-11-13[Float2Int] Make sure the CFP can be represented in the integer type (#167699)Yingwei Zheng
When `convertToInteger` fails, the integer result is undefined. In this case, we cannot use it in the subsequent steps. Close https://github.com/llvm/llvm-project/issues/167627.
2025-04-04[EquivClasses] Shorten members_{begin,end} idiom (#134373)Ramkumar Ramachandra
Introduce members() iterator-helper to shorten the members_{begin,end} idiom. A previous attempt of this patch was #130319, which had to be reverted due to unit-test failures when attempting to call members() on the end iterator. In this patch, members() accepts either an ECValue or an ElemTy, which is more intuitive and doesn't suffer from the same issue.
2025-04-02[EquivalenceClasses] Use SmallVector for deterministic iteration order. ↵Florian Hahn
(#134075) Currently iterators over EquivalenceClasses will iterate over std::set, which guarantees the order specified by the comperator. Unfortunately in many cases, EquivalenceClasses are used with pointers, so iterating over std::set of pointers will not be deterministic across runs. There are multiple places that explicitly try to sort the equivalence classes before using them to try to get a deterministic order (LowerTypeTests, SplitModule), but there are others that do not at the moment and this can result at least in non-determinstic value naming in Float2Int. This patch updates EquivalenceClasses to keep track of all members via a extra SmallVector and removes code from LowerTypeTests and SplitModule to sort the classes before processing. Overall it looks like compile-time slightly decreases in most cases, but close to noise: https://llvm-compile-time-tracker.com/compare.php?from=7d441d9892295a6eb8aaf481e1715f039f6f224f&to=b0c2ac67a88d3ef86987e2f82115ea0170675a17&stat=instructions PR: https://github.com/llvm/llvm-project/pull/134075
2025-04-01[EquivalenceClasses] Update member_begin to take ECValue (NFC).Florian Hahn
Remove a level of indirection and update code to use range-based for loops.
2024-10-16[Scalar] Avoid repeated hash lookups (NFC) (#112486)Kazu Hirata
2024-09-09[Float2Int] Avoid repeated hash lookups (NFC) (#107795)Kazu Hirata
2024-06-28[IR] Add getDataLayout() helpers to Function and GlobalValue (#96919)Nikita Popov
Similar to https://github.com/llvm/llvm-project/pull/96902, this adds `getDataLayout()` helpers to Function and GlobalValue, replacing the current `getParent()->getDataLayout()` pattern.
2024-03-25Reapply: [Float2Int] Resolve FIXME: Pick the smallest legal type that fits ↵AtariDreams
(#86337) Originally reverted because of a bug in Range that is now fixed (#86041), we can reland this commit. Tests have been added to ensure the miscompile that caused the revert does not happen again.
2024-03-21[Float2Int] Fix pessimization in the MinBW calculation. (#86051)Craig Topper
The MinBW was being calculated using the significant bits of the upper and lower bounds. The upper bound is 1 past the last value in the range so I don't think it should be included. Instead use ConstantRange::getMinSignedBits. I'm still not sure if the +1 is needed after the getMinSignedBits call.
2024-03-19Revert "[Float2Int] Resolve FIXME: Pick the smallest legal type that fits" ↵alexfh
(#85843) Reverts llvm/llvm-project#79158, which causes a miscompile. See https://github.com/llvm/llvm-project/pull/79158#issuecomment-2007842032
2024-03-13[Float2Int] Resolve FIXME: Pick the smallest legal type that fits (#79158)AtariDreams
Pick the type based on the smallest bit-width possible, using DataLayout.
2023-04-17Remove several no longer needed includes. NFCIBjorn Pettersson
Mostly removing includes of InitializePasses.h and Pass.h in passes that no longer has support for the legacy PM.
2023-03-14[Passes] Remove some legacy passesArthur Eubanks
NewGVN GVNHoist GVNSink MemCpyOpt Float2Int These were only used for the optimization pipeline, of which the legacy version was removed.
2023-03-14[Transforms] Use *{Set,Map}::contains (NFC)Kazu Hirata
2023-02-19Use APInt::getSignificantBits instead of APInt::getMinSignedBits (NFC)Kazu Hirata
Note that getMinSignedBits has been soft-deprecated in favor of getSignificantBits.
2022-12-13[Transforms/Scalar] llvm::Optional => std::optionalFangrui Song
2022-12-04[llvm] Use std::nullopt instead of None in comments (NFC)Kazu Hirata
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-12-02[Transforms] Use std::nullopt instead of None (NFC)Kazu Hirata
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-04-05[iwyu] Fix some header include regressionserge-sans-paille
Running iwyu-diff from https://github.com/serge-sans-paille/preprocessor-utils makes it possible to quickly spot regression in unused includes. This patch contains the few regressions since the last header cleanup. Differential Revision: https://reviews.llvm.org/D123036
2022-04-04[Float2Int] Make sure dependent ranges are calculated first (PR54669)Nikita Popov
The range calculation in walkForwards() assumes that the ranges of the operands have already been calculated. With the used visit order, this is not necessarily the case when there are multiple roots. (There is nothing guaranteeing that instructions are visited in topological order.) Fix this by queuing instructions for reprocessing if the operand ranges haven't been calculated yet. Fixes https://github.com/llvm/llvm-project/issues/54669. Differential Revision: https://reviews.llvm.org/D122817
2022-03-31[Float2Int] Avoid unnecessary lamdbas (NFC)Nikita Popov
Instead of first creating a lambda for calculating the range, then collecting the ranges for the operands, and then calling the lambda on those ranges, we can first calculate the operand ranges and then calculate the result directly in the switch.
2022-03-31[Float2Int] Extract calcRange() method (NFC)Nikita Popov
This avoids the awkward "Abort" flag, because we can simply early-return instead.
2022-03-12Cleanup includes: DebugInfo & CodeGenserge-sans-paille
Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D121332
2022-03-03Cleanup includes: Transform/Scalarserge-sans-paille
Estimated impact on preprocessor output line: before: 1062981579 after: 1062494547 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D120817
2021-10-31[Transforms] Use {DenseSet,SetVector,SmallPtrSet}::contains (NFC)Kazu Hirata
2021-09-09[APInt] Normalize naming on keep constructors / predicate methods.Chris Lattner
This renames the primary methods for creating a zero value to `getZero` instead of `getNullValue` and renames predicates like `isAllOnesValue` to simply `isAllOnes`. This achieves two things: 1) This starts standardizing predicates across the LLVM codebase, following (in this case) ConstantInt. The word "Value" doesn't convey anything of merit, and is missing in some of the other things. 2) Calling an integer "null" doesn't make any sense. The original sin here is mine and I've regretted it for years. This moves us to calling it "zero" instead, which is correct! APInt is widely used and I don't think anyone is keen to take massive source breakage on anything so core, at least not all in one go. As such, this doesn't actually delete any entrypoints, it "soft deprecates" them with a comment. Included in this patch are changes to a bunch of the codebase, but there are more. We should normalize SelectionDAG and other APIs as well, which would make the API change more mechanical. Differential Revision: https://reviews.llvm.org/D109483
2021-05-30[NFCI] Move DEBUG_TYPE definition below #includesMindong Chen
When you try to define a new DEBUG_TYPE in a header file, DEBUG_TYPE definition defined around the #includes in files include it could result in redefinition warnings even compile errors. Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D102594
2021-05-18[NewPM] Don't mark AA analyses as preservedArthur Eubanks
Currently all AA analyses marked as preserved are stateless, not taking into account their dependent analyses. So there's no need to mark them as preserved, they won't be invalidated unless their analyses are. SCEVAAResults was the one exception to this, it was treated like a typical analysis result. Make it like the others and don't invalidate unless SCEV is invalidated. Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D102032
2020-12-17[NFC] Reduce include files dependency and AA header cleanup (part 2).dfukalov
Continuing work started in https://reviews.llvm.org/D92489: Removed a bunch of includes from "AliasAnalysis.h" and "LoopPassManager.h". Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D92852
2020-04-16[Float2Int] Stop passing around a reference to the class member Roots. NFCBjorn Pettersson
The Float2IntPass got a class member called Roots, but Roots was also passed around to member function as a reference. This patch simply remove those references.
2020-03-06[APFloat] Make use of new overloaded comparison operators. NFC.Jay Foad
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
2019-11-14Add missing includes needed to prune LLVMContext.h include, NFCReid Kleckner
These are a pre-requisite to removing #include "llvm/Support/Options.h" from LLVMContext.h: https://reviews.llvm.org/D70280
2019-11-13Sink all InitializePasses.h includesReid Kleckner
This file lists every pass in LLVM, and is included by Pass.h, which is very popular. Every time we add, remove, or rename a pass in LLVM, it caused lots of recompilation. I found this fact by looking at this table, which is sorted by the number of times a file was changed over the last 100,000 git commits multiplied by the number of object files that depend on it in the current checkout: recompiles touches affected_files header 342380 95 3604 llvm/include/llvm/ADT/STLExtras.h 314730 234 1345 llvm/include/llvm/InitializePasses.h 307036 118 2602 llvm/include/llvm/ADT/APInt.h 213049 59 3611 llvm/include/llvm/Support/MathExtras.h 170422 47 3626 llvm/include/llvm/Support/Compiler.h 162225 45 3605 llvm/include/llvm/ADT/Optional.h 158319 63 2513 llvm/include/llvm/ADT/Triple.h 140322 39 3598 llvm/include/llvm/ADT/StringRef.h 137647 59 2333 llvm/include/llvm/Support/Error.h 131619 73 1803 llvm/include/llvm/Support/FileSystem.h Before this change, touching InitializePasses.h would cause 1345 files to recompile. After this change, touching it only causes 550 compiles in an incremental rebuild. Reviewers: bkramer, asbirlea, bollu, jdoerfert Differential Revision: https://reviews.llvm.org/D70211
2019-09-19[Float2Int] avoid crashing on unreachable code (PR38502)Sanjay Patel
In the example from: https://bugs.llvm.org/show_bug.cgi?id=38502 ...we hit infinite looping/crashing because we have non-standard IR - an instruction operand is used before defined. This and other unusual constructs are allowed in unreachable blocks, so avoid the problem by using DominatorTree to step around landmines. Differential Revision: https://reviews.llvm.org/D67766 llvm-svn: 372339
2019-07-16Fix parameter name comments using clang-tidy. NFC.Rui Ueyama
This patch applies clang-tidy's bugprone-argument-comment tool to LLVM, clang and lld source trees. Here is how I created this patch: $ git clone https://github.com/llvm/llvm-project.git $ cd llvm-project $ mkdir build $ cd build $ cmake -GNinja -DCMAKE_BUILD_TYPE=Debug \ -DLLVM_ENABLE_PROJECTS='clang;lld;clang-tools-extra' \ -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DLLVM_ENABLE_LLD=On \ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ../llvm $ ninja $ parallel clang-tidy -checks='-*,bugprone-argument-comment' \ -config='{CheckOptions: [{key: StrictMode, value: 1}]}' -fix \ ::: ../llvm/lib/**/*.{cpp,h} ../clang/lib/**/*.{cpp,h} ../lld/**/*.{cpp,h} llvm-svn: 366177
2019-07-08[Float2Int] Add support for unary FNeg to Float2IntCameron McInally
Differential Revision: https://reviews.llvm.org/D63941 llvm-svn: 365324
2019-03-24[ConstantRange] Add getFull() + getEmpty() named constructors; NFCNikita Popov
This adds ConstantRange::getFull(BitWidth) and ConstantRange::getEmpty(BitWidth) named constructors as more readable alternatives to the current ConstantRange(BitWidth, /* full */ false) and similar. Additionally private getFull() and getEmpty() member functions are added which return a full/empty range with the same bit width -- these are commonly needed inside ConstantRange.cpp. The IsFullSet argument in the ConstantRange(BitWidth, IsFullSet) constructor is now mandatory for the few usages that still make use of it. Differential Revision: https://reviews.llvm.org/D59716 llvm-svn: 356852
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
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
2018-05-14Rename DEBUG macro to LLVM_DEBUG.Nicola Zaghen
The DEBUG() macro is very generic so it might clash with other projects. The renaming was done as follows: - git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g' - git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM - Manual change to APInt - Manually chage DOCS as regex doesn't match it. In the transition period the DEBUG() macro is still present and aliased to the LLVM_DEBUG() one. Differential Revision: https://reviews.llvm.org/D43624 llvm-svn: 332240
2017-05-05[Float2Int] Replace a ConstantRange copy with a move. Remove an extra call ↵Craig Topper
to MapVector::find. llvm-svn: 302256
2017-05-04[Float2Int] Remove return of ConstantRange from seen method. Nothing uses it ↵Craig Topper
so it just creates and discards a ConstantRange object for no reason. llvm-svn: 302193
2017-01-15[PM] Introduce an analysis set used to preserve all analyses overChandler Carruth
a function's CFG when that CFG is unchanged. This allows transformation passes to simply claim they preserve the CFG and analysis passes to check for the CFG being preserved to remove the fanout of all analyses being listed in all passes. I've gone through and removed or cleaned up as many of the comments reminding us to do this as I could. Differential Revision: https://reviews.llvm.org/D28627 llvm-svn: 292054
2016-12-01Factor out common parts of LVI and Float2Int into ConstantRange [NFCI]Philip Reames
This just extracts out the transfer rules for constant ranges into a single shared point. As it happens, neither bit of code actually overlaps in terms of the handled operators, but with this change that could easily be tweaked in the future. I also want to have this separated out to make experimenting with a eager value info implementation and possibly a ValueTracking-like fixed depth recursion peephole version. There's no reason all four of these can't share a common implementation which reduces the chances of bugs. Differential Revision: https://reviews.llvm.org/D27294 llvm-svn: 288413
2016-06-28[PM] Normalize FIXMEs for missing PreserveCFG to have the same wording.Michael Kuperstein
llvm-svn: 273974
2016-06-24[PM] Port float2int to the new pass managerMichael Kuperstein
Differential Revision: http://reviews.llvm.org/D21704 llvm-svn: 273747
2016-06-24Switch more loops to be range-basedDavid Majnemer
This makes the code a little more concise, no functional change is intended. llvm-svn: 273644
2016-06-08Avoid copies of std::strings and APInt/APFloats where we only read from itBenjamin Kramer
As suggested by clang-tidy's performance-unnecessary-copy-initialization. This can easily hit lifetime issues, so I audited every change and ran the tests under asan, which came back clean. llvm-svn: 272126
2016-04-22Re-commit optimization bisect support (r267022) without new pass manager ↵Andrew Kaylor
support. The original commit was reverted because of a buildbot problem with LazyCallGraph::SCC handling (not related to the OptBisect handling). Differential Revision: http://reviews.llvm.org/D19172 llvm-svn: 267231
2016-04-22Revert "Initial implementation of optimization bisect support."Vedant Kumar
This reverts commit r267022, due to an ASan failure: http://lab.llvm.org:8080/green/job/clang-stage2-cmake-RgSan_check/1549 llvm-svn: 267115
2016-04-21Initial implementation of optimization bisect support.Andrew Kaylor
This patch implements a optimization bisect feature, which will allow optimizations to be selectively disabled at compile time in order to track down test failures that are caused by incorrect optimizations. The bisection is enabled using a new command line option (-opt-bisect-limit). Individual passes that may be skipped call the OptBisect object (via an LLVMContext) to see if they should be skipped based on the bisect limit. A finer level of control (disabling individual transformations) can be managed through an addition OptBisect method, but this is not yet used. The skip checking in this implementation is based on (and replaces) the skipOptnoneFunction check. Where that check was being called, a new call has been inserted in its place which checks the bisect limit and the optnone attribute. A new function call has been added for module and SCC passes that behaves in a similar way. Differential Revision: http://reviews.llvm.org/D19172 llvm-svn: 267022