summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/SCCP.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [Constants] If we already have a ConstantInt*, prefer to use ↵Craig Topper2017-07-061-1/+1
| | | | | | | | isZero/isOne/isMinusOne instead of isNullValue/isOneValue/isAllOnesValue inherited from Constant. NFCI Going through the Constant methods requires redetermining that the Constant is a ConstantInt and then calling isZero/isOne/isMinusOne. llvm-svn: 307292
* [SCCP] Simplify the code a bit. NFCI.Davide Italiano2017-06-161-7/+3
| | | | llvm-svn: 305583
* [SCCP] Clarify a comment about unhandled instructions.Davide Italiano2017-06-161-2/+3
| | | | llvm-svn: 305579
* [SCCP] Remove redundant instruction visitors.Davide Italiano2017-06-161-11/+0
| | | | | | | Whenever we don't know what to do with an instruction, we send it to overdefined anyway. llvm-svn: 305575
* [InstSimplify] Don't constant fold or DCE calls that are marked nobuiltinAndrew Kaylor2017-06-091-2/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D33737 llvm-svn: 305132
* [SCCP] Use the `hasAddressTaken()` version defined in `Function`.Davide Italiano2017-05-231-1/+2
| | | | | | | | | | Instead of using the SCCP homegrown one. We should eventually make the private SCCP version disappear, but that wont' be today. PR33143 tracks this issue. Add braces for consistency while here. No functional change intended. llvm-svn: 303706
* [IR] Redesign the case iterator in SwitchInst to actually be an iteratorChandler Carruth2017-04-121-5/+5
| | | | | | | | | | | | | | | | and to expose a handle to represent the actual case rather than having the iterator return a reference to itself. All of this allows the iterator to be used with common STL facilities, standard algorithms, etc. Doing this exposed some missing facilities in the iterator facade that I've fixed and required some work to the actual iterator to fully support the necessary API. Differential Revision: https://reviews.llvm.org/D31548 llvm-svn: 300032
* [SCCP] Resolve indirect branch target when possible.Xin Tong2017-04-101-8/+71
| | | | | | | | | | | | | | Summary: Resolve indirect branch target when possible. This potentially eliminates more basicblocks and result in better evaluation for phi and other things. Reviewers: davide, efriedma, sanjoy Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D30322 llvm-svn: 299830
* [SCCP] Merge markOverdefined and markAnythingOverdefined.Davide Italiano2017-03-081-23/+17
| | | | | | There's no need to have two separate APIs. llvm-svn: 297253
* [SCCP] Remove manual folding of terminator instructions.Xin Tong2017-02-261-26/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: BranchInst, SwitchInst (with non-default case) with Undef as input is not possible at this point. As we always default-fold terminator to one target in ResolvedUndefsIn and set the input accordingly. So we should only have constantint/blockaddress here. If ConstantFoldTerminator fails, that could mean 2 things. 1. ConstantFoldTerminator is doing something unexpected, i.e. not folding on constantint or blockaddress and not making blocks that should be dead dead. 2. This is not a terminator on constantint or blockaddress. Its on a constant or overdefined, then this block should not be dead. In both cases, we should assert. Reviewers: davide, efriedma, sanjoy Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D30381 llvm-svn: 296281
* [IPSCCP] Restore the old behaviour (pre r293799).Davide Italiano2017-02-021-6/+1
| | | | | | | It's not clear the change I made a good idea, and it definitely needs further discussion. Thanks to Eli for pointing out. llvm-svn: 293846
* [IPSCCP] Don't propagate return values of functions marked as noinline.Davide Italiano2017-02-011-1/+6
| | | | | | | | | | | | This tries to address what Hal defined (in the post-commit review of r293727) a long-standing problem with noinline, where we end up de facto inlining trivial functions e.g. __attribute__((noinline)) int patatino(void) { return 5; } because of return value propagation. llvm-svn: 293799
* [IPSCCP] Teach how to not propagate return values of naked functions.Davide Italiano2017-02-011-1/+4
| | | | | | Differential Revision: https://reviews.llvm.org/D29360 llvm-svn: 293727
* [SCCP] Teach the pass how to handle `div` with overdefined operands.Davide Italiano2017-01-191-0/+6
| | | | | | | | | | | | | | | | | | This can prove that: extern int f; int g() { int x = 0; for (int i = 0; i < 365; ++i) { x /= f; } return x; } always returns zero. Thanks to Sanjoy for confirming this transformation actually made sense (bugs are mine). llvm-svn: 292531
* [SCCP] Update comment in visitBinaryOp() after recent changes.Davide Italiano2017-01-191-3/+4
| | | | llvm-svn: 292519
* [SCCP] Unknown instructions are sent to overdefined anyway. NFCI.Davide Italiano2017-01-081-18/+0
| | | | llvm-svn: 291400
* [SCCP] Debug diagnostic goes under DEBUG(). NFCI.Davide Italiano2016-12-131-1/+1
| | | | llvm-svn: 289519
* [SCCP] Use the appropriate helper function. NFCI.Davide Italiano2016-12-111-2/+2
| | | | llvm-svn: 289406
* [SCCP] Teach the pass about `mul %x 0` even if %x is overdefined.Davide Italiano2016-12-091-2/+5
| | | | | | | | | | | | | | | | | | | | | | | The motivating example is: extern int patatino; int goo() { int x = 0; for (int i = 0; i < 1000000; ++i) { x *= patatino; } return x; } Currently SCCP will not realize that this function returns always zero, therefore will try to unroll and vectorize the loop at -O3 producing an awful lot of (useless) code. With this change, it will just produce: 0000000000000000 <g>: xor %eax,%eax retq llvm-svn: 289175
* [SCCP] Make sure SCCP and ConstantFolding agree on undef >> a.Davide Italiano2016-12-081-2/+2
| | | | | | | Currently SCCP folds the value to -1, while ConstantProp folds to 0. This changes SCCP to do what ConstantFolding does. llvm-svn: 289147
* Revert "[SCCP] Remove manual folding of terminator instructions."Davide Italiano2016-12-061-2/+27
| | | | | | This reverts commit r288725 as it broke a bot. llvm-svn: 288759
* [SCCP] Remove manual folding of terminator instructions.Davide Italiano2016-12-051-27/+2
| | | | | | | | | | | | | There are two cases handled here: 1) a branch on undef 2) a switch with an undef condition. Both cases are currently handled by ResolvedUndefsIn. If we have a branch on undef, we force its value to false (which is trivially foldable). If we have a switch on undef, we force to the first constant (which is also foldable). llvm-svn: 288725
* [SCCP] Switch over to DEBUG() and drop an #ifdef.Davide Italiano2016-12-011-6/+2
| | | | llvm-svn: 288325
* [SCCP] Prefer `auto` when the type is obvious. NFCI.Davide Italiano2016-12-011-27/+27
| | | | llvm-svn: 288324
* [SCCP] Remove code in visitBinaryOperator (and add tests).Davide Italiano2016-11-221-11/+3
| | | | | | | | | | We visit and/or, we try to derive a lattice value for the instruction even if one of the operands is overdefined. If the non-overdefined value is still 'unknown' just return and wait for ResolvedUndefsIn to "plug in" the correct value. This simplifies the logic a bit. While I'm here add tests for missing cases. llvm-svn: 287709
* [SCCP] Don't delete side-effecting instructionsSanjoy Das2016-08-241-17/+6
| | | | | | | | I'm not sure if the `!isa<CallInst>(Inst) && !isa<TerminatorInst>(Inst))` bit is correct either, but this fixes the case we know is broken. llvm-svn: 279647
* Use range algorithms instead of unpacking begin/endDavid Majnemer2016-08-111-2/+1
| | | | | | No functionality change is intended. llvm-svn: 278417
* Consistently use ModuleAnalysisManagerSean Silva2016-08-091-1/+1
| | | | | | | | | | | Besides a general consistently benefit, the extra layer of indirection allows the mechanical part of https://reviews.llvm.org/D23256 that requires touching every transformation and analysis to be factored out cleanly. Thanks to David for the suggestion. llvm-svn: 278078
* Consistently use FunctionAnalysisManagerSean Silva2016-08-091-1/+1
| | | | | | | | | | | Besides a general consistently benefit, the extra layer of indirection allows the mechanical part of https://reviews.llvm.org/D23256 that requires touching every transformation and analysis to be factored out cleanly. Thanks to David for the suggestion. llvm-svn: 278077
* [SCCP] Zap multiple return values.Davide Italiano2016-07-201-9/+41
| | | | | | | | | We can replace the return values with undef if we replaced all the call uses with a constant/undef. Differential Revision: https://reviews.llvm.org/D22336 llvm-svn: 276174
* [SCCP] Improve assert messages. NFCI.Davide Italiano2016-07-191-4/+6
| | | | | | | I've been hitting those already while working on SCCP and I think it's be useful to provide a more explanatory diagnostic. llvm-svn: 276007
* [SCCP] Merge two conditions into one. NFCI.Davide Italiano2016-07-151-3/+1
| | | | llvm-svn: 275593
* [SCCP] Pass the Solver by reference, copies are expensive ...Davide Italiano2016-07-141-2/+2
| | | | | | | | .. enough to cause LTO compile time to regress insanely. Thanks *a lot* to Rafael for reporting the problem and testing the fix! llvm-svn: 275468
* [SCCP] Pass a Value * instead of templating this function. NFC.Davide Italiano2016-07-141-9/+8
| | | | | | Thanks to Eli for the suggestion! llvm-svn: 275366
* [IPSCCP] Constant fold struct argument/instructions when all the lattice ↵Davide Italiano2016-07-141-10/+3
| | | | | | | | | | | values are constant. This now should also work with the interprocedural variant of the pass. Slightly easier now that the yak is shaved. Differential Revision: http://reviews.llvm.org/D22329 llvm-svn: 275363
* [SCCP] Generalize tryToReplaceInstWithConstant to work also with arguments.Davide Italiano2016-07-141-22/+18
| | | | llvm-svn: 275357
* [SCCP] Have the logic for replacing insts with constant in a single place.Davide Italiano2016-07-131-53/+50
| | | | | | | | | The code was pretty much copy-pasted between SCCP and IPSCCP. The situation became clearly worse after I introduced the support for folding structs in SCCP. This commit is NFC as we currently (still) skip the replacement step in IPSCCP, but I'll change this soon. llvm-svn: 275339
* [SCCP] Factor out common code.Davide Italiano2016-07-131-8/+9
| | | | llvm-svn: 275308
* [SCCP] Use early return. NFCI.Davide Italiano2016-07-131-5/+5
| | | | llvm-svn: 275307
* [SCCP] Constant fold structs if all the lattice value are constant.Davide Italiano2016-07-121-9/+35
| | | | | | Differential Revision: http://reviews.llvm.org/D22269 llvm-svn: 275208
* [SCCP] Try to follow the DRY principle, use `OpSt`.Davide Italiano2016-07-111-3/+2
| | | | | | Thanks to Eli Friedman for pointing out in his post-commit review! llvm-svn: 275084
* [SCCP] Rename undefined -> unknown.Davide Italiano2016-07-101-40/+40
| | | | | | | | | | In the solver, isUndefined() does really mean "we don't know the value yet" rather than "this is an UndefinedValue". Discussed with Eli Friedman. Differential Revision: http://reviews.llvm.org/D22192 llvm-svn: 275004
* [SCCP] Remove wrong and misleading vector handling code.Davide Italiano2016-07-091-53/+0
| | | | | | | | | This code was already commented out and it made some weird assumptions, e.g. using isUndefined() as "this value is UndefValue" instead of "we haven't computed this value is yet". Thanks to Eli Friedman for pointing out where I was wrong (and where this code was wrong). llvm-svn: 274995
* [SCCP] Fold constants as we build them whne visiting cast instructions.Davide Italiano2016-07-081-2/+4
| | | | | | | | | This should be slightly more efficient and could avoid spurious overdefined markings, as Eli pointed out. Differential Revision: http://reviews.llvm.org/D22122 llvm-svn: 274905
* Apply clang-tidy's modernize-loop-convert to most of lib/Transforms.Benjamin Kramer2016-06-261-27/+26
| | | | | | Only minor manual fixes. No functionality change intended. llvm-svn: 273808
* Revert "[SimplifyCFG] Stop inserting calls to llvm.trap for UB"David Majnemer2016-06-251-1/+2
| | | | | | This reverts commit r273778, it seems to break UBSan :/ llvm-svn: 273779
* [SimplifyCFG] Stop inserting calls to llvm.trap for UBDavid Majnemer2016-06-251-2/+1
| | | | | | | | | | | | | | | | | SimplifyCFG had logic to insert calls to llvm.trap for two very particular IR patterns: stores and invokes of undef/null. While InstCombine canonicalizes certain undefined behavior IR patterns to stores of undef, phase ordering means that this cannot be relied upon in general. There are much better tools than llvm.trap: UBSan and ASan. N.B. I could be argued into reverting this change if a clear argument as to why it is important that we synthesize llvm.trap for stores, I'd be hard pressed to see why it'd be useful for invokes... llvm-svn: 273778
* [SCCP] Don't assume all Constants are ConstantIntDavid Majnemer2016-06-231-8/+8
| | | | | | This fixes PR28269. llvm-svn: 273521
* [PM] SCCP should preserve GlobalsAA even if the IR is mutated.Davide Italiano2016-05-291-1/+4
| | | | llvm-svn: 271149
* [SCCP] Prefer class to struct.Davide Italiano2016-05-191-2/+4
| | | | llvm-svn: 270074
OpenPOWER on IntegriCloud