summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine
Commit message (Collapse)AuthorAgeFilesLines
* [InstCombine] Fixed bug introduced in r282237Alexey Bataev2016-09-261-6/+8
| | | | | | | | The index of the new insertelement instruction was evaluated in the wrong way, it was considered as the index of the inserted value instead of index of the position, where the value should be inserted. llvm-svn: 282401
* [InstCombine] Teach the udiv folding logic how to handle constant expressions.Andrea Di Biagio2016-09-261-11/+14
| | | | | | | | | | | | | | | | | | | This patch fixes PR30366. Function foldUDivShl() worked under the assumption that one of the values in input to the function was always an instance of llvm::Instruction. However, function visitUDivOperand() (the only user of foldUDivShl) was clearly violating that precondition; internally, visitUDivOperand() uses pattern matches to check the operands of a udiv. Pattern matchers for binary operators know how to handle both Instruction and ConstantExpr values. This patch fixes the problem in foldUDivShl(). Now we use pattern matchers instead of explicit casts to Instruction. The reduced test case from PR30366 has been added to test file InstCombine/udiv-simplify.ll. Differential Revision: https://reviews.llvm.org/D24565 llvm-svn: 282398
* [InstCombine] Fix for PR29124: reduce insertelements to shufflevectorAlexey Bataev2016-09-232-50/+138
| | | | | | | | | | | | | | | | | | | | | | | | | If inserting more than one constant into a vector: define <4 x float> @foo(<4 x float> %x) { %ins1 = insertelement <4 x float> %x, float 1.0, i32 1 %ins2 = insertelement <4 x float> %ins1, float 2.0, i32 2 ret <4 x float> %ins2 } InstCombine could reduce that to a shufflevector: define <4 x float> @goo(<4 x float> %x) { %shuf = shufflevector <4 x float> %x, <4 x float> <float undef, float 1.0, float 2.0, float undef>, <4 x i32><i32 0, i32 5, i32 6, i32 3> ret <4 x float> %shuf } Also, InstCombine tries to convert shuffle instruction to single insertelement, if one of the vectors is a constant vector and only a single element from this constant should be used in shuffle, i.e. shufflevector <4 x float> %v, <4 x float> <float undef, float 1.0, float undef, float undef>, <4 x i32> <i32 0, i32 5, i32 undef, i32 undef> -> insertelement <4 x float> %v, float 1.0, 1 Differential Revision: https://reviews.llvm.org/D24182 llvm-svn: 282237
* [InstCombine] fold X urem C -> X < C ? X : X - C when C is big (PR28672)Sanjay Patel2016-09-221-0/+8
| | | | | | | | | | | | We already have the udiv variant of this transform, so I think this is ok for InstCombine too even though there is an increase in IR instructions. As the tests and TODO comments show, the transform can lead to follow-on combines. This should fix: https://llvm.org/bugs/show_bug.cgi?id=28672 Differential Revision: https://reviews.llvm.org/D24527 llvm-svn: 282209
* [InstCombine] canonicalize vector select with constant vector condition to ↵Sanjay Patel2016-09-161-0/+39
| | | | | | | | | | | | | | | | | | | | shuffle As discussed on llvm-dev ( http://lists.llvm.org/pipermail/llvm-dev/2016-August/104210.html ): turn a vector select with constant condition operand into a shuffle as a canonicalization step. Shuffles may be easier to reason about in conjunction with other shuffles and insert/extract. Possible known (minor?) regressions from this change are filed as: https://llvm.org/bugs/show_bug.cgi?id=28530 https://llvm.org/bugs/show_bug.cgi?id=28531 https://llvm.org/bugs/show_bug.cgi?id=30371 If something terrible happens to perf after this commit, feel free to revert until a backend fix is in place. Differential Revision: https://reviews.llvm.org/D24279 llvm-svn: 281787
* [InstCombine] allow vector types for constant folding / computeKnownBits ↵Sanjay Patel2016-09-161-3/+4
| | | | | | | | | | | | | | | | (PR24942) computeKnownBits() already works for integer vectors, so allow vector types when calling that from InstCombine. I don't think the change to use m_APInt in computeKnownBits is strictly necessary because we do check for ConstantVector later, but it's more efficient to handle the splat case without needing to loop on vector elements. This should work with InstSimplify, but doesn't yet, so I made that a FIXME comment on the test for PR24942: https://llvm.org/bugs/show_bug.cgi?id=24942 Differential Revision: https://reviews.llvm.org/D24677 llvm-svn: 281777
* [InstCombine] add helper functions for visitICmpInst(); NFCISanjay Patel2016-09-162-523/+559
| | | | llvm-svn: 281743
* [InstCombine] move folds for icmp (sh C2, Y), C1 in with other icmp+sh ↵Sanjay Patel2016-09-152-31/+25
| | | | | | folds; NFCI llvm-svn: 281672
* [InstCombine] allow icmp (shr/shl) folds for vectorsSanjay Patel2016-09-152-25/+20
| | | | | | | | | | | | 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-152-210/+223
| | | | | | | 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
* Reapply "InstCombine: Reduce trunc (shl x, K) width."Matt Arsenault2016-09-131-7/+25
| | | | | | | This reapplies r272987 with a fix for infinitely looping when the truncated value is another shift of a constant. llvm-svn: 281379
* [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-122-259/+279
| | | | llvm-svn: 281217
* fix formatting/typos; NFCSanjay Patel2016-09-122-12/+11
| | | | llvm-svn: 281214
* [InstCombine] add helper function for folding {and,or,xor} (cast X), C ; NFCISanjay Patel2016-09-121-28/+41
| | | | llvm-svn: 281187
* InstCombine: Don't combine loads/stores from swifterror to a new typeArnold Schwaighofer2016-09-101-0/+8
| | | | | | | | | This generates invalid IR: the only users of swifterror can be call arguments, loads, and stores. rdar://28242257 llvm-svn: 281144
* [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-102-24/+23
| | | | | | | | | | 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-072-52/+22
| | | | | | 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][SSE4a] Fix assertion failure in the insertq/insertqi combining ↵Andrea Di Biagio2016-09-071-3/+3
| | | | | | | | | | | logic. This fixes a similar issue to the one already fixed by r280804 (revieved in D24256). Revision 280804 fixed the problem with unsafe dyn_casts in the extrq/extrqi combining logic. However, it turns out that even the insertq/insertqi logic was affected by the same problem. llvm-svn: 280807
* [InstCombine][SSE4a] Fix assertion failure caused by unsafe dyn_casts on the ↵Andrea Di Biagio2016-09-071-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | operands of extrq/extrqi intrinsic calls. This patch fixes an assertion failure caused by unsafe dynamic casts on the constant operands of sse4a intrinsic calls to extrq/extrqi The combine logic that simplifies sse4a extrq/extrqi intrinsic calls currently checks if the input operands are constants. Internally, that logic relies on dyn_casts of values returned by calls to method Constant::getAggregateElement. However, method getAggregateElemet may return nullptr if the constant element cannot be retrieved. So, all the dyn_casts can potentially fail. This is what happens for example if a constexpr value is passed in input to an extrq/extrqi intrinsic call. This patch fixes the problem by using a dyn_cast_or_null (instead of a simple dyn_cast) on the result of each call to Constant::getAggregateElement. Added reproducible test cases to x86-sse4a.ll. Differential Revision: https://reviews.llvm.org/D24256 llvm-svn: 280804
* fix formatting; NFCSanjay Patel2016-09-061-19/+14
| | | | llvm-svn: 280727
* [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
* [InstCombine] allow icmp (and X, C2), C1 folds for splat constant vectorsSanjay Patel2016-09-041-43/+33
| | | | | | | | The code to calculate 'UsesRemoved' could be simplified. As-is, that code is a victim of PR30273: https://llvm.org/bugs/show_bug.cgi?id=30273 llvm-svn: 280637
* [InstCombine] recode icmp fold in a vector-friendly way; NFCSanjay Patel2016-09-041-22/+30
| | | | | | | | | | | The transform in question: icmp (and (trunc W), C2), C1 -> icmp (and W, C2'), C1' ...is still not enabled for vectors, thus no functional change intended. It's not clear to me if this is a good transform for vectors or even scalars in general. Changing that behavior may be a follow-on patch. llvm-svn: 280627
* [InstCombine] Preserve llvm.mem.parallel_loop_access metadata when replacingDorit Nuzman2016-09-041-0/+6
| | | | | | | | | | | | memcpy with ld/st. When InstCombine replaces a memcpy with loads+stores it does not copy over the llvm.mem.parallel_loop_access from the memcpy instruction. This patch fixes that. Differential Revision: https://reviews.llvm.org/D23499 llvm-svn: 280617
* Test commit.Dorit Nuzman2016-09-041-0/+1
| | | | llvm-svn: 280615
* AMDGPU: Do basic folding of class intrinsicMatt Arsenault2016-09-031-0/+79
| | | | | | | This allows more of the OCML builtin library to be constant folded. llvm-svn: 280586
* [InsttCombine] fold insertelement of constant into shuffle with constant ↵Sanjay Patel2016-09-021-0/+76
| | | | | | | | | | | | | | | | | operand (PR29126) The motivating case occurs with SSE/AVX scalar intrinsics, so this is a first step towards shrinking that to a single shufflevector. Note that the transform is intentionally limited to shuffles that are equivalent to vector selects to avoid creating arbitrary shuffle masks that may not lower well. This should solve PR29126: https://llvm.org/bugs/show_bug.cgi?id=29126 Differential Revision: https://reviews.llvm.org/D23886 llvm-svn: 280504
* [InstCombine] remove fold of an icmp pattern that should never happenSanjay Patel2016-09-011-15/+0
| | | | | | | | | | | | While removing a scalar shackle from an icmp fold, I noticed that I couldn't find any tests to trigger this code path. The 'and' shrinking transform should be handled by InstCombiner::foldCastedBitwiseLogic() or eliminated with InstSimplify. The icmp narrowing is part of InstCombiner::foldICmpWithCastAndCast(). Differential Revision: https://reviews.llvm.org/D24031 llvm-svn: 280370
* [InstCombine] allow icmp (shr exact X, C2), C fold for splat constant vectorsSanjay Patel2016-08-311-5/+0
| | | | | | | The enhancement to foldICmpDivConstant ( http://llvm.org/viewvc/llvm-project?view=revision&revision=280299 ) allows us to remove the ConstantInt check; no other changes needed. llvm-svn: 280300
* [InstCombine] allow icmp (div X, Y), C folds for splat constant vectorsSanjay Patel2016-08-311-37/+26
| | | | | | Converting all of the overflow ops to APInt looked risky, so I've left that as a TODO. llvm-svn: 280299
* [InstCombine] change insertRangeTest() to use APInt instead of Constant; NFCISanjay Patel2016-08-313-20/+29
| | | | | | | | This is prep work before changing the callers to also use APInt which will allow folds for splat vectors. Currently, the callers have ConstantInt guards in place, so no functional change intended with this commit. llvm-svn: 280282
* [InstCombine] clean up InsertRangeTest; NFCISanjay Patel2016-08-311-35/+15
| | | | | | | | | | It's much less code and easier to read if we don't duplicate everything between the 'Inside' and not 'Inside' cases. As noted with the FIXME, the goal is to make this vector-friendly in a follow-up patch. llvm-svn: 280183
* [InstCombine] replace divide-by-constant checks with asserts; NFCSanjay Patel2016-08-301-19/+16
| | | | | | | These folds already have tests for scalar and vector types, except for the vector div-by-0 case, so I'm adding tests for that. llvm-svn: 280115
* [InstCombine] clean up foldICmpDivConstant; NFCISanjay Patel2016-08-301-16/+20
| | | | | | | | 1. Fix comments to match variable names 2. Remove redundant CmpRHS variable 3. Add FIXME to replace some checks with asserts llvm-svn: 280112
OpenPOWER on IntegriCloud