summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Avoid combining GEPs that might overflow at runtime.Stuart Hastings2011-05-141-1/+3
| | | | | | | | rdar://problem/9267970 Patch by Julien Lerouge! llvm-svn: 131339
* PR9838: Fix transform introduced in r127064 to not trigger when only one ↵Eli Friedman2011-05-051-1/+1
| | | | | | side of the icmp is an exact shift. llvm-svn: 130954
* Transform: "icmp eq (trunc (lshr(X, cst1)), cst" to "icmp (and X, mask), cst"Chris Lattner2011-04-261-0/+25
| | | | | | | | | | when X has multiple uses. This is useful for exposing secondary optimizations, but the X86 backend isn't ready for this when X has a single use. For example, this can disable load folding. This is inching towards resolving PR6627. llvm-svn: 130238
* some random cleanups, no functionality change.Chris Lattner2011-04-261-5/+5
| | | | llvm-svn: 130237
* Fix a ton of comment typos found by codespell. Patch byChris Lattner2011-04-151-1/+1
| | | | | | Luis Felipe Strano Moraes! llvm-svn: 129558
* InstCombine: APFloat can't perform arithmetic on PPC double doubles, don't ↵Benjamin Kramer2011-03-311-2/+4
| | | | | | | | even try. Thanks Eli! llvm-svn: 128676
* InstCombine: Fix transform to use the swapped predicate.Benjamin Kramer2011-03-311-2/+2
| | | | | | Thanks Frits! llvm-svn: 128628
* InstCombine: fold fcmp (fneg x), (fneg y) -> fcmp x, yBenjamin Kramer2011-03-311-0/+5
| | | | llvm-svn: 128627
* InstCombine: fold fcmp pred (fneg x), C -> fcmp swap(pred) x, -CBenjamin Kramer2011-03-311-0/+8
| | | | llvm-svn: 128626
* InstCombine: Shrink "fcmp (fpext x), C" to "fcmp x, C" if C can be ↵Benjamin Kramer2011-03-311-0/+34
| | | | | | | | losslessly converted to the type of x. Fixes PR9592. llvm-svn: 128625
* InstCombine: fold fcmp (fpext x), (fpext y) -> fcmp x, y.Benjamin Kramer2011-03-311-0/+7
| | | | llvm-svn: 128624
* Reorder comments to put them the right way around.Nick Lewycky2011-03-081-2/+2
| | | | llvm-svn: 127220
* ConstantInt has some getters which return ConstantInt's or ConstantVector's ofNick Lewycky2011-03-061-22/+22
| | | | | | | | the value splatted into every element. Extend this to getTrue and getFalse which by providing new overloads that take Types that are either i1 or <N x i1>. Use it in InstCombine to add vector support to some code, fixing PR8469! llvm-svn: 127116
* Thread comparisons over udiv/sdiv/ashr/lshr exact and lshr nuw/nsw wheneverNick Lewycky2011-03-051-0/+21
| | | | | | | | | possible. This goes into instcombine and instsimplify because instsimplify doesn't need to check hasOneUse since it returns (almost exclusively) constants. This fixes PR9343 #4 #5 and #8! llvm-svn: 127064
* Try once again to optimize "icmp (srem X, Y), Y" by turning the comparison intoNick Lewycky2011-03-051-0/+29
| | | | | | true/false or "icmp slt/sge Y, 0". llvm-svn: 127063
* srem doesn't actually have the same resulting sign as its numerator, you couldNick Lewycky2011-02-281-10/+0
| | | | | | | also have a zero when numerator = denominator. Reverts parts of r126635 and r126637. llvm-svn: 126644
* Teach InstCombine to fold "(shr exact X, Y) == 0" --> X == 0, fixing #1 fromNick Lewycky2011-02-281-5/+13
| | | | | | PR9343. llvm-svn: 126643
* The sign of an srem instruction is the sign of its dividend (the firstNick Lewycky2011-02-281-3/+13
| | | | | | | argument), regardless of the divisor. Teach instcombine about this and fix test7 in PR9343! llvm-svn: 126635
* Add some transforms of the kind X-Y>X -> 0>Y which are valid when there is noDuncan Sands2011-02-181-18/+17
| | | | | | overflow. These subsume some existing equality transforms, so zap those. llvm-svn: 125843
* Transform "A + B >= A + C" into "B >= C" if the adds do not wrap. Likewise ↵Duncan Sands2011-02-171-93/+106
| | | | | | | | | for some variations (some of these were already present so I unified the code). Spotted by my auto-simplifier as occurring a lot. llvm-svn: 125734
* remove a now-unneccesary cast.Chris Lattner2011-02-131-1/+1
| | | | llvm-svn: 125464
* implement instcombine folding for things like (x >> c) < 42.Chris Lattner2011-02-131-8/+50
| | | | | | We were previously simplifying divisions, but not right shifts! llvm-svn: 125454
* refactor some code out into a helper method.Chris Lattner2011-02-131-46/+54
| | | | llvm-svn: 125451
* Also fold (A+B) == A -> B == 0 when the add is commuted.Benjamin Kramer2011-02-111-2/+4
| | | | llvm-svn: 125411
* Enhance the "compare with shift" and "compare with div" Chris Lattner2011-02-101-44/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | optimizations to be much more aggressive in the face of exact/nsw/nuw div and shifts. For example, these (which are the same except the first is 'exact' sdiv: define i1 @sdiv_icmp4_exact(i64 %X) nounwind { %A = sdiv exact i64 %X, -5 ; X/-5 == 0 --> x == 0 %B = icmp eq i64 %A, 0 ret i1 %B } define i1 @sdiv_icmp4(i64 %X) nounwind { %A = sdiv i64 %X, -5 ; X/-5 == 0 --> x == 0 %B = icmp eq i64 %A, 0 ret i1 %B } compile down to: define i1 @sdiv_icmp4_exact(i64 %X) nounwind { %1 = icmp eq i64 %X, 0 ret i1 %1 } define i1 @sdiv_icmp4(i64 %X) nounwind { %X.off = add i64 %X, 4 %1 = icmp ult i64 %X.off, 9 ret i1 %1 } This happens when you do something like: (ptr1-ptr2) == 42 where the pointers are pointers to non-unit types. llvm-svn: 125266
* Recognize and simplifyAnders Carlsson2011-01-301-1/+11
| | | | | | | (A+B) == A -> B == 0 A == (A+B) -> B == 0 llvm-svn: 124567
* At -O123 the early-cse pass is run before instcombine has run. According to myDuncan Sands2011-01-201-32/+11
| | | | | | | | | | | | | | | | auto-simplier the transform most missed by early-cse is (zext X) != 0 -> X != 0. This patch adds this transform and some related logic to InstructionSimplify and removes some of the logic from instcombine (unfortunately not all because there are several situations in which instcombine can improve things by making new instructions, whereas instsimplify is not allowed to do this). At -O2 this often results in more than 15% more simplifications by early-cse, and results in hundreds of lines of bitcode being eliminated from the testsuite. I did see some small negative effects in the testsuite, for example a few additional instructions in three programs. One program, 483.xalancbmk, got an additional 35 instructions, which seems to be due to a function getting an additional instruction and then being inlined all over the place. llvm-svn: 123911
* remove the AllowAggressive argument to FoldOpIntoPhi. It is forced to false ↵Chris Lattner2011-01-161-2/+2
| | | | | | | | in the first line of the function because it isn't a good idea, even for compares. llvm-svn: 123566
* fix typoChris Lattner2011-01-151-1/+1
| | | | llvm-svn: 123516
* Catch ~x < cst just like ~x < ~y, we currently handle this throughChris Lattner2011-01-151-4/+8
| | | | | | means that are about to disappear. llvm-svn: 123515
* Remove dead variable, const-ref-ize an APInt.Owen Anderson2011-01-111-4/+1
| | | | llvm-svn: 123248
* Fix a random missed optimization by making InstCombine more aggressive when ↵Owen Anderson2011-01-111-2/+40
| | | | | | | | determining which bits are demanded by a comparison against a constant. llvm-svn: 123203
* recognize an unsigned add with overflow idiom into uadd.Chris Lattner2010-12-191-5/+50
| | | | | | | | | | | | | | | | | | | | | | | | | This resolves a README entry and technically resolves PR4916, but we still get poor code for the testcase in that PR because GVN isn't CSE'ing uadd with add, filed as PR8817. Previously we got: _test7: ## @test7 addq %rsi, %rdi cmpq %rdi, %rsi movl $42, %eax cmovaq %rsi, %rax ret Now we get: _test7: ## @test7 addq %rsi, %rdi movl $42, %eax cmovbq %rsi, %rax ret llvm-svn: 122182
* use IC.ReplaceInstUsesWith instead of a raw RAUW so that uses ofChris Lattner2010-12-191-3/+5
| | | | | | | | the old thing end up on the instcombine worklist. Not doing this can cause an extra top-level iteration of instcombine, burning compile time. llvm-svn: 122179
* generalize the sadd creation code to not require that theChris Lattner2010-12-191-39/+16
| | | | | | | | | | | | | | sadd formed is half the size of the original type. We can now compile this into a sadd.i8: unsigned char X(char a, char b) { int res = a+b; if ((unsigned )(res+128) > 255U) abort(); return res; } llvm-svn: 122178
* fix another miscompile in the llvm.sadd formation logic: it wasn't Chris Lattner2010-12-191-4/+39
| | | | | | | | | checking to see if the high bits of the original add result were dead. Inserting a smaller add and zexting back to that size is not good enough. This is likely to be the fix for 8816. llvm-svn: 122177
* fix a bug (possibly 8816) in the sadd forming xform: it isn'tChris Lattner2010-12-191-0/+10
| | | | | | | profitable (or safe) to promote code when the add-with-constant has other uses. llvm-svn: 122175
* rework the code added in r122072 to pull it out to its ownChris Lattner2010-12-191-61/+64
| | | | | | | helper function, clean up comments, and reduce indentation. No functionality change. llvm-svn: 122174
* Reapply r121905 (automatic synthesis of @llvm.sadd.with.overflow) with a fix ↵Owen Anderson2010-12-171-0/+73
| | | | | | | | | for a bug that manifested itself on the DragonEgg self-host bot. Unfortunately, the testcase is pretty messy and doesn't reduce well due to interactions with other parts of InstCombine. llvm-svn: 122072
* Speculatively revert commit 121905 since it looks like it might have broken theDuncan Sands2010-12-161-65/+0
| | | | | | | | | | | dragonegg self-host buildbot. Original commit message: Add an InstCombine transform to recognize instances of manual overflow-safe addition (performing the addition in a wider type and explicitly checking for overflow), and fold them down to intrinsics. This currently only supports signed-addition, but could be generalized if someone works out the magic constant formulas for other operations. llvm-svn: 121965
* Add an InstCombine transform to recognize instances of manual overflow-safe ↵Owen Anderson2010-12-151-0/+65
| | | | | | | | | | | | addition (performing the addition in a wider type and explicitly checking for overflow), and fold them down to intrinsics. This currently only supports signed-addition, but could be generalized if someone works out the magic constant formulas for other operations. Fixes <rdar://problem/8558713>. llvm-svn: 121905
* PR5207: Change APInt methods trunc(), sext(), zext(), sextOrTrunc() andJay Foad2010-12-071-6/+3
| | | | | | | | zextOrTrunc(), and APSInt methods extend(), extOrTrunc() and new method trunc(), to be const and to return a new value instead of modifying the object in place. llvm-svn: 121120
* PR5207: Rename overloaded APInt methods set(), clear(), flip() toJay Foad2010-12-011-2/+2
| | | | | | setAllBits(), setBit(unsigned), etc. llvm-svn: 120564
* duncan's spider sense was right, I completely reversed the conditionChris Lattner2010-11-231-8/+8
| | | | | | on this instcombine xform. This fixes a miscompilation of 403.gcc. llvm-svn: 119988
* optimize:Chris Lattner2010-11-211-2/+72
| | | | | | | | | void a(int x) { if (((1<<x)&8)==0) b(); } into "x != 3", which occurs over 100 times in 403.gcc but in no other program in llvm-test. llvm-svn: 119922
* PR7750: !CExpr->isNullValue() only properly computes whether CExpr is nonnullEli Friedman2010-07-291-1/+1
| | | | | | if CExpr is a ConstantInt. llvm-svn: 109773
* Convert some tab stops into spaces.Duncan Sands2010-07-121-1/+1
| | | | llvm-svn: 108130
* use ArgOperand APIGabor Greif2010-06-241-3/+3
| | | | llvm-svn: 106752
* Teach instCombine to remove malloc+free if malloc's only uses are comparisonsDuncan Sands2010-05-271-29/+0
| | | | | | to null. Patch by Matti Niemenmaa. llvm-svn: 104871
* Revert 101465, it broke internal OpenGL testing.Eric Christopher2010-04-161-3/+3
| | | | | | | Probably the best way to know that all getOperand() calls have been handled is to replace that API instead of updating. llvm-svn: 101579
OpenPOWER on IntegriCloud