summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/InstSimplify
Commit message (Collapse)AuthorAgeFilesLines
...
* [InstSimplify] add folds for constant mask of value shifted by constantSanjay Patel2017-05-161-8/+4
| | | | | | | | | | | | | | | | | We would eventually catch these via demanded bits and computing known bits in InstCombine, but I think it's better to handle the simple cases as soon as possible as a matter of efficiency. This fold allows further simplifications based on distributed ops transforms. eg: %a = lshr i8 %x, 7 %b = or i8 %a, 2 %c = and i8 %b, 1 InstSimplify can directly fold this now: %a = lshr i8 %x, 7 Differential Revision: https://reviews.llvm.org/D33221 llvm-svn: 303213
* [InstSimplify] add tests for unnecessary mask of shifted values; NFCSanjay Patel2017-05-151-0/+67
| | | | llvm-svn: 303127
* [InstSimplify] restrict icmp fold with 2 sdiv exact operands (PR32949)Sanjay Patel2017-05-151-2/+5
| | | | | | | | | | | | | | | | | | | | These folds were introduced with https://reviews.llvm.org/rL127064 as part of solving: https://bugs.llvm.org/show_bug.cgi?id=9343 As shown here: http://rise4fun.com/Alive/C8 ...however, the sdiv exact case needs a stronger predicate. I opted for duplicated code instead of adding another fallthrough because I think that's easier to read (and edit in case we need/want to restrict/loosen the predicates any more). This should fix: https://bugs.llvm.org/show_bug.cgi?id=32949 https://bugs.llvm.org/show_bug.cgi?id=32948 Differential Revision: https://reviews.llvm.org/D32954 llvm-svn: 303104
* [InstSimplify] Add patterns for folding (A & B) | (~A ^ B) -> (~A ^ B) and ↵Craig Topper2017-05-141-32/+16
| | | | | | | | its commuted variants. We already had (A & ~B) | (A ^ B), but we missed the cases where the not was part of the xor. llvm-svn: 303004
* fooCraig Topper2017-05-141-0/+122
| | | | llvm-svn: 303003
* [InstSimplify, InstCombine] move 'or' simplification tests; NFCSanjay Patel2017-05-102-72/+181
| | | | | | | Surprisingly, I don't think these are redundant for InstSimplify. They were just misplaced as InstCombine tests. llvm-svn: 302684
* [InstSimplify] add tests for PR32949 miscompile; NFCSanjay Patel2017-05-071-2/+27
| | | | llvm-svn: 302374
* InstructionSimplify: Relanding r301766Zvi Rackover2017-05-071-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Re-applying r301766 with a fix to a typo and a regression test. The log message for r301766 was: ================================================================================== InstructionSimplify: Canonicalize shuffle operands. NFC-ish. Summary: Apply canonicalization rules: 1. Input vectors with no elements selected from can be replaced with undef. 2. If only one input vector is constant it shall be the second one. This allows constant-folding to cover more ad-hoc simplifications that were in place and avoid duplication for RHS and LHS checks. There are more rules we may want to add in the future when we see a justification. e.g. mask elements that select undef elements can be replaced with undef. ================================================================================== Reviewers: spatel, RKSimon Reviewed By: spatel Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32863 llvm-svn: 302373
* [InstSimplify] use ConstantRange to simplify or-of-icmpsSanjay Patel2017-05-071-420/+126
| | | | | | | | | | | | | We can simplify (or (icmp X, C1), (icmp X, C2)) to 'true' or one of the icmps in many cases. I had to check some of these with Alive to prove to myself it's right, but everything seems to check out. Eg, the deleted code in instcombine was completely ignoring predicates with mismatched signedness. This is a follow-up to: https://reviews.llvm.org/rL301260 https://reviews.llvm.org/D32143 llvm-svn: 302370
* [InstSimplify] fix copy-paste mistake in test comments; NFCSanjay Patel2017-05-051-200/+200
| | | | llvm-svn: 302251
* [InstSimplify] add tests for (icmp X, C1 | icmp X, C2); NFCSanjay Patel2017-05-051-0/+3020
| | | | | | These are the 'or' counterparts for the tests added with r300493. llvm-svn: 302248
* [InstSimplify] add folds for or-of-casted-icmpsSanjay Patel2017-05-041-15/+2
| | | | | | | | | | | | | | | | | The sibling folds for 'and' with casts were added with https://reviews.llvm.org/rL273200. This is a preliminary step for adding the 'or' variants for the folds added with https://reviews.llvm.org/rL301260. The reason for the strange form with constant LHS in the 1st test is because there's another missing fold in that case for the inverted predicate. That should be fixed when we add the ConstantRange functionality for 'or-of-icmps' that already exists for 'and-of-icmps'. I'm hoping to share more code for the and/or cases, so we won't have these differences. This will allow us to remove code from InstCombine. It's also possible that we can remove some code here in InstSimplify. I think we have some duplicated folds because patterns are not matched in a general way. Differential Revision: https://reviews.llvm.org/D32876 llvm-svn: 302189
* [InstSimplify] add tests for or-of-casted-icmps; NFCSanjay Patel2017-05-041-0/+58
| | | | llvm-svn: 302174
* Revert r301880George Burgess IV2017-05-011-19/+0
| | | | | | | | | This change caused buildbot failures, apparently because we're not passing around types that InstSimplify is used to seeing. I'm not overly familiar with InstSimplify, so I'm reverting this until I can figure out what exactly is wrong. llvm-svn: 301885
* [InstSimplify] Handle selects of GEPs with 0 offsetGeorge Burgess IV2017-05-011-0/+19
| | | | | | | | | In particular (since it wouldn't fit nicely in the summary): (select (icmp eq V 0) P (getelementptr P V)) -> (getelementptr P V) Differential Revision: https://reviews.llvm.org/D31435 llvm-svn: 301880
* InstructionSimplify: Simplify a shuffle with a undef mask to undefZvi Rackover2017-04-301-0/+8
| | | | | | | | | | | | | | | | Summary: Following the discussion in pr32486, adding the simplification: shuffle %x, %y, undef -> undef Reviewers: spatel, RKSimon, andreadb, davide Reviewed By: spatel Subscribers: jroelofs, davide, llvm-commits Differential Revision: https://reviews.llvm.org/D32293 llvm-svn: 301764
* [InstCombine] Fix CHECK-LABEL in two tests.Craig Topper2017-04-251-2/+2
| | | | llvm-svn: 301337
* [InstSimplify] Handle (~A & ~B) | (~A ^ B) -> ~A ^ BCraig Topper2017-04-251-0/+62
| | | | | | | | | | The code Sanjay Patel moved over from InstCombine doesn't work properly if the 'and' has both inputs as nots because we used a commuted op matcher on the 'and' first. But this will bind to the first 'not' on 'and' when there could be two 'not's. InstCombine could rely on DeMorgan to ensure the 'and' wouldn't have two 'not's eventually, but InstSimplify can't rely on that. This patch matches the xor first then checks for the ands and allows a not of either operand of the xor. Differential Revision: https://reviews.llvm.org/D32458 llvm-svn: 301329
* [InstSimplify] use ConstantRange to simplify more and-of-icmpsSanjay Patel2017-04-241-252/+84
| | | | | | | | | | | | | We can simplify (and (icmp X, C1), (icmp X, C2)) to one of the icmps in many cases. I had to check some of these with Alive to prove to myself it's right, but everything seems to check out. Eg, the code in instcombine was completely ignoring predicates with mismatched signedness. Handling or-of-icmps would be a follow-up step. Differential Revision: https://reviews.llvm.org/D32143 llvm-svn: 301260
* [InstSimplify] move (A & ~B) | (A ^ B) -> (A ^ B) from InstCombineSanjay Patel2017-04-241-0/+53
| | | | | | | | | | | This is a straight cut and paste, but there's a bigger problem: if this fold exists for simplifyOr, there should be a DeMorganized version for simplifyAnd. But more than that, we have a patchwork of ad hoc logic optimizations in InstCombine. There should be some structure to ensure that we're not missing sibling folds across and/or/xor. llvm-svn: 301213
* [InstSimplify] fold identity shuffles (recursing if needed)Sanjay Patel2017-04-191-26/+41
| | | | | | | | | | | | | | | | | This patch simplifies the examples from D31509 and D31927 (PR30630) and catches the basic identity shuffle tests that Zvi recently added. I'm not sure if we have something like this in DAGCombiner, but we should? It's worth noting that "MaxRecurse / RecursionLimit" is only 3 on entry at the moment. We might want to bump that up if there are longer shuffle chains like this in the wild. For now, we're ignoring shuffles that have undef mask elements because it's not clear how those should be handled. Differential Revision: https://reviews.llvm.org/D31960 llvm-svn: 300714
* [InstSimplify] Deduce correct type for vector GEP.Davide Italiano2017-04-191-1/+25
| | | | | | | | | | InstSimplify returned the wrong type when simplifying a vector GEP and we ended up crashing when trying to replace all uses with the new value. Fixes PR32697. Differential Revision: https://reviews.llvm.org/D32180 llvm-svn: 300693
* [InstSimplify] add/move tests for (icmp X, C1 & icmp X, C2); NFCSanjay Patel2017-04-172-20/+2912
| | | | | | We simplify based on range intersection, but we're missing folds. llvm-svn: 300493
* InstSimplify: A shuffle of a splat is always the splat itselfZvi Rackover2017-04-111-2/+75
| | | | | | | | | | | | | | | | Summary: Fold: shuffle (splat-shuffle), undef, M --> splat-shuffle Reviewers: spatel, RKSimon, craig.topper Reviewed By: RKSimon Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D31527 llvm-svn: 299990
* [InstSimplify] add tests for chains of shuffles; NFCSanjay Patel2017-04-111-0/+45
| | | | llvm-svn: 299984
* [InstSimplify] Teach SimplifyMulInst to recognize vectors of i1 as And. Not ↵Craig Topper2017-04-061-0/+11
| | | | | | just scalar i1. llvm-svn: 299665
* [InstSimplify] Add test cases for mixing add/sub i1 with xor of i1. Seems we ↵Craig Topper2017-04-061-0/+42
| | | | | | can simplify in one direction but not the other. llvm-svn: 299627
* [InstSimplify] Teach SimplifyAddInst and SimplifySubInst that vectors of i1 ↵Craig Topper2017-04-061-0/+36
| | | | | | can be treated as Xor too. llvm-svn: 299626
* InstSimplify: Add a hook for shufflevectorZvi Rackover2017-04-031-6/+20
| | | | | | | | | | | | | | | | | | Summary: Add a hook for simplification of shufflevector's with the following rules: - Constant folding - NFC, as it was already being done by the default handler. - If only one of the operands is constant, constant fold the shuffle if the mask does not select elements from the variable operand - to show the hook is firing and affecting the test-cases. Reviewers: RKSimon, craig.topper, spatel, sanjoy, nlopes, majnemer Reviewed By: spatel Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D31525 llvm-svn: 299393
* Add another interesting shufflevector test case for InstSimplify. NFC.Zvi Rackover2017-04-021-0/+9
| | | | | | | Test case shows opportunity to constant fold a shuffle with one variable input vector operand. llvm-svn: 299327
* [InstSimplify] add constant folding for fdiv/fremSanjay Patel2017-04-011-4/+2
| | | | | | Also, add a helper function so we don't have to repeat this code for each binop. llvm-svn: 299309
* [InstSimplify] add tests for missed constant folding; NFCSanjay Patel2017-04-011-3/+21
| | | | llvm-svn: 299308
* Instsimplify: Adding shufflevector test. NFC.Zvi Rackover2017-03-311-0/+71
| | | | | | | Adding some test-cases demonstrating cases that need to be improved. To be followed by patches that improve these cases. llvm-svn: 299189
* [InstSimplify] allow folds for bool vector div/remSanjay Patel2017-03-092-10/+6
| | | | llvm-svn: 297411
* [ConstantFold] vector div/rem with any zero element in divisor is undefSanjay Patel2017-03-092-4/+4
| | | | | | | | Follow-up for: https://reviews.llvm.org/D30665 https://reviews.llvm.org/rL297390 llvm-svn: 297409
* [InstSimplify] add tests for vector constant folding div/rem-by-0; NFCSanjay Patel2017-03-092-0/+32
| | | | llvm-svn: 297407
* [InstSimplify] vector div/rem with any zero element in divisor is undefSanjay Patel2017-03-092-10/+6
| | | | | | | | | | | This was suggested as a DAG simplification in the review for rL297026 : http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20170306/435253.html ...but let's start with IR since we have actual docs for IR (LangRef). Differential Revision: https://reviews.llvm.org/D30665 llvm-svn: 297390
* [InstSimplify] add tests for vector div/rem with UB potential; NFCSanjay Patel2017-03-062-0/+84
| | | | llvm-svn: 297048
* [InstSimplify] regenerate checks; NFCSanjay Patel2017-03-062-16/+16
| | | | llvm-svn: 297040
* [InstSimplify] add nsw/nuw (xor X, signbit), signbit --> XSanjay Patel2017-02-181-6/+2
| | | | | | | | | The change to InstCombine in: https://reviews.llvm.org/D29729 ...exposes this missing fold in InstSimplify, so adding this first to avoid a regression. llvm-svn: 295573
* [InstSimplify] add tests for add nsw/nuw (xor X, signbit), signbit --> X; NFCSanjay Patel2017-02-181-0/+26
| | | | llvm-svn: 295572
* [ValueTracking] emit a remark when we detect a conflicting assumption (PR31809)Sanjay Patel2017-02-061-5/+28
| | | | | | | | | | | | This is a follow-up to D29395 where we try to be good citizens and let the user know that we've probably gone off the rails. This should allow us to resolve: https://llvm.org/bugs/show_bug.cgi?id=31809 Differential Revision: https://reviews.llvm.org/D29404 llvm-svn: 294208
* [ValueTracking] remove a FIXME for something we don't want to do; NFCSanjay Patel2017-02-011-2/+1
| | | | | | | | The comment was added with: https://reviews.llvm.org/rL293773 ...but there would be a cost to implement this and possibly no payoff. llvm-svn: 293823
* [ValueTracking] avoid crashing from bad assumptions (PR31809)Sanjay Patel2017-02-011-0/+36
| | | | | | | | | | | | | A program may contain llvm.assume info that disagrees with other analysis. This may be caused by UB in the program, so we must not crash because of that. As noted in the code comments: https://llvm.org/bugs/show_bug.cgi?id=31809 ...we can do better, but this at least avoids the assert/crash in the bug report. Differential Revision: https://reviews.llvm.org/D29395 llvm-svn: 293773
* [ValueTracking] Implement SignBitMustBeZero correctly for sqrt.Justin Lebar2017-01-261-0/+54
| | | | | | | | | | | | | | Summary: Previously we assumed that the result of sqrt(x) always had 0 as its sign bit. But sqrt(-0) == -0. Reviewers: hfinkel, efriedma, sanjoy Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D28928 llvm-svn: 293115
* [InstSimplify] try to eliminate icmp Pred (add nsw X, C1), C2Sanjay Patel2017-01-241-21/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I was surprised to see that we're missing icmp folds based on 'add nsw' in InstCombine, but we should handle the InstSimplify cases first because that could make the InstCombine code simpler. Here are Alive-based proofs for the logic: Name: add_neg_constant Pre: C1 < 0 && (C2 > ((1<<(width(C1)-1)) + C1)) %a = add nsw i7 %x, C1 %b = icmp sgt %a, C2 => %b = false Name: add_pos_constant Pre: C1 > 0 && (C2 < ((1<<(width(C1)-1)) + C1 - 1)) %a = add nsw i6 %x, C1 %b = icmp slt %a, C2 => %b = false Name: nuw Pre: C1 u>= C2 %a = add nuw i11 %x, C1 %b = icmp ult %a, C2 => %b = false Differential Revision: https://reviews.llvm.org/D29053 llvm-svn: 292952
* [InstSimplify] add tests to show missing folds from 'icmp (add nsw)'; NFCSanjay Patel2017-01-231-0/+169
| | | | llvm-svn: 292841
* [ValueTracking] Extend known bits to understand @llvm.bitreverse.Chad Rosier2017-01-171-0/+31
| | | | | | Differential Revision: https://reviews.llvm.org/D28780 llvm-svn: 292233
* [InstCombine / InstSimplify] add and move tests for lshr transforms; NFCSanjay Patel2017-01-131-0/+43
| | | | llvm-svn: 291970
* [InstCombine] if the condition of a select may be known via assumes, ↵Sanjay Patel2017-01-131-1/+2
| | | | | | | | | | | | | | | | | | | | eliminate the select This is a limited solution for PR31512: https://llvm.org/bugs/show_bug.cgi?id=31512 The motivation is that we will need to increase usage of llvm.assume and/or metadata to solve PR28430: https://llvm.org/bugs/show_bug.cgi?id=28430 ...and this kind of simplification is needed to take advantage of that extra information. The 'not' test case would be handled by: https://reviews.llvm.org/D28485 Differential Revision: https://reviews.llvm.org/D28337 llvm-svn: 291915
OpenPOWER on IntegriCloud