summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [ValueTracking][InstCombine] Use m_Shr instead m_CombineOr(m_LShr, m_AShr). NFCCraig Topper2017-06-241-2/+1
| | | | llvm-svn: 306205
* [InstCombine] lshr (sext iM X to iN), N-M --> zext (ashr X, min(N-M, M-1)) to iNSanjay Patel2017-06-121-4/+10
| | | | | | | | | | | | | | | | | | | This is a follow-up to https://reviews.llvm.org/D33879 / https://reviews.llvm.org/rL304939 , and was discussed in https://reviews.llvm.org/D33338. We prefer this form because a narrower shift may be cheaper, and we can more easily fold a zext than a sext. http://rise4fun.com/Alive/slVe Name: shz %s = sext i8 %x to i12 %r = lshr i12 %s, 4 => %a = ashr i8 %x, 4 %r = zext i8 %a to i12 llvm-svn: 305190
* [InstCombine] Pass a proper context instruction to all of the calls into ↵Craig Topper2017-06-091-4/+7
| | | | | | | | | | | | | | | | InstSimplify Summary: This matches the behavior we already had for compares and makes us consistent everywhere. Reviewers: dberlin, hfinkel, spatel Reviewed By: dberlin Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D33604 llvm-svn: 305049
* [InstCombine] fold lshr (sext X), C1 --> zext (lshr X, C2)Sanjay Patel2017-06-071-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This was discussed in D33338. We have larger pattern-matching ending in a truncate that we can reduce or remove by handling these smaller patterns first. Further motivation is that narrower shift ops are easier for value tracking and zext is better than sext. http://rise4fun.com/Alive/rhh Name: boolshift %sext = sext i1 %x to i8 %r = lshr i8 %sext, 7 => %r = zext i1 %x to i8 Name: noboolshift %sext = sext i3 %x to i8 %r = lshr i8 %sext, 7 => %sh = lshr i3 %x, 2 %r = zext i3 %sh to i8 Differential Revision: https://reviews.llvm.org/D33879 llvm-svn: 304939
* [InstCombine] Pass the DominatorTree, AssumptionCache, and context ↵Craig Topper2017-05-261-1/+2
| | | | | | | | | | instruction to a few calls to isKnownPositive, isKnownNegative, and isKnownNonZero Every other place in InstCombine that uses these methods in ValueTracking already pass this information. This makes the remaining sites consistent. Differential Revision: https://reviews.llvm.org/D33567 llvm-svn: 304018
* InstCombine: Use the new SimplifyQuery versions of Simplify*. Use ↵Daniel Berlin2017-04-261-3/+3
| | | | | | AssumptionCache, DominatorTree, TargetLibraryInfo everywhere. llvm-svn: 301464
* [APInt] Rename getSignBit to getSignMaskCraig Topper2017-04-201-1/+1
| | | | | | | | getSignBit is a static function that creates an APInt with only the sign bit set. getSignMask seems like a better name to convey its functionality. In fact several places use it and then store in an APInt named SignMask. Differential Revision: https://reviews.llvm.org/D32108 llvm-svn: 300856
* [APInt] Use lshrInPlace to replace lshr where possibleCraig Topper2017-04-181-1/+1
| | | | | | | | | | This patch uses lshrInPlace to replace code where the object that lshr is called on is being overwritten with the result. This adds an lshrInPlace(const APInt &) version as well. Differential Revision: https://reviews.llvm.org/D32155 llvm-svn: 300566
* [InstCombine] allow (X * C2) << C1 --> X * (C2 << C1) for vectorsSanjay Patel2017-02-091-13/+12
| | | | | | | | | | This fold already existed for vectors but only when 'C1' was a splat constant (but 'C2' could be any constant). There were no tests for any vector constants, so I'm adding a test that shows non-splat constants for both operands. llvm-svn: 294650
* [InstCombine] move folds for shift-shift pairs; NFCISanjay Patel2017-02-011-48/+34
| | | | | | | | | | | Although this is 'no-functional-change-intended', I'm adding tests for shl-shl and lshr-lshr pairs because there is no existing test coverage for those folds. It seems like we should be able to remove some code from foldShiftedShift() at this point because we're handling those patterns on the general path. llvm-svn: 293814
* [InstCombine] enable (X <<nsw C1) >>s C2 --> X <<nsw (C1 - C2) for vectors ↵Sanjay Patel2017-01-301-54/+19
| | | | | | with splat constants llvm-svn: 293570
* [InstCombine] enable more lshr(shl X, C1), C2 folds for vectors with splat ↵Sanjay Patel2017-01-301-23/+17
| | | | | | constants llvm-svn: 293562
* [InstCombine] enable (X >>?exact C1) << C2 --> X >>?exact (C1-C2) for ↵Sanjay Patel2017-01-301-24/+22
| | | | | | vectors with splat constants llvm-svn: 293524
* [InstCombine] use auto with obvious type; NFCSanjay Patel2017-01-301-3/+3
| | | | llvm-svn: 293508
* [InstCombine] enable (X <<nsw C1) >>s C2 --> X <<nsw (C1-C2) for vectors ↵Sanjay Patel2017-01-301-20/+16
| | | | | | with splat constants llvm-svn: 293507
* [InstCombine] fixed to propagate 'exact' on lshrSanjay Patel2017-01-301-1/+1
| | | | | | | | | | | | | | | | | The original shift is bigger, so this may qualify as 'obvious', but here's an attempt at an Alive-based proof: Name: exact Pre: (C1 u< C2) %a = shl i8 %x, C1 %b = lshr exact i8 %a, C2 => %c = lshr exact i8 %x, C2 - C1 %b = and i8 %c, ((1 << width(C1)) - 1) u>> C2 Optimization is correct! llvm-svn: 293498
* [InstCombine] enable lshr(shl X, C1), C2 folds for vectors with splat constantsSanjay Patel2017-01-301-25/+25
| | | | llvm-svn: 293489
* [InstCombine] enable (X >>?,exact C1) << C2 --> X << (C2 - C1) for vectors ↵Sanjay Patel2017-01-291-17/+17
| | | | | | with splats llvm-svn: 293435
* [InstCombine] fold (X >>u C) << C --> X & (-1 << C)Sanjay Patel2017-01-261-18/+17
| | | | | | | | | | | | | | | We already have this fold when the lshr has one use, but it doesn't need that restriction. We may be able to remove some code from foldShiftedShift(). Also, move the similar: (X << C) >>u C --> X & (-1 >>u C) ...directly into visitLShr to help clean up foldShiftByConstOfShiftByConst(). That whole function seems questionable since it is called by commonShiftTransforms(), but there's really not much in common if we're checking the shift opcodes for every fold. llvm-svn: 293215
* [InstCombine] use m_APInt to allow (X << C) >>u C --> X & (-1 >>u C) with ↵Sanjay Patel2017-01-261-16/+24
| | | | | | splat vectors llvm-svn: 293208
* [InstCombine] use m_APInt to allow ashr folds for vectors with splat constantsSanjay Patel2017-01-211-21/+28
| | | | | | | We may be able to assert that no shl-shl or lshr-lshr pairs ever get here because we should have already handled those in foldShiftedShift(). llvm-svn: 292726
* [InstCombine] reduce indent; NFCISanjay Patel2017-01-171-133/+131
| | | | llvm-svn: 292230
* [InstCombine] use m_APInt instead of faking itSanjay Patel2017-01-161-20/+14
| | | | llvm-svn: 292164
* [InstCombine] fix names in canEvaluateShiftedShift(); NFCSanjay Patel2017-01-161-27/+26
| | | | | | | | It's not clear what 'First' and 'Second' mean, so use 'Inner' and 'Outer' to match foldShiftedShift() and add comments with formulas, so it's easier to see what's going on. llvm-svn: 292153
* [InstCombine] use m_APInt to allow shift-shift folds for vectors with splat ↵Sanjay Patel2017-01-161-4/+5
| | | | | | | | constants Some existing 'FIXME' tests are still not folded because of splat holes in value tracking. llvm-svn: 292151
* [InstCombine] refactor shift-of-shift folds; NFCISanjay Patel2017-01-161-83/+66
| | | | | | Reduces code duplication and makes it easier to extend these folds for vectors. llvm-svn: 292145
* [InstCombine] fix formatting; NFCSanjay Patel2017-01-151-24/+22
| | | | llvm-svn: 292073
* [InstCombine] use m_APInt to allow ashr folds for vectors with splat constantsSanjay Patel2017-01-151-3/+4
| | | | llvm-svn: 292064
* [InstCombine] clean up visitAshr(); NFCISanjay Patel2017-01-141-20/+9
| | | | llvm-svn: 292036
* [InstCombine] use m_APInt to allow lshr folds for vectors with splat constantsSanjay Patel2017-01-131-17/+14
| | | | llvm-svn: 291972
* [InstCombine] use 'match' and other clean-up; NFCISanjay Patel2017-01-131-17/+8
| | | | llvm-svn: 291937
* [InstCombine] use m_APInt to allow shl folds for vectors with splat constantsSanjay Patel2017-01-131-3/+5
| | | | llvm-svn: 291934
* [InstCombine] use Op0/Op1 local variables more consistently with shifts; NFCSanjay Patel2017-01-131-22/+16
| | | | llvm-svn: 291923
* [InstCombine] add a wrapper for a common pair of transforms; NFCISanjay Patel2017-01-101-7/+2
| | | | | | | Some of the callers are artificially limiting this transform to integer types; this should make it easier to incrementally remove that restriction. llvm-svn: 291620
* [InstCombine] Move casts around shift operationsDavid Majnemer2017-01-041-0/+19
| | | | | | | It is possible to perform a left shift before zero extending if the shift would only shift out zeros. llvm-svn: 290928
* Revert @llvm.assume with operator bundles (r289755-r289757)Daniel Jasper2016-12-191-3/+3
| | | | | | | This creates non-linear behavior in the inliner (see more details in r289755's commit thread). llvm-svn: 290086
* Remove the AssumptionCacheHal Finkel2016-12-151-3/+3
| | | | | | | | | After r289755, the AssumptionCache is no longer needed. Variables affected by assumptions are now found by using the new operand-bundle-based scheme. This new scheme is more computationally efficient, and also we need much less code... llvm-svn: 289756
* [InstCombine] add helper for shift-by-shift folds; NFCISanjay Patel2016-12-101-150/+162
| | | | | | | These are currently limited to integer types, but we should be able to extend to splat vectors and possibly general vectors. llvm-svn: 289343
* [InstSimplify] allow integer vector types to use computeKnownBitsSanjay Patel2016-11-271-5/+5
| | | | | | | | Note that the non-splat lshr+lshr test folded, but that does not work in general. Something is missing or wrong in computeKnownBits as the non-splat shl+shl test still shows. llvm-svn: 288005
* [InstCombine] Folding of shifts by the sum of positive valuesSimon Pilgrim2016-11-011-1/+10
| | | | | | | | | | | | | | | This patch introduces the combine: (C1 shift (A add C2)) -> ((C1 shift C2) shift A) iff A and C2 are both positive If both A and C2 are know to be positive then we can safely split into 2 shifts, permitting the folding of the Inner shift. Fix for the spec benchmark case mentioned by @nadav on PR15141 (assuming we can prove that the inputs as positive). Differential Revision: https://reviews.llvm.org/D26000 llvm-svn: 285696
* Replace a few more "fall through" comments with LLVM_FALLTHROUGHJustin Bogner2016-08-171-1/+1
| | | | | | Follow up to r278902. I had missed "fall through", with a space. llvm-svn: 278970
* InstCombine: Replace some never-null pointers with references. NFCJustin Bogner2016-08-051-4/+4
| | | | llvm-svn: 277792
* [ConstnatFolding] Teach the folder how to fold ConstantVectorDavid Majnemer2016-07-291-2/+4
| | | | | | | | | | | A ConstantVector can have ConstantExpr operands and vice versa. However, the folder had no ability to fold ConstantVectors which, in some cases, was an optimization barrier. Instead, rephrase the folder in terms of Constants instead of ConstantExprs and teach callers how to deal with failure. llvm-svn: 277099
* add FIXME comment; NFCSanjay Patel2016-04-111-1/+3
| | | | llvm-svn: 265970
* add an assert for safety; NFCSanjay Patel2016-04-111-0/+2
| | | | llvm-svn: 265969
* variable names start with a capital letter; NFCSanjay Patel2016-04-111-9/+9
| | | | llvm-svn: 265968
* [InstCombine] use canEvaluateShiftedShift() to handle the lshr case (NFCI)Sanjay Patel2016-04-111-33/+12
| | | | | | | | | We need just a couple of logic tweaks to consolidate the shl and lshr cases. This is step 5 of refactoring to solve PR26760: https://llvm.org/bugs/show_bug.cgi?id=26760 llvm-svn: 265965
* [InstCombine] don't try to shift an illegal amount (PR26760)Sanjay Patel2016-04-111-1/+3
| | | | | | | | | | This is the straightforward fix for PR26760: https://llvm.org/bugs/show_bug.cgi?id=26760 But we still need to make some changes to generalize this helper function and then send the lshr case into here. llvm-svn: 265960
* [InstCombine] rename variables in shifted-shift helper function (NFCI)Sanjay Patel2016-04-111-17/+20
| | | | | | | This is step 3 of refactoring to solve PR26760: https://llvm.org/bugs/show_bug.cgi?id=26760 llvm-svn: 265954
* [InstCombine] add helper function for shift-shift optimization (NFCI)Sanjay Patel2016-04-111-24/+37
| | | | | | | This is step 2 of refactoring to solve PR26760: https://llvm.org/bugs/show_bug.cgi?id=26760 llvm-svn: 265951
OpenPOWER on IntegriCloud