summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/SCCP.cpp
AgeCommit message (Collapse)Author
2018-04-11Merging r326404:Tom Stellard
------------------------------------------------------------------------ r326404 | rnk | 2018-02-28 17:19:18 -0800 (Wed, 28 Feb 2018) | 14 lines [IPSCCP] do not break musttail invariant (PR36485) Do not replace results of `musttail` calls with a constant if the call itself can't be removed. Do not zap returns of `musttail` callees, if the call site can't be removed and replaced with a constant. Do not zap returns of `musttail`-calling blocks, this breaks invariant too. Patch by Fedor Indutny Differential Revision: https://reviews.llvm.org/D43695 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_60@329855 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-30Use phi ranges to simplify code. No functionality change intended.Benjamin Kramer
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321585 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-23[SCCP] Manually fold branches on undef.Davide Italiano
This code was originally removed and replace with an assertion because believed unnecessary. It turns out there was simply no test coverage for this case, and the constant folder doesn't yet know about patterns like `br undef %label1, %label2`. Presumably at some point the constant folder might learn about these patterns, but it's a broader change. A testcase will be added to make sure this doesn't regress again in the future. Fixes PR35723. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321402 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-22[SCCP] Pick the right lattice value for constants.Davide Italiano
After the dataflow algorithm proves that an argument is constant, it replaces it value with the integer constant and drops the lattice value associated to the DEF. e.g. in the example we have @f() that's called twice: call @f(undef, ...) call @f(2, ...) `undef` MEET 2 = 2 so we replace the argument and all its uses with the constant 2. Shortly after, tryToReplaceWithConstantRange() tries to get the lattice value for the argument we just replaced, causing an assertion. This function is a little peculiar as it runs when we're doing replacement and not as part of the solver but still queries the solver. The fix is that of checking whether we replaced the value already and get a temporary lattice value for the constant. Thanks to Zhendong Su for the report! Fixes PR35357. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318817 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-21[SCCP] If we replace with a constant, we can't replace with a range.Davide Italiano
This microoptimization is NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318711 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-30Recommit r315288: [SCCP] Propagate integer range info for parameters in IPSCCP.Florian Hahn
This version of the patch includes a fix addressing a stage2 LTO buildbot failure and addressed some additional nits. Original commit message: This updates the SCCP solver to use of the ValueElement lattice for parameters, which provides integer range information. The range information is used to remove unneeded icmp instructions. For the following function, f() can be optimized to ret i32 2 with this change source_filename = "sccp.c" target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" ; Function Attrs: norecurse nounwind readnone uwtable define i32 @main() local_unnamed_addr #0 { entry: %call = tail call fastcc i32 @f(i32 1) %call1 = tail call fastcc i32 @f(i32 47) %add3 = add nsw i32 %call, %call1 ret i32 %add3 } ; Function Attrs: noinline norecurse nounwind readnone uwtable define internal fastcc i32 @f(i32 %x) unnamed_addr #1 { entry: %c1 = icmp sle i32 %x, 100 %cmp = icmp sgt i32 %x, 300 %. = select i1 %cmp, i32 1, i32 2 ret i32 %. } attributes #1 = { noinline } Reviewers: davide, sanjoy, efriedma, dberlin Reviewed By: davide, dberlin Subscribers: mcrosier, gberry, mssimpso, dberlin, llvm-commits Differential Revision: https://reviews.llvm.org/D36656 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316891 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-30Revert r316887 to fix buildbot failures.Florian Hahn
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316888 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-30Recommit r315288: [SCCP] Propagate integer range info for parameters in IPSCCP.Florian Hahn
This version of the patch includes a fix addressing a stage2 LTO buildbot failure and addressed some additional nits. Original commit message: This updates the SCCP solver to use of the ValueElement lattice for parameters, which provides integer range information. The range information is used to remove unneeded icmp instructions. For the following function, f() can be optimized to ret i32 2 with this change source_filename = "sccp.c" target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" ; Function Attrs: norecurse nounwind readnone uwtable define i32 @main() local_unnamed_addr #0 { entry: %call = tail call fastcc i32 @f(i32 1) %call1 = tail call fastcc i32 @f(i32 47) %add3 = add nsw i32 %call, %call1 ret i32 %add3 } ; Function Attrs: noinline norecurse nounwind readnone uwtable define internal fastcc i32 @f(i32 %x) unnamed_addr #1 { entry: %c1 = icmp sle i32 %x, 100 %cmp = icmp sgt i32 %x, 300 %. = select i1 %cmp, i32 1, i32 2 ret i32 %. } attributes #1 = { noinline } Reviewers: davide, sanjoy, efriedma, dberlin Reviewed By: davide, dberlin Subscribers: mcrosier, gberry, mssimpso, dberlin, llvm-commits Differential Revision: https://reviews.llvm.org/D36656 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316887 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-20[Transforms] Fix some Clang-tidy modernize and Include What You Use ↵Eugene Zelenko
warnings; other minor fixes (NFC). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316241 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-13[IPSCCP] Move common functions to ValueLatticeUtils (NFC)Matthew Simpson
This patch moves some common utility functions out of IPSCCP and makes them available globally. The functions determine if interprocedural data-flow analyses can propagate information through function returns, arguments, and global variables. Differential Revision: https://reviews.llvm.org/D37638 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315719 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-12Revert "Reintroduce "[SCCP] Propagate integer range info for parameters in ↵Bruno Cardoso Lopes
IPSCCP."" This reverts commit r315593: still affect two bots: http://lab.llvm.org:8011/builders/clang-with-lto-ubuntu/builds/5308 http://green.lab.llvm.org/green/job/clang-stage2-configure-Rlto/21751/ git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315618 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-12Reintroduce "[SCCP] Propagate integer range info for parameters in IPSCCP."Bruno Cardoso Lopes
This is r315288 & r315294, which were reverted due to stage2 bot failures. Summary: This updates the SCCP solver to use of the ValueElement lattice for parameters, which provides integer range information. The range information is used to remove unneeded icmp instructions. For the following function, f() can be optimized to `ret i32 2` with this change source_filename = "sccp.c" target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" ; Function Attrs: norecurse nounwind readnone uwtable define i32 @main() local_unnamed_addr #0 { entry: %call = tail call fastcc i32 @f(i32 1) %call1 = tail call fastcc i32 @f(i32 47) %add3 = add nsw i32 %call, %call1 ret i32 %add3 } ; Function Attrs: noinline norecurse nounwind readnone uwtable define internal fastcc i32 @f(i32 %x) unnamed_addr #1 { entry: %c1 = icmp sle i32 %x, 100 %cmp = icmp sgt i32 %x, 300 %. = select i1 %cmp, i32 1, i32 2 ret i32 %. } attributes #1 = { noinline } Reviewers: davide, sanjoy, efriedma, dberlin Reviewed By: davide, dberlin Subscribers: mcrosier, gberry, mssimpso, dberlin, llvm-commits Differential Revision: https://reviews.llvm.org/D36656 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315593 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-10Revert "[SCCP] Propagate integer range info for parameters in IPSCCP."Bruno Cardoso Lopes
This reverts commit r315288. This is part of fixing segfault introduced in: http://green.lab.llvm.org/green/job/clang-stage2-configure-Rlto/21675/ git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315329 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-10Revert "[SCCP] Fix mem-sanitizer failure introduced by r315288."Bruno Cardoso Lopes
This reverts commit r315294. Part of fixing seg fault introduced in: http://green.lab.llvm.org/green/job/clang-stage2-configure-Rlto/21675/ git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315328 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-10[SCCP] Fix mem-sanitizer failure introduced by r315288.Florian Hahn
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315294 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-10[SCCP] Propagate integer range info for parameters in IPSCCP.Florian Hahn
Summary: This updates the SCCP solver to use of the ValueElement lattice for parameters, which provides integer range information. The range information is used to remove unneeded icmp instructions. For the following function, f() can be optimized to `ret i32 2` with this change source_filename = "sccp.c" target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" ; Function Attrs: norecurse nounwind readnone uwtable define i32 @main() local_unnamed_addr #0 { entry: %call = tail call fastcc i32 @f(i32 1) %call1 = tail call fastcc i32 @f(i32 47) %add3 = add nsw i32 %call, %call1 ret i32 %add3 } ; Function Attrs: noinline norecurse nounwind readnone uwtable define internal fastcc i32 @f(i32 %x) unnamed_addr #1 { entry: %c1 = icmp sle i32 %x, 100 %cmp = icmp sgt i32 %x, 300 %. = select i1 %cmp, i32 1, i32 2 ret i32 %. } attributes #1 = { noinline } Reviewers: davide, sanjoy, efriedma, dberlin Reviewed By: davide, dberlin Subscribers: mcrosier, gberry, mssimpso, dberlin, llvm-commits Differential Revision: https://reviews.llvm.org/D36656 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315288 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-31[IPSCCP] Guard a user of getInitializer with hasDefinitiveInitializerDavid Majnemer
We are not allowed to reason about an initializer value without first consulting hasDefinitiveInitializer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309594 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-06[Constants] If we already have a ConstantInt*, prefer to use ↵Craig Topper
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307292 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-16[SCCP] Simplify the code a bit. NFCI.Davide Italiano
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305583 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-16[SCCP] Clarify a comment about unhandled instructions.Davide Italiano
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305579 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-16[SCCP] Remove redundant instruction visitors.Davide Italiano
Whenever we don't know what to do with an instruction, we send it to overdefined anyway. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305575 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-09[InstSimplify] Don't constant fold or DCE calls that are marked nobuiltinAndrew Kaylor
Differential Revision: https://reviews.llvm.org/D33737 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305132 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-23[SCCP] Use the `hasAddressTaken()` version defined in `Function`.Davide Italiano
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303706 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-12[IR] Redesign the case iterator in SwitchInst to actually be an iteratorChandler Carruth
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300032 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-10[SCCP] Resolve indirect branch target when possible.Xin Tong
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299830 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-08[SCCP] Merge markOverdefined and markAnythingOverdefined.Davide Italiano
There's no need to have two separate APIs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297253 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-26[SCCP] Remove manual folding of terminator instructions.Xin Tong
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296281 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-02[IPSCCP] Restore the old behaviour (pre r293799).Davide Italiano
It's not clear the change I made a good idea, and it definitely needs further discussion. Thanks to Eli for pointing out. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293846 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01[IPSCCP] Don't propagate return values of functions marked as noinline.Davide Italiano
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293799 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01[IPSCCP] Teach how to not propagate return values of naked functions.Davide Italiano
Differential Revision: https://reviews.llvm.org/D29360 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293727 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-19[SCCP] Teach the pass how to handle `div` with overdefined operands.Davide Italiano
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). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292531 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-19[SCCP] Update comment in visitBinaryOp() after recent changes.Davide Italiano
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292519 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-08[SCCP] Unknown instructions are sent to overdefined anyway. NFCI.Davide Italiano
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291400 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-13[SCCP] Debug diagnostic goes under DEBUG(). NFCI.Davide Italiano
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289519 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-11[SCCP] Use the appropriate helper function. NFCI.Davide Italiano
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289406 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-09[SCCP] Teach the pass about `mul %x 0` even if %x is overdefined.Davide Italiano
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289175 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-08[SCCP] Make sure SCCP and ConstantFolding agree on undef >> a.Davide Italiano
Currently SCCP folds the value to -1, while ConstantProp folds to 0. This changes SCCP to do what ConstantFolding does. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289147 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-06Revert "[SCCP] Remove manual folding of terminator instructions."Davide Italiano
This reverts commit r288725 as it broke a bot. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288759 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-05[SCCP] Remove manual folding of terminator instructions.Davide Italiano
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). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288725 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-01[SCCP] Switch over to DEBUG() and drop an #ifdef.Davide Italiano
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288325 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-01[SCCP] Prefer `auto` when the type is obvious. NFCI.Davide Italiano
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288324 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-22[SCCP] Remove code in visitBinaryOperator (and add tests).Davide Italiano
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287709 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-24[SCCP] Don't delete side-effecting instructionsSanjoy Das
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279647 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-11Use range algorithms instead of unpacking begin/endDavid Majnemer
No functionality change is intended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278417 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-09Consistently use ModuleAnalysisManagerSean Silva
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278078 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-09Consistently use FunctionAnalysisManagerSean Silva
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278077 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-20[SCCP] Zap multiple return values.Davide Italiano
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276174 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-19[SCCP] Improve assert messages. NFCI.Davide Italiano
I've been hitting those already while working on SCCP and I think it's be useful to provide a more explanatory diagnostic. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276007 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-15[SCCP] Merge two conditions into one. NFCI.Davide Italiano
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275593 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-14[SCCP] Pass the Solver by reference, copies are expensive ...Davide Italiano
.. enough to cause LTO compile time to regress insanely. Thanks *a lot* to Rafael for reporting the problem and testing the fix! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275468 91177308-0d34-0410-b5e6-96231b3b80d8