summaryrefslogtreecommitdiff
path: root/test/Transforms/InstCombine/icmp.ll
Commit message (Collapse)AuthorAge
* Merging r168181: into 3.2 release branch.Pawel Wodnicki2012-11-21
| | | | | | | | | | | Fix PR14361: wrong simplification of A+B==B+A. You may think that the old logic replaced by this patch is equivalent to the new logic, but you'd be wrong, and that's exactly where the bug was. There's a similar bug in instsimplify which manifests itself as instsimplify failing to simplify this, rather than doing it wrong, see next commit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_32@168447 91177308-0d34-0410-b5e6-96231b3b80d8
* InstCombine: Turn (zext A) == (B & (1<<X)-1) into A == (trunc B), narrowing ↵Benjamin Kramer2012-06-10
| | | | | | | | | | | | | | | | | | | | the compare. This saves a cast, and zext is more expensive on platforms with subreg support than trunc is. This occurs in the BSD implementation of memchr(3), see PR12750. On the synthetic benchmark from that bug stupid_memchr and bsd_memchr have the same performance now when not inlining either function. stupid_memchr: 323.0us bsd_memchr: 321.0us memchr: 479.0us where memchr is the llvm-gcc compiled bsd_memchr from osx lion's libc. When inlining is enabled bsd_memchr still regresses down to llvm-gcc memchr time, I haven't fully understood the issue yet, something is grossly mangling the loop after inlining. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158297 91177308-0d34-0410-b5e6-96231b3b80d8
* Reinstate the optimization from r151449 with a fix to not turn 'gep %x' intoNick Lewycky2012-02-26
| | | | | | | 'gep null' when the icmp predicate is unsigned (or is signed without inbounds). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151467 91177308-0d34-0410-b5e6-96231b3b80d8
* Roll these back to r151448 until I figure out how they're breakingNick Lewycky2012-02-25
| | | | | | | MultiSource/Applications/lua. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151463 91177308-0d34-0410-b5e6-96231b3b80d8
* Teach instsimplify to be more aggressive when analyzing comparisons of pointersNick Lewycky2012-02-25
| | | | | | | | by using llvm::isIdentifiedObject. Also teach it to handle GEPs that have the same base pointer and constant operands. Fixes PR11238! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151449 91177308-0d34-0410-b5e6-96231b3b80d8
* InstCombine: Don't transform a signed icmp of two GEPs into a signed compare ↵Benjamin Kramer2012-02-21
| | | | | | | | | | | of the indices. This transformation is not safe in some pathological cases (signed icmp of pointers should be an extremely rare thing, but it's valid IR!). Add an explanatory comment. Kudos to Duncan for pointing out this edge case (and not giving up explaining it until I finally got it). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151055 91177308-0d34-0410-b5e6-96231b3b80d8
* Test case for r150978.Benjamin Kramer2012-02-20
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150979 91177308-0d34-0410-b5e6-96231b3b80d8
* InstCombine: When comparing two GEPs that were derived from the same base ↵Benjamin Kramer2012-02-20
| | | | | | | | pointer but use different types, expand the offset calculation and to the compare on the offset if profitable. This came up in SmallVector code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150962 91177308-0d34-0410-b5e6-96231b3b80d8
* Add r149110 back with a fix for when the vector and the int have the sameRafael Espindola2012-01-27
| | | | | | width. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149151 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r149110 and add a testcase that was crashing since that revision.Rafael Espindola2012-01-27
| | | | | | | Unfortunately I also had to disable constant-pool-sharing.ll the code it tests has been updated to use the IL logic. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149148 91177308-0d34-0410-b5e6-96231b3b80d8
* enhance constant folding to be able to constant fold bitcast of Chris Lattner2012-01-27
| | | | | | | ConstantVector's to integer type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149110 91177308-0d34-0410-b5e6-96231b3b80d8
* FileCheck hygiene.Benjamin Kramer2012-01-05
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147580 91177308-0d34-0410-b5e6-96231b3b80d8
* Improved fix for abs(val) != 0 to check other similar case. Also fixed ↵Pete Cooper2011-12-01
| | | | | | style issues and confusing comment git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145618 91177308-0d34-0410-b5e6-96231b3b80d8
* Removed use of grep from test and moved it to be with other icmp testsPete Cooper2011-12-01
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145570 91177308-0d34-0410-b5e6-96231b3b80d8
* PR10267: Don't combine an equality compare with an AND into an inequality ↵Benjamin Kramer2011-07-04
| | | | | | | | compare when the AND has more than one use. This can pessimize code, inequalities are generally more expensive. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134379 91177308-0d34-0410-b5e6-96231b3b80d8
* InstCombine: Fold A-b == C --> b == A-C if A and C are constants.Benjamin Kramer2011-06-13
| | | | | | The backend already knew this trick. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@132915 91177308-0d34-0410-b5e6-96231b3b80d8
* InstCombine: Shrink ((zext X) & C1) == C2 to fold away the cast if the ↵Benjamin Kramer2011-06-12
| | | | | | "zext" and the "and" have one use. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@132897 91177308-0d34-0410-b5e6-96231b3b80d8
* PR9838: Fix transform introduced in r127064 to not trigger when only one ↵Eli Friedman2011-05-05
| | | | | | side of the icmp is an exact shift. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130954 91177308-0d34-0410-b5e6-96231b3b80d8
* Transform: "icmp eq (trunc (lshr(X, cst1)), cst" to "icmp (and X, mask), cst"Chris Lattner2011-04-26
| | | | | | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130238 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix mistyped CHECK lines.Benjamin Kramer2011-03-09
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127366 91177308-0d34-0410-b5e6-96231b3b80d8
* Tweak this test. We can analyze what happens and show that we still do theNick Lewycky2011-03-07
| | | | | | | | right thing, instead of merely being unable to analyze and the transform doesn't occur. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127149 91177308-0d34-0410-b5e6-96231b3b80d8
* Add more analysis of the sign bit of an srem instruction. If the LHS is negativeNick Lewycky2011-03-07
| | | | | | | | then the result could go either way. If it's provably positive then so is the srem. Fixes PR9343 #7! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127146 91177308-0d34-0410-b5e6-96231b3b80d8
* ConstantInt has some getters which return ConstantInt's or ConstantVector's ofNick Lewycky2011-03-06
| | | | | | | | | 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! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127116 91177308-0d34-0410-b5e6-96231b3b80d8
* Thread comparisons over udiv/sdiv/ashr/lshr exact and lshr nuw/nsw wheneverNick Lewycky2011-03-05
| | | | | | | | | | 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! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127064 91177308-0d34-0410-b5e6-96231b3b80d8
* Try once again to optimize "icmp (srem X, Y), Y" by turning the comparison intoNick Lewycky2011-03-05
| | | | | | | true/false or "icmp slt/sge Y, 0". git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127063 91177308-0d34-0410-b5e6-96231b3b80d8
* Fold "icmp pred (srem X, Y), Y" like we do for urem. Handle signed comparisonsNick Lewycky2011-03-04
| | | | | | | | in the urem case, though not the other way around. This is enough to get #3 from PR9343! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126991 91177308-0d34-0410-b5e6-96231b3b80d8
* srem doesn't actually have the same resulting sign as its numerator, you couldNick Lewycky2011-02-28
| | | | | | | | also have a zero when numerator = denominator. Reverts parts of r126635 and r126637. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126644 91177308-0d34-0410-b5e6-96231b3b80d8
* Teach InstCombine to fold "(shr exact X, Y) == 0" --> X == 0, fixing #1 fromNick Lewycky2011-02-28
| | | | | | | PR9343. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126643 91177308-0d34-0410-b5e6-96231b3b80d8
* The sign of an srem instruction is the sign of its dividend (the firstNick Lewycky2011-02-28
| | | | | | | | argument), regardless of the divisor. Teach instcombine about this and fix test7 in PR9343! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126635 91177308-0d34-0410-b5e6-96231b3b80d8
* Add some transforms of the kind X-Y>X -> 0>Y which are valid when there is noDuncan Sands2011-02-18
| | | | | | | overflow. These subsume some existing equality transforms, so zap those. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125843 91177308-0d34-0410-b5e6-96231b3b80d8
* Transform "A + B >= A + C" into "B >= C" if the adds do not wrap. Likewise ↵Duncan Sands2011-02-17
| | | | | | | | | | for some variations (some of these were already present so I unified the code). Spotted by my auto-simplifier as occurring a lot. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125734 91177308-0d34-0410-b5e6-96231b3b80d8
* implement the first part of PR8882: when lowering an inboundsChris Lattner2011-02-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | gep to explicit addressing, we know that none of the intermediate computation overflows. This could use review: it seems that the shifts certainly wouldn't overflow, but could the intermediate adds overflow if there is a negative index? Previously the testcase would instcombine to: define i1 @test(i64 %i) { %p1.idx.mask = and i64 %i, 4611686018427387903 %cmp = icmp eq i64 %p1.idx.mask, 1000 ret i1 %cmp } now we get: define i1 @test(i64 %i) { %cmp = icmp eq i64 %i, 1000 ret i1 %cmp } git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125271 91177308-0d34-0410-b5e6-96231b3b80d8
* merge two tests.Chris Lattner2011-02-09
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125195 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix a random missed optimization by making InstCombine more aggressive when ↵Owen Anderson2011-01-11
| | | | | | | | | determining which bits are demanded by a comparison against a constant. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123203 91177308-0d34-0410-b5e6-96231b3b80d8
* duncan's spider sense was right, I completely reversed the conditionChris Lattner2010-11-23
| | | | | | | on this instcombine xform. This fixes a miscompilation of 403.gcc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119988 91177308-0d34-0410-b5e6-96231b3b80d8
* optimize:Chris Lattner2010-11-21
| | | | | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119922 91177308-0d34-0410-b5e6-96231b3b80d8
* Constant fold x == undef to undef.Dan Gohman2010-06-28
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@107074 91177308-0d34-0410-b5e6-96231b3b80d8
* fix incorrect folding of icmp with undef, PR6481.Chris Lattner2010-03-03
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97659 91177308-0d34-0410-b5e6-96231b3b80d8
* fix PR6195, a bug constant folding scalar -> vector compares.Chris Lattner2010-02-01
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94997 91177308-0d34-0410-b5e6-96231b3b80d8
* enhance x-(-A) -> x+A to preserve NUW/NSW.Chris Lattner2009-12-21
| | | | | | | | | | | | | Use the presence of NSW/NUW to fold "icmp (x+cst), x" to a constant in cases where it would otherwise be undefined behavior. Surprisingly (to me at least), this triggers hundreds of the times in a few benchmarks: lencode, ldecode, and 466.h264ref seem to *really* like this. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91812 91177308-0d34-0410-b5e6-96231b3b80d8
* Optimize all cases of "icmp (X+Cst), X" to something simpler. This triggersChris Lattner2009-12-21
| | | | | | | | a bunch in lencode, ldecod, spass, 176.gcc, 252.eon, among others. It is also the first part of PR5822 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91811 91177308-0d34-0410-b5e6-96231b3b80d8
* convert to filecheckChris Lattner2009-12-21
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91810 91177308-0d34-0410-b5e6-96231b3b80d8
* simplify a transformation by making it more general.Chris Lattner2009-10-11
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83792 91177308-0d34-0410-b5e6-96231b3b80d8
* Use opt -S instead of piping bitcode output through llvm-dis.Dan Gohman2009-09-08
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81257 91177308-0d34-0410-b5e6-96231b3b80d8
* Change these tests to feed the assembly files to opt directly, insteadDan Gohman2009-09-08
| | | | | | | of using llvm-as, now that opt supports this. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81226 91177308-0d34-0410-b5e6-96231b3b80d8
* fix PR4837, some bugs folding vector compares. TheseChris Lattner2009-09-02
| | | | | | | return a vector of i1, not i1 itself. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80761 91177308-0d34-0410-b5e6-96231b3b80d8
* Implement rdar://6480391, extending of equality icmp's to avoid a truncation.Chris Lattner2009-01-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I noticed this in the code compiled for a routine using std::map, which produced this code: %25 = tail call i32 @memcmp(i8* %24, i8* %23, i32 6) nounwind readonly %.lobit.i = lshr i32 %25, 31 ; <i32> [#uses=1] %tmp.i = trunc i32 %.lobit.i to i8 ; <i8> [#uses=1] %toBool = icmp eq i8 %tmp.i, 0 ; <i1> [#uses=1] br i1 %toBool, label %bb3, label %bb4 which compiled to: call L_memcmp$stub shrl $31, %eax testb %al, %al jne LBB1_11 ## with this change, we compile it to: call L_memcmp$stub testl %eax, %eax js LBB1_11 This triggers all the time in common code, with patters like this: %169 = and i32 %ply, 1 ; <i32> [#uses=1] %170 = trunc i32 %169 to i8 ; <i8> [#uses=1] %toBool = icmp ne i8 %170, 0 ; <i1> [#uses=1] %7 = lshr i32 %6, 24 ; <i32> [#uses=1] %9 = trunc i32 %7 to i8 ; <i8> [#uses=1] %10 = icmp ne i8 %9, 0 ; <i1> [#uses=1] etc git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61985 91177308-0d34-0410-b5e6-96231b3b80d8
* For PR1319:Reid Spencer2007-04-14
| | | | | | | Upgrade tests to work with new llvm.exp version of llvm_runtest. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36013 91177308-0d34-0410-b5e6-96231b3b80d8
* sext of compares.Chris Lattner2007-04-11
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35892 91177308-0d34-0410-b5e6-96231b3b80d8
* new testcaseChris Lattner2007-04-11
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35889 91177308-0d34-0410-b5e6-96231b3b80d8