summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
Commit message (Collapse)AuthorAgeFilesLines
* We require threse bits to be zero, too.Benjamin Kramer2011-04-281-2/+2
| | | | | | | This shouldn't happen in practice because the icmp would be a constant. Add a check so we don't miscompile code if something goes wrong. llvm-svn: 130446
* Fix a comment.Benjamin Kramer2011-04-281-1/+1
| | | | llvm-svn: 130428
* InstCombine: Merge "(trunc x) == C1 & (and x, CA) == C2" into a single and+icmp.Benjamin Kramer2011-04-281-0/+36
| | | | | | This happens when GVN widens loads. Part of PR6627. llvm-svn: 130405
* Fix a ton of comment typos found by codespell. Patch byChris Lattner2011-04-151-1/+1
| | | | | | Luis Felipe Strano Moraes! llvm-svn: 129558
* Add an instcombine for constructs like a | -(b != c); a select is moreEli Friedman2011-04-141-1/+8
| | | | | | | canonical, and generally leads to better code. Found while looking at an article about saturating arithmetic. llvm-svn: 129545
* InstCombine: Add a few missing combines for ANDs and ORs of sign bit tests.Benjamin Kramer2011-03-291-0/+24
| | | | | | | | On x86 we now compile "if (a < 0 && b < 0)" into testl %edi, %esi js IF.THEN llvm-svn: 128496
* Make InstCombiner::FoldAndOfICmps create a ConstantRange that's theAnders Carlsson2011-03-011-8/+12
| | | | | | | | | intersection of the LHS and RHS ConstantRanges and return "false" when the range is empty. This simplifies some code and catches some extra cases. llvm-svn: 126744
* Move "A | ~(A & ?) -> -1" from InstCombine to InstructionSimplify.Benjamin Kramer2011-02-201-16/+8
| | | | llvm-svn: 126082
* InstCombine: Add a bunch of combines of the form x | (y ^ z).Benjamin Kramer2011-02-201-0/+41
| | | | | | | | | We usually catch this kind of optimization through InstSimplify's distributive magic, but or doesn't distribute over xor in general. "A | ~(A | B) -> A | ~B" hits 24 times on gcc.c. llvm-svn: 126081
* Fix 9216 - Endless loop in InstCombine pass.Nadav Rotem2011-02-151-1/+5
| | | | | | | The pattern "A&(A^B) -> A & ~B" recreated itself because ~B is actually a xor -1. llvm-svn: 125557
* tidy up a bit.Chris Lattner2011-02-151-7/+9
| | | | llvm-svn: 125546
* more cleanups, notably bitcast isn't used for "signed to unsigned type Chris Lattner2011-02-101-45/+27
| | | | | | conversions". :) llvm-svn: 125265
* Rework InstrTypes.h so to reduce the repetition around the NSW/NUW/ExactChris Lattner2011-02-091-2/+2
| | | | | | | | | | | | | | | | | versions of creation functions. Eventually, the "insertion point" versions of these should just be removed, we do have IRBuilder afterall. Do a massive rewrite of much of pattern match. It is now shorter and less redundant and has several other widgets I will be using in other patches. Among other changes, m_Div is renamed to m_IDiv (since it only matches integer divides) and m_Shift is gone (it used to match all binops!!) and we now have m_LogicalShift for the one client to use. Enhance IRBuilder to have "isExact" arguments to things like CreateUDiv and reduce redundancy within IRbuilder by having these methods chain to each other more instead of duplicating code. llvm-svn: 125194
* Just because we have determined that an (fcmp | fcmp) is true for A < B,Owen Anderson2011-01-211-1/+3
| | | | | | | A == B, and A > B, does not mean we can fold it to true. We still need to check for A ? B (A unordered B). llvm-svn: 123993
* reduce indentationChris Lattner2011-01-151-29/+29
| | | | llvm-svn: 123514
* Add a generic expansion transform: A op (B op' C) -> (A op B) op' (A op C)Duncan Sands2010-12-221-6/+9
| | | | | | | | if both A op B and A op C simplify. This fires fairly often but doesn't make that much difference. On gcc-as-one-file it removes two "and"s and turns one branch into a select. llvm-svn: 122399
* Add a check missing from my last commit and avoid a potential overflow ↵Benjamin Kramer2010-12-201-3/+3
| | | | | | situation. llvm-svn: 122258
* Reduce indentation.Benjamin Kramer2010-12-201-7/+5
| | | | llvm-svn: 122249
* Teach InstCombine to merge (icmp ult (X + CA), C1) | (icmp eq X, C2) into ↵Benjamin Kramer2010-12-201-1/+10
| | | | | | | | | | | | | | | (icmp ult (X + CA), C1 + 1) if C2 + CA == C1. InstCombine creates these so now we compile x == 23 || x == 24 || x == 25 to %x.off = add i32 %x, -23 %1 = icmp ult i32 %x.off, 3 instead of %x.off = add i32 %x, -23 %1 = icmp ult i32 %x.off, 2 %cmp3 = icmp eq i32 %x, 25 %ret2 = or i1 %1, %cmp3 llvm-svn: 122248
* Rename SimplifyDistributed to the more meaningfull name SimplifyByFactorizing.Duncan Sands2010-11-231-3/+3
| | | | llvm-svn: 120051
* Exploit distributive laws (eg: And distributes over Or, Mul over Add, etc) in aDuncan Sands2010-11-231-42/+11
| | | | | | | | | | | | fairly systematic way in instcombine. Some of these cases were already dealt with, in which case I removed the existing code. The case of Add has a bunch of funky logic which covers some of this plus a few variants (considers shifts to be a form of multiplication), which I didn't touch. The simplification performed is: A*B+A*C -> A*(B+C). The improvement is to do this in cases that were not already handled [such as A*B-A*C -> A*(B-C), which was reported on the mailing list], and also to do it more often by not checking for "only one use" if "B+C" simplifies. llvm-svn: 120024
* Move some those Xor simplifications which don't require creating newDuncan Sands2010-11-171-31/+2
| | | | | | | | 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. llvm-svn: 119536
* Generalize the reassociation transform in SimplifyCommutative (now renamed toDuncan Sands2010-11-131-3/+3
| | | | | | | | | | | | | | | | SimplifyAssociativeOrCommutative) "(A op C1) op C2" -> "A op (C1 op C2)", which previously was only done if C1 and C2 were constants, to occur whenever "C1 op C2" simplifies (a la InstructionSimplify). Since the simplifying operand combination can no longer be assumed to be the right-hand terms, consider all of the possible permutations. When compiling "gcc as one big file", transform 2 (i.e. using right-hand operands) fires about 4000 times but it has to be said that most of the time the simplifying operands are both constants. Transforms 3, 4 and 5 each fired once. Transform 6, which is an existing transform that I didn't change, never fired. With this change, the testcase is now optimized perfectly with one run of instcombine (previously it required instcombine + reassociate + instcombine, and it may just have been luck that this worked). llvm-svn: 119002
* Re-apply r113679, which was reverted in r113720, which added a paid of new ↵Owen Anderson2010-09-131-5/+31
| | | | | | | | | instcombine transforms to expose greater opportunities for store narrowing in codegen. This patch fixes a potential infinite loop in instcombine caused by one of the introduced transforms being overly aggressive. llvm-svn: 113763
* Revert 113679, it was causing an infinite loop in a testcase that I've sentEric Christopher2010-09-121-30/+5
| | | | | | on to Owen. llvm-svn: 113720
* Invert and-of-or into or-of-and when doing so would allow us to clear bits ↵Owen Anderson2010-09-111-5/+30
| | | | | | | | | | | | | | of the and's mask. This can result in increased opportunities for store narrowing in code generation. Update a number of tests for this change. This fixes <rdar://problem/8285027>. Additionally, because this inverts the order of ors and ands, some patterns for optimizing or-of-and-of-or no longer fire in instances where they did originally. Add a simple transform which recaptures most of these opportunities: if we have an or-of-constant-or and have failed to fold away the inner or, commute the order of the two ors, to give the non-constant or a chance for simplification instead. llvm-svn: 113679
* This transform is also performed by InstructionSimplify, remove the duplicate.Benjamin Kramer2010-09-101-3/+0
| | | | llvm-svn: 113608
* Generalize instcombine's support for combining multiple bit checks into a ↵Owen Anderson2010-09-081-32/+278
| | | | | | single test. Patch by Dirk Steinke! llvm-svn: 113423
* Re-apply the infamous r108614, with a fix pointed out by Dirk Steinke.Owen Anderson2010-08-021-5/+38
| | | | llvm-svn: 110036
* Speculatively revert r108614, "Another attempt at getting the clang self-host toDaniel Dunbar2010-07-311-32/+0
| | | | | | | like my instcombine patch.", in an attempt to fix Clang i386 bootstrap. - Also PR7719. llvm-svn: 109953
* Another attempt at getting the clang self-host to like my instcombine patch.Owen Anderson2010-07-171-0/+32
| | | | llvm-svn: 108614
* Also revert 108422, it's causing some test failures.Eric Christopher2010-07-161-19/+0
| | | | | | Working on testcases for Owen. llvm-svn: 108494
* Speculatively revert r108429 to fix the clang self-host.Owen Anderson2010-07-151-19/+0
| | | | llvm-svn: 108436
* Per Chris' suggestion, get rid of the select canonicalization and just addOwen Anderson2010-07-151-0/+19
| | | | | | | | the corresponding or-icmp-and pattern. This has the added benefit of doing the matching earlier, and thus being less susceptible to being confused by earlier transforms. llvm-svn: 108429
* Reapply r108378, with bugfixes, testcase, and improved comment formatting.Owen Anderson2010-07-151-0/+19
| | | | | | This now passes LIT, nighty test, and llvm-gcc bootstrap on my machine. llvm-svn: 108422
* Speculatively revert r108378; may be causing bootstrap failures.Eli Friedman2010-07-151-18/+0
| | | | llvm-svn: 108389
* Add instcombine transforms to optimize tests of multiple bits of the same ↵Owen Anderson2010-07-141-0/+18
| | | | | | value into a single larger comparison. llvm-svn: 108378
* revert r108320, I see the failures now...Chris Lattner2010-07-141-8/+0
| | | | llvm-svn: 108322
* reapply benjamin's instcombine patch, I don't see anything wrong with it and ↵Chris Lattner2010-07-141-0/+8
| | | | | | can't repro any problems with a manual self-host. llvm-svn: 108320
* Nope, still breaks the release selfhost bots :(Benjamin Kramer2010-07-121-8/+0
| | | | llvm-svn: 108153
* Reapply the "or" half of r108136, which seems to be less problematic.Benjamin Kramer2010-07-121-0/+8
| | | | llvm-svn: 108152
* Revert r108141 again, sigh.Benjamin Kramer2010-07-121-17/+0
| | | | llvm-svn: 108148
* Reapply 108136 with an ugly pasto fixed.Benjamin Kramer2010-07-121-0/+17
| | | | llvm-svn: 108141
* Move optimization to avoid redundant matching.Benjamin Kramer2010-07-121-13/+13
| | | | llvm-svn: 108140
* Revert r108136 until I figure out why it broke selfhost.Benjamin Kramer2010-07-121-17/+0
| | | | llvm-svn: 108139
* instcombine: fold (x & y) | (~x & z) and (x & y) ^ (~x & z) into ((y ^ z) & ↵Benjamin Kramer2010-07-121-0/+17
| | | | | | | | | | | | | | | | | x) ^ z which is one instruction shorter. (PR6773) before: %and = and i32 %y, %x %neg = xor i32 %x, -1 %and4 = and i32 %z, %neg %xor = xor i32 %and4, %and after: %xor1 = xor i32 %z, %y %and2 = and i32 %xor1, %x %xor = xor i32 %and2, %z llvm-svn: 108136
* Minor code simplification.Dan Gohman2010-04-091-9/+5
| | | | llvm-svn: 100859
* Fix PR6503. This turned into a much more interesting and nasty bug. Various Chris Lattner2010-03-051-125/+92
| | | | | | | | | | | parts of the cmp|cmp and cmp&cmp folding logic wasn't prepared for vectors (unrelated to the bug but noticed while in the code) and the code was *definitely* not safe to use by the (cast icmp)|(cast icmp) handling logic that I added in r95855. Fix all this up by changing the various routines to more consistently use IRBuilder and not pass in the I which had the wrong type. llvm-svn: 97801
* simplify some functions and make them work with vectorChris Lattner2010-03-051-62/+25
| | | | | | compares, noticed by inspection. llvm-svn: 97795
* This test case:Bill Wendling2010-03-031-2/+4
| | | | | | | | | | | | | | | | | | | | | long test(long x) { return (x & 123124) | 3; } Currently compiles to: _test: orl $3, %edi movq %rdi, %rax andq $123127, %rax ret This is because instruction and DAG combiners canonicalize (or (and x, C), D) -> (and (or, D), (C | D)) However, this is only profitable if (C & D) != 0. It gets in the way of the 3-addressification because the input bits are known to be zero. llvm-svn: 97616
OpenPOWER on IntegriCloud