summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [InstCombine] Change the interface of SimplifyDemandedBits so that it takes ↵Craig Topper2017-03-251-2/+2
| | | | | | | | the instruction and operand instead of the Use. The first thing it did was get the User for the Use to get the instruction back. This requires looking through the Uses for the User using the waymarking walk. That's pretty fast, but its probably still better to just pass the Instruction we already had. llvm-svn: 298772
* [InstCombine] Avoid faulty combines of select-cmp-brBjorn Pettersson2017-03-021-3/+5
| | | | | | | | | | | | | | | | | | | | | | Summary: When InstCombine is optimizing certain select-cmp-br patterns it replaces the result of the select in uses outside of the basic block containing the select. This is only legal if the path from the select to the outside use is disjoint from all other paths out from the originating basic block. The problem found was that InstCombiner::replacedSelectWithOperand did not consider the case when both edges out from the br pointed to the same label. In that case the paths aren't disjoint and the transformation is illegal. This patch avoids the faulty rewrites by verifying that there is a single flow to the successor where we want to replace uses. Reviewers: llvm-commits, spatel, majnemer Differential Revision: https://reviews.llvm.org/D30455 llvm-svn: 296752
* [InstCombine] fold icmp sgt/slt (add nsw X, C2), C --> icmp sgt/slt X, (C - C2)Sanjay Patel2017-02-121-6/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | I found one special case of this transform for 'slt 0', so I removed that and added the general transform. Alive code to check correctness: Name: slt_no_overflow Pre: WillNotOverflowSignedSub(C1, C2) %a = add nsw i8 %x, C2 %b = icmp slt %a, C1 => %b = icmp slt %x, C1 - C2 Name: sgt_no_overflow Pre: WillNotOverflowSignedSub(C1, C2) %a = add nsw i8 %x, C2 %b = icmp sgt %a, C1 => %b = icmp sgt %x, C1 - C2 http://rise4fun.com/Alive/MH Differential Revision: https://reviews.llvm.org/D29774 llvm-svn: 294898
* [InstCombine] add local name for repeated calls; NFC Sanjay Patel2017-02-081-6/+4
| | | | llvm-svn: 294470
* [InstCombine] Make max size array combine a tunable.Davide Italiano2017-02-071-1/+3
| | | | | | | Requested by Sanjoy/Hal a while ago, and forgotten by me (r283612). llvm-svn: 294323
* fix formatting; NFCSanjay Patel2017-01-311-1/+1
| | | | llvm-svn: 293652
* [InstCombine] Make sure that LHS and RHS have the same type inSilviu Baranga2017-01-311-0/+4
| | | | | | | | | | | | | | | | | transformToIndexedCompare If they don't have the same type, the size of the constant index would need to be adjusted (and this wouldn't be always possible). Alternatively we could try the analysis with the initial RHS value, which would guarantee that the two sides have the same type. However it is unlikely that in practice this would pass our transformation requirements. Fixes PR31808 (https://llvm.org/bugs/show_bug.cgi?id=31808). llvm-svn: 293629
* [InstCombine] move icmp transforms that might be recognized as min/max and ↵Sanjay Patel2017-01-271-10/+21
| | | | | | | | | | | | | | | | | | | | | | inf-loop (PR31751) This is a minimal patch to avoid the infinite loop in: https://llvm.org/bugs/show_bug.cgi?id=31751 But the general problem is bigger: we're not canonicalizing all of the min/max forms reported by value tracking's matchSelectPattern(), and we don't define min/max consistently. Some code uses matchSelectPattern(), other code uses matchers like m_Umax, and others have their own inline definitions which may be subtly different from any of the above. The reason that the test cases in this patch need a cast op to trigger is because we don't (yet) canonicalize all min/max forms based on matchSelectPattern() in canonicalizeMinMaxWithConstant(), but we do make min/max+cast transforms based on matchSelectPattern() in visitSelectInst(). The location of the icmp transforms that trigger the inf-loop seems arbitrary at best, so I'm moving those behind the min/max fence in visitICmpInst() as the quick fix. llvm-svn: 293345
* [InstCombine] icmp Pred (shl nsw X, C1), C0 --> icmp Pred X, C0 >> C1Sanjay Patel2017-01-191-24/+43
| | | | | | | | | | | | | | Try harder to fold icmp with shl nsw as discussed here: http://lists.llvm.org/pipermail/llvm-dev/2017-January/108749.html This is similar to the 'shl nuw' transforms that were added with D25913. This may eventually help solve: https://llvm.org/bugs/show_bug.cgi?id=30773 Differential Revision: https://reviews.llvm.org/D28406 llvm-svn: 292492
* [InstCombine] add an assert to make a shl+icmp transform assumption ↵Sanjay Patel2017-01-181-1/+9
| | | | | | explicit; NFCI llvm-svn: 292440
* [InstCombine] remove a redundant check; NFCISanjay Patel2017-01-181-2/+0
| | | | | | | I missed deleting this check when I refactored this chunk in: https://reviews.llvm.org/rL292260 llvm-svn: 292433
* [InstCombine] refactor foldICmpShlConstant(); NFCISanjay Patel2017-01-171-32/+35
| | | | | | | This reduces the size of and increases the symmetry with the planned functional change in: https://reviews.llvm.org/D28406 llvm-svn: 292260
* [InstCombine] optimize unsigned icmp of incrementSanjay Patel2017-01-131-0/+25
| | | | | | | | | | | | | | | | | | | | | | | Allows LLVM to optimize sequences like the following: %add = add nuw i32 %x, 1 %cmp = icmp ugt i32 %add, %y Into: %cmp = icmp uge i32 %x, %y Previously, only signed comparisons were being handled. Decrements could also be handled, but 'sub nuw %x, 1' is currently canonicalized to 'add %x, -1' in InstCombineAddSub, losing the nuw flag. Removing that canonicalization seems like it might have far-reaching ramifications so I kept this simple for now. Patch by Matti Niemenmaa! Differential Revision: https://reviews.llvm.org/D24700 llvm-svn: 291975
* fix comment typos; NFCSanjay Patel2017-01-091-5/+5
| | | | llvm-svn: 291447
* [InstCombine] add folds for icmp (umin|umax X, Y), XSanjay Patel2016-12-191-19/+54
| | | | | | | | This is a follow-up to: https://reviews.llvm.org/rL289855 (https://reviews.llvm.org/D27531) https://reviews.llvm.org/rL290111 llvm-svn: 290118
* [InstCombine] add folds for icmp (smax X, Y), XSanjay Patel2016-12-191-17/+35
| | | | | | | This is a follow-up to: https://reviews.llvm.org/rL289855 (D27531) llvm-svn: 290111
* 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
* [InstCombine] add folds for icmp (smin X, Y), XSanjay Patel2016-12-151-0/+37
| | | | | | | | | | | | | | Min/max canonicalization (r287585) exposes the fact that we're missing combines for min/max patterns. This patch won't solve the example that was attached to that thread, so something else still needs fixing. The line between InstCombine and InstSimplify gets blurry here because sometimes the icmp instruction that we want to fold to already exists, but sometimes it's the swapped form of what we want. Corresponding changes for smax/umin/umax to follow. Differential Revision: https://reviews.llvm.org/D27531 llvm-svn: 289855
* 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
* Replace APFloatBase static fltSemantics data members with getter functionsStephan Bergmann2016-12-141-6/+6
| | | | | | | | | | | | | At least the plugin used by the LibreOffice build (<https://wiki.documentfoundation.org/Development/Clang_plugins>) indirectly uses those members (through inline functions in LLVM/Clang include files in turn using them), but they are not exported by utils/extract_symbols.py on Windows, and accessing data across DLL/EXE boundaries on Windows is generally problematic. Differential Revision: https://reviews.llvm.org/D26671 llvm-svn: 289647
* IR: Change the gep_type_iterator API to avoid always exposing the "current" ↵Peter Collingbourne2016-12-021-2/+2
| | | | | | | | | | | | | type. Instead, expose whether the current type is an array or a struct, if an array what the upper bound is, and if a struct the struct type itself. This is in preparation for a later change which will make PointerType derive from Type rather than SequentialType. Differential Revision: https://reviews.llvm.org/D26594 llvm-svn: 288458
* [InstCombine] Fold nuw left-shifts in `ugt`/`ule` comparisons.Sanjay Patel2016-11-011-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This transforms %a = shl nuw %x, c1 %b = icmp {ugt|ule} %a, c0 into %b = icmp {ugt|ule} %x, (c0 >> c1) z3: (declare-const x (_ BitVec 64)) (declare-const c0 (_ BitVec 64)) (declare-const c1 (_ BitVec 64)) (push) (assert (= x (bvlshr (bvshl x c1) c1))) ; nuw (assert (not (= (bvugt (bvshl x c1) c0) (bvugt x (bvlshr c0 c1))))) (check-sat) (get-model) (pop) (push) (assert (= x (bvlshr (bvshl x c1) c1))) ; nuw (assert (not (= (bvule (bvshl x c1) c0) (bvule x (bvlshr c0 c1))))) (check-sat) (get-model) (pop) Patch by bryant! Differential Revision: https://reviews.llvm.org/D25913 llvm-svn: 285729
* [InstCombine] Ensure that truncated int types are legal.Sanjay Patel2016-10-251-4/+2
| | | | | | | | | | Fixes the FIXMEs in D25952 and rL285075. Patch by bryant! Differential Revision: https://reviews.llvm.org/D25955 llvm-svn: 285108
* [InstCombine] add test and code comment to show potentially misguided icmp ↵Sanjay Patel2016-10-251-0/+3
| | | | | | trunc transform llvm-svn: 285075
* Remove duplicated code; NFCSanjoy Das2016-10-021-1/+2
| | | | | | | ICmpInst::makeConstantRange does exactly the same thing as ConstantRange::makeExactICmpRegion. llvm-svn: 283059
* [InstCombine] add helper functions for visitICmpInst(); NFCISanjay Patel2016-09-161-523/+556
| | | | llvm-svn: 281743
* [InstCombine] move folds for icmp (sh C2, Y), C1 in with other icmp+sh ↵Sanjay Patel2016-09-151-27/+21
| | | | | | folds; NFCI llvm-svn: 281672
* [InstCombine] allow icmp (shr/shl) folds for vectorsSanjay Patel2016-09-151-23/+18
| | | | | | | | | | | | These 2 helper functions were already using APInt internally, so just change the API and caller to allow folds for splats. The scalar regression tests look quite thorough, so I just added a couple of tests to prove that vectors are handled too. These folds should be grouped with the other cmp+shift folds though. That can be an NFC follow-up. llvm-svn: 281663
* [InstCombine] Do not RAUW a constant GEPDavid Majnemer2016-09-151-1/+1
| | | | | | | | canRewriteGEPAsOffset expects to process instructions, not constants. This fixes PR30342. llvm-svn: 281650
* [InstCombine] simplify code; NFCISanjay Patel2016-09-151-14/+7
| | | | llvm-svn: 281644
* fix function names; NFCSanjay Patel2016-09-151-34/+34
| | | | llvm-svn: 281637
* [InstCombine] allow icmp (sub nsw) folds for vectorsSanjay Patel2016-09-151-40/+35
| | | | | | Also, clean up the code and comments for the existing folds in foldICmpSubConstant(). llvm-svn: 281631
* [InstCombine] remove duplicated fold ; NFCISanjay Patel2016-09-151-7/+2
| | | | | | | | | | | This pattern is matched in foldICmpBinOpEqualityWithConstant() and already works with vectors too. I changed some comments over there to point out the current location. The tests for this transform are currently in 'sub.ll'. Note that the remaining folds in this block all require a sub too, so they should get grouped with the other icmp(sub) patterns. llvm-svn: 281627
* [InstCombine] allow (icmp sgt smin(PosA, B), 0) fold for vectorsSanjay Patel2016-09-151-14/+18
| | | | llvm-svn: 281624
* [InstCombine] clean up foldICmpWithConstant(); NFCSanjay Patel2016-09-151-114/+117
| | | | | | | | 1. Early exit to reduce indent 2. Rename variables 3. Add local 'Pred' variable llvm-svn: 281615
* [InstCombine] add helper function for foldICmpWithConstant; NFCSanjay Patel2016-09-151-210/+222
| | | | | | | This is a big glob of transforms that probably should work for vectors, but currently they are disallowed because of ConstantInt guards. llvm-svn: 281614
* [InstCombine] use m_APInt to allow icmp folds using known bits for splat ↵Sanjay Patel2016-09-151-3/+3
| | | | | | constant vectors llvm-svn: 281613
* [InstCombine] refactor eq/ne cases in foldICmpUsingKnownBits() ; NFCISanjay Patel2016-09-141-62/+27
| | | | | | The pattern matching and transforms are identical; the cmp predicate just changes. llvm-svn: 281561
* [InstCombine] use m_APInt to allow icmp X, C folds for splat constant vectorsSanjay Patel2016-09-121-2/+3
| | | | | | isSignBitCheck could be changed to take a pointer param to avoid the 'UnusedBit' ugliness. llvm-svn: 281231
* fix formatting; NFCSanjay Patel2016-09-121-14/+13
| | | | llvm-svn: 281220
* [InstCombine] add helper function for foldICmpUsingKnownBits; NFCISanjay Patel2016-09-121-259/+278
| | | | llvm-svn: 281217
* fix formatting/typos; NFCSanjay Patel2016-09-121-7/+6
| | | | llvm-svn: 281214
* [InstCombine] clean up foldICmpBinOpEqualityWithConstant / ↵Sanjay Patel2016-09-101-59/+56
| | | | | | | | | foldICmpIntrinsicWithConstant ; NFC 1. Rename variables to be consistent with related/preceding code (may want to reorganize). 2. Fix comments/formatting. llvm-svn: 281140
* [InstCombine] rename and reorganize some icmp folding functions; NFCSanjay Patel2016-09-101-21/+17
| | | | | | | | | | Everything under foldICmpInstWithConstant() should now be working for splat vectors via m_APInt matchers. Ie, I've removed all of the FIXMEs that I added while cleaning that section up. Note that not all of the associated FIXMEs in the regression tests are gone though, because some of the tests require earlier folds that are still scalar-only. llvm-svn: 281139
* [InstCombine] use m_APInt to allow icmp ult X, C folds for splat constant ↵Sanjay Patel2016-09-091-8/+13
| | | | | | vectors llvm-svn: 281107
* [InstCombine] return a vector-safe true/false constantSanjay Patel2016-09-081-2/+2
| | | | | | | | | | | I introduced this potential bug by missing this diff in: https://reviews.llvm.org/rL280873 ...however, I'm not sure how to reach this code path with a regression test. We may be able to remove this code and assume that the transform to a constant is always handled by InstSimplify? llvm-svn: 280964
* [InstCombine] use m_APInt to allow icmp (and (sh X, Y), C2), C1 folds for ↵Sanjay Patel2016-09-071-51/+21
| | | | | | splat constant vectors llvm-svn: 280873
* [InstCombine] allow icmp (and X, C2), C1 folds for splat constant vectorsSanjay Patel2016-09-071-43/+33
| | | | | | | | This is a revert of r280676 which was a revert of r280637; ie, this is r280637 again. It was speculatively reverted to help debug buildbot failures. llvm-svn: 280861
* [InstCombine] don't assert that division-by-constant has been folded (PR30281)Sanjay Patel2016-09-051-7/+6
| | | | | | | | | | This is effectively a revert of: https://reviews.llvm.org/rL280115 And this should fix https://llvm.org/bugs/show_bug.cgi?id=30281: llvm-svn: 280677
* [InstCombine] revert r280637 because it causes test failures on an ARM botSanjay Patel2016-09-051-33/+43
| | | | | | http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15/builds/14952/steps/ninja%20check%201/logs/FAIL%3A%20LLVM%3A%3Aicmp.ll llvm-svn: 280676
OpenPOWER on IntegriCloud