aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Analysis/InstructionSimplify.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix inverted condition noticed by Frits van Bommel.Duncan Sands2010-12-211-3/+3
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122331 91177308-0d34-0410-b5e6-96231b3b80d8
* Pull a few more simplifications out of instcombine (there are stillDuncan Sands2010-12-211-5/+86
| | | | | | | plenty left though!), in particular for multiplication. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122330 91177308-0d34-0410-b5e6-96231b3b80d8
* Teach InstructionSimplify about distributive laws. These transforms fireDuncan Sands2010-12-211-11/+159
| | | | | | | | quite often, but don't make much difference in practice presumably because instcombine also knows them and more. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122328 91177308-0d34-0410-b5e6-96231b3b80d8
* Move checking of the recursion limit into the various Thread methods.Duncan Sands2010-12-211-20/+36
| | | | | | | No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122327 91177308-0d34-0410-b5e6-96231b3b80d8
* Add generic simplification of associative operations, generalizingDuncan Sands2010-12-211-28/+118
| | | | | | | | | | | | | a couple of existing transforms. This fires surprisingly often, for example when compiling gcc "(X+(-1))+1->X" fires quite a lot as well as various "and" simplifications (usually with a phi node operand). Most of the time this doesn't make a real difference since the same thing would have been done elsewhere anyway, eg: by instcombine, but there are a few places where this results in simplifications that we were not doing before. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122326 91177308-0d34-0410-b5e6-96231b3b80d8
* Have SimplifyBinOp dispatch Xor, Add and Sub to the corresponding methodsDuncan Sands2010-12-201-5/+27
| | | | | | | | (they had just been forgotten before). Adding Xor causes "main" in the existing testcase 2010-11-01-lshr-mask.ll to be hugely more simplified. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122245 91177308-0d34-0410-b5e6-96231b3b80d8
* Move Sub simplifications and additional Add simplifications out ofDuncan Sands2010-12-151-10/+67
| | | | | | | instcombine and into InstructionSimplify. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121861 91177308-0d34-0410-b5e6-96231b3b80d8
* If we detect that the instruction we are simplifying is unreachable, arrange forDuncan Sands2010-12-151-3/+3
| | | | | | | | it to be replaced by undef rather than not replaced at all, the idea being that this may reduce the amount of work done by whoever called InstructionSimplify. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121860 91177308-0d34-0410-b5e6-96231b3b80d8
* Add some dead stores to pacify my least favorite GCC warning: may beChandler Carruth2010-11-291-3/+3
| | | | | | | | | | | | uninitialized. The warning is terrible, has incorrect source locations, and has a huge false positive rate such as *all* of these. If anyone has a better solution, please let me know. Alternatively, I'll happily add -Wno-uninitialized to the -Werror build mode. Maybe I can even do it *only* when building with GCC instead of Clang. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120281 91177308-0d34-0410-b5e6-96231b3b80d8
* Expand a little on the description of what InstructionSimplify does.Duncan Sands2010-11-231-2/+4
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120016 91177308-0d34-0410-b5e6-96231b3b80d8
* If a GEP index simply advances by multiples of a type of zero size,Duncan Sands2010-11-221-1/+1
| | | | | | | then replace the index with zero. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119974 91177308-0d34-0410-b5e6-96231b3b80d8
* Move the "gep undef" -> "undef" transform from instcombine toDuncan Sands2010-11-221-4/+11
| | | | | | | InstructionSimplify. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119970 91177308-0d34-0410-b5e6-96231b3b80d8
* Add a rather pointless InstructionSimplify transform, inspired by recent ↵Duncan Sands2010-11-211-2/+10
| | | | | | | | | | | constant folding improvements: if P points to a type of size zero, turn "gep P, N" into "P". More generally, if a gep index type has size zero, instcombine could replace the index with zero, but that is not done here. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119942 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove threading of Xor over selects and phis, with an explanationDuncan Sands2010-11-191-13/+18
| | | | | | | of why such threading is pointless. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119798 91177308-0d34-0410-b5e6-96231b3b80d8
* Move some those Xor simplifications which don't require creating newDuncan Sands2010-11-171-30/+78
| | | | | | | | | instructions out of InstCombine and into InstructionSimplify. While there, introduce an m_AllOnes pattern to simplify matching with integers and vectors with all bits equal to one. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119536 91177308-0d34-0410-b5e6-96231b3b80d8
* Previously SimplifyInstruction could report that an instructionDuncan Sands2010-11-171-15/+31
| | | | | | | | | simplified to itself (this can only happen in unreachable blocks). Change it to return null instead. Hopefully this will fix some buildbot failures. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119490 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix a layering violation: hasConstantValue, which is part of the PHINodeDuncan Sands2010-11-171-3/+37
| | | | | | | | | | | | | | | class, uses DominatorTree which is an analysis. This change moves all of the tricky hasConstantValue logic to SimplifyInstruction, and replaces it with a very simple literal implementation. I already taught users of hasConstantValue that need tricky stuff to use SimplifyInstruction instead. I didn't update InlineFunction because the IR looks like it might be in a funky state at the point it calls hasConstantValue, which makes calling SimplifyInstruction dangerous since it can in theory do a lot of tricky reasoning. This may be a pessimization, for example in the case where all phi node operands are either undef or a fixed constant. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119459 91177308-0d34-0410-b5e6-96231b3b80d8
* In which I discover the existence of loops. Threading an operationDuncan Sands2010-11-161-60/+102
| | | | | | | | | | | | over a phi node by applying it to each operand may be wrong if the operation and the phi node are mutually interdependent (the testcase has a simple example of this). So only do this transform if it would be correct to perform the operation in each predecessor of the block containing the phi, i.e. if the other operands all dominate the phi. This should fix the FFMPEG snow.c regression reported by İsmail Dönmez. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119347 91177308-0d34-0410-b5e6-96231b3b80d8
* Teach InstructionSimplify the trick of skipping incoming phiDuncan Sands2010-11-151-4/+9
| | | | | | | values that are equal to the phi itself. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119161 91177308-0d34-0410-b5e6-96231b3b80d8
* If dom tree information is available, make it possible to passDuncan Sands2010-11-141-5/+7
| | | | | | | it to get better phi node simplification. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119055 91177308-0d34-0410-b5e6-96231b3b80d8
* Teach InstructionSimplify about phi nodes. I chose to have it simplyDuncan Sands2010-11-141-0/+2
| | | | | | | | | | | offload the work to hasConstantValue rather than do something more complicated (such handling mutually recursive phis) because (1) it is not clear it is worth it; and (2) if it is worth it, maybe such logic would be better placed in hasConstantValue. Adjust some GVN tests which are now cleaned up much further (eg: all phi nodes are removed). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119043 91177308-0d34-0410-b5e6-96231b3b80d8
* Strip trailing whitespace.Duncan Sands2010-11-141-50/+49
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119038 91177308-0d34-0410-b5e6-96231b3b80d8
* Reduce the maximum recursion depth, 5 seems pointlessly too much.Duncan Sands2010-11-101-1/+1
| | | | | | | Probably it should just be 1, but compromise with 3. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118718 91177308-0d34-0410-b5e6-96231b3b80d8
* Teach InstructionSimplify how to look through PHI nodes. Since PHIDuncan Sands2010-11-101-32/+163
| | | | | | | | | | nodes can be used in loops, this could result in infinite looping if there is no recursion limit, so add such a limit. It is also used for the SelectInst case because in theory there could be an infinite loop there too if the basic block is unreachable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118694 91177308-0d34-0410-b5e6-96231b3b80d8
* Simplify binary operations where one operand is a select instruction.Duncan Sands2010-11-101-28/+113
| | | | | | | | | | | | | | | | | | The simplifications performed here never create new instructions, they only return existing instructions (or a constant), and so are always a win. In theory they should transform (for example) %z = and i32 %x, %y %s = select i1 %cond, i32 %y, i32 %z %r = and i32 %x, %s into %r = and i32 %x, y but in practice they get into a fight with instcombine, and lose. Unfortunately instcombine does a poor job in this case. Nonetheless I'm committing this transform to make it easier to discuss what to do to make peace with instcombine. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118679 91177308-0d34-0410-b5e6-96231b3b80d8
* Factorize code, no functionality change.Duncan Sands2010-11-091-34/+31
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118516 91177308-0d34-0410-b5e6-96231b3b80d8
* Add simplification of floating point comparisons with the resultDuncan Sands2010-11-071-0/+20
| | | | | | | | of a select instruction, the same as already exists for integer comparisons. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118379 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix a README item: when doing a comparison with the resultDuncan Sands2010-11-071-2/+21
| | | | | | | | | of a select instruction, see if doing the compare with the true and false values of the select gives the same result. If so, that can be used as the value of the comparison. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118378 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r114097, adding back in the assertion against replacing an ↵Owen Anderson2010-09-161-24/+11
| | | | | | | | | | Instruction by itself. Now that CorrelatedValuePropagation is more careful not to call SimplifyInstructionsInBlock() on an unreachable block, the issue has been fixed at a higher level. Add a big warning to SimplifyInstructionsInBlock() to hopefully prevent this in the future. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114117 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix PR8161, in which an unreachable loop causes recursive instruction ↵Owen Anderson2010-09-161-11/+24
| | | | | | | | | simplification to try to replace an instruction with itself. Add a predicate to the simplifier to prevent this case. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114097 91177308-0d34-0410-b5e6-96231b3b80d8
* Teach InstructionSimplify to fold (A & B) & A -> A & B and (A | B) | A -> A | B.Benjamin Kramer2010-09-101-0/+20
| | | | | | | Reassociate does this but it doesn't catch all cases (e.g. if the operands are i1). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113651 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix PR7647, handling the case when 'To' ends up being Chris Lattner2010-07-151-14/+34
| | | | | | | | | | | mutated by recursive simplification. This also enhances ReplaceAndSimplifyAllUses to actually do a real RAUW at the end of it, which updates any value handles pointing to "From" to start pointing to "To". This seems useful for debug info and random other VH users. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108415 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r108401; it breaks bootstrap :(Eli Friedman2010-07-151-3/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108407 91177308-0d34-0410-b5e6-96231b3b80d8
* Add AssertingVH which makes PR7647 break consistently.Eli Friedman2010-07-151-1/+3
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108401 91177308-0d34-0410-b5e6-96231b3b80d8
* move some select simplifications out out instcombine intoChris Lattner2010-04-201-0/+32
| | | | | | | inst simplify. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101873 91177308-0d34-0410-b5e6-96231b3b80d8
* fix incorrect folding of icmp with undef, PR6481.Chris Lattner2010-03-031-4/+3
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97659 91177308-0d34-0410-b5e6-96231b3b80d8
* Constant-fold certain comparisons with infinity and negative infinity.Dan Gohman2010-02-221-0/+26
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96777 91177308-0d34-0410-b5e6-96231b3b80d8
* factor some logic out of instcombine into a new SimplifyAddInst method.Chris Lattner2009-11-271-6/+35
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90011 91177308-0d34-0410-b5e6-96231b3b80d8
* factor some instcombine simplifications for getelementptr out to a new Chris Lattner2009-11-271-0/+32
| | | | | | | SimplifyGEPInst method in InstructionSimplify.h. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89980 91177308-0d34-0410-b5e6-96231b3b80d8
* move some generally useful functions out of jump threadingChris Lattner2009-11-101-0/+35
| | | | | | | into libanalysis and transformutils. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86735 91177308-0d34-0410-b5e6-96231b3b80d8
* I misread the parens, not so redundant after all.Chris Lattner2009-11-101-4/+4
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86648 91177308-0d34-0410-b5e6-96231b3b80d8
* remove some redundant parens.Chris Lattner2009-11-101-4/+4
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86645 91177308-0d34-0410-b5e6-96231b3b80d8
* add a new SimplifyInstruction API, which is like ConstantFoldInstruction, Chris Lattner2009-11-101-0/+20
| | | | | | | | | except that the result may not be a constant. Switch jump threading to use it so that it gets things like (X & 0) -> 0, which occur when phi preds are deleted and the remaining phi pred was a zero. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86637 91177308-0d34-0410-b5e6-96231b3b80d8
* factor simplification logic for AND and OR out to InstSimplify from instcombine.Chris Lattner2009-11-101-24/+149
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86635 91177308-0d34-0410-b5e6-96231b3b80d8
* pull a bunch of logic out of instcombine into instsimplify for compare Chris Lattner2009-11-091-5/+93
| | | | | | | simplification, this handles the foldable fcmp x,x cases among many others. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86627 91177308-0d34-0410-b5e6-96231b3b80d8
* rename SimplifyCompare -> SimplifyCmpInst and split it into Chris Lattner2009-11-091-10/+35
| | | | | | | | Simplify[IF]Cmp pieces. Add some predicates to CmpInst to determine whether a predicate is fp or int. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86624 91177308-0d34-0410-b5e6-96231b3b80d8
* fix ConstantFoldCompareInstOperands to take the LHS/RHS asChris Lattner2009-11-091-4/+2
| | | | | | | individual operands instead of taking a temporary array git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86619 91177308-0d34-0410-b5e6-96231b3b80d8
* stub out a new libanalysis "instruction simplify" interface thatChris Lattner2009-11-091-0/+57
takes decimated instructions and applies identities to them. This is pretty minimal at this point, but I plan to pull some instcombine logic out into these and similar routines. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86613 91177308-0d34-0410-b5e6-96231b3b80d8