Commit Graph

3049 Commits

Author SHA1 Message Date
Simon Pilgrim
dc0a1d53ba [InstCombine][X86] MULDQ/MULUDQ undef -> zero
Match generic mul behaviour so that <X x i64> multiply and muldq/muludq pattern act the same

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292784 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-23 12:07:32 +00:00
Simon Pilgrim
70a34a86e6 [InstCombine][SSE] Tests showing missed opportunities to constant fold PMULDQ/PMULUDQ
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292782 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-23 10:57:39 +00:00
Benjamin Kramer
84d682db0f Fix some broken CHECK lines.
The colon is important.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292761 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-22 20:28:56 +00:00
Sanjay Patel
1493913c79 [InstCombine] use m_APInt to allow ashr folds for vectors with splat constants
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().


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292726 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-21 17:59:59 +00:00
Sanjay Patel
54739f0087 [InstCombine] add tests for ashr-ashr; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292724 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-21 17:43:06 +00:00
Justin Lebar
f103cf3473 [ConstantFold] Remove test checking that we don't constant-fold sqrt(-2).
This depended on libm's errno behavior (we constant fold iff libm's
sqrt(-2) does not set errno) and was breaking on mac.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292701 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-21 02:02:27 +00:00
Justin Lebar
12044b3dd7 [ConstantFolding] Constant-fold llvm.sqrt(x) like other intrinsics.
Summary:
Currently we return undef, but we're in the process of changing the
LangRef so that llvm.sqrt behaves like the other math intrinsics,
matching the return value of the standard libcall but not setting errno.

This change is legal even without the LangRef change because currently
calling llvm.sqrt(x) where x is negative is spec'ed to be UB.  But in
practice it's also safe because we're simply constant-folding fewer
inputs: Inputs >= -0 get constant-folded as before, but inputs < -0 now
aren't constant-folded, because ConstantFoldFP aborts if the host math
function raises an fp exception.

Reviewers: hfinkel, efriedma, sanjoy

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D28929

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292692 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-21 00:59:57 +00:00
Sanjay Patel
6139474d82 [InstCombine] auto-generate checks; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292682 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-20 23:39:01 +00:00
Sanjay Patel
92a30c54f3 [ValueTracking] recognize variations of 'clamp' to improve codegen (PR31693)
By enhancing value tracking, we allow an existing min/max canonicalization to
kick in and improve codegen for several targets that have min/max instructions.

Unfortunately, recognizing min/max in value tracking may cause us to hit
a hack in InstCombiner::visitICmpInst() more often:
http://lists.llvm.org/pipermail/llvm-dev/2017-January/109340.html
...but I'm hoping we can remove that soon.

Correctness proofs based on Alive:

Name: smaxmin
Pre: C1 < C2
%cmp2 = icmp slt i8 %x, C2
%min = select i1 %cmp2, i8 %x, i8 C2
%cmp3 = icmp slt i8 %x, C1
%r = select i1 %cmp3, i8 C1, i8 %min
=>
%cmp2 = icmp slt i8 %x, C2
%min = select i1 %cmp2, i8 %x, i8 C2
%cmp1 = icmp sgt i8 %min, C1
%r = select i1 %cmp1, i8 %min, i8 C1

Name: sminmax
Pre: C1 > C2
%cmp2 = icmp sgt i8 %x, C2
%max = select i1 %cmp2, i8 %x, i8 C2
%cmp3 = icmp sgt i8 %x, C1
%r = select i1 %cmp3, i8 C1, i8 %max
=>
%cmp2 = icmp sgt i8 %x, C2
%max = select i1 %cmp2, i8 %x, i8 C2
%cmp1 = icmp slt i8 %max, C1
%r = select i1 %cmp1, i8 %max, i8 C1

---------------------------------------- 
Optimization: smaxmin 
Done: 1 
Optimization is correct! 
---------------------------------------- 
Optimization: sminmax 
Done: 1 
Optimization is correct!



Name: umaxmin
Pre: C1 u< C2
%cmp2 = icmp ult i8 %x, C2
%min = select i1 %cmp2, i8 %x, i8 C2
%cmp3 = icmp ult i8 %x, C1
%r = select i1 %cmp3, i8 C1, i8 %min
=>
%cmp2 = icmp ult i8 %x, C2
%min = select i1 %cmp2, i8 %x, i8 C2
%cmp1 = icmp ugt i8 %min, C1
%r = select i1 %cmp1, i8 %min, i8 C1

Name: uminmax
Pre: C1 u> C2
%cmp2 = icmp ugt i8 %x, C2
%max = select i1 %cmp2, i8 %x, i8 C2
%cmp3 = icmp ugt i8 %x, C1
%r = select i1 %cmp3, i8 C1, i8 %max
=>
%cmp2 = icmp ugt i8 %x, C2
%max = select i1 %cmp2, i8 %x, i8 C2
%cmp1 = icmp ult i8 %max, C1
%r = select i1 %cmp1, i8 %max, i8 C1

---------------------------------------- 
Optimization: umaxmin 
Done: 1 
Optimization is correct! 
---------------------------------------- 
Optimization: uminmax 
Done: 1 
Optimization is correct! 
 


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292660 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-20 22:18:47 +00:00
Sanjay Patel
7d5b56cb3e [InstCombine] add tests to show missed canonicalization of min/max; NFC
Unfortunately, recognizing these in value tracking may cause us to hit
a hack in InstCombiner::visitICmpInst() more often:
http://lists.llvm.org/pipermail/llvm-dev/2017-January/109340.html

...but besides being the obviously Right Thing To Do, there's a clear 
codegen win from identifying these patterns for several targets.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292655 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-20 21:49:41 +00:00
Simon Pilgrim
116ba1a31a [InstCombine][X86] Add MULDQ/MULUDQ undef handling
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292627 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-20 18:20:30 +00:00
Simon Pilgrim
1d1dc060d7 [InstCombine][SSE] Tests showing missed opportunities to handle muldq/muludq with undef arguments
Fixed a typo in existing test names at the same time

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292619 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-20 17:06:38 +00:00
Simon Pilgrim
4ad0fb1e2c [InstCombine][SSE] Tests showing missed opportunities to constant fold packss/packus
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292609 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-20 13:21:30 +00:00
Simon Pilgrim
0a1c1b20e2 [InstCombine][SSE] Tests showing missed opportunities to handle packss/packus with undef arguments
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292601 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-20 11:28:07 +00:00
Simon Pilgrim
87735961e4 [InstCombine][SSE] Add DemandedElts support for PACKSS/PACKUS instructions
Simplify a packss/packus truncation based on the elements of the mask that are actually demanded.

Differential Revision: https://reviews.llvm.org/D28777

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292591 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-20 09:28:21 +00:00
Davide Italiano
02d80d355e [InstCombine] Simplify gep (gep p, a), (b-a)
Patch by Andrea Canciani.

Differential Revision:  https://reviews.llvm.org/D27413

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292506 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-19 18:51:56 +00:00
Sanjay Patel
d942fa6726 [InstCombine] icmp Pred (shl nsw X, C1), C0 --> icmp Pred X, C0 >> C1
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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292492 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-19 16:12:10 +00:00
Sanjay Patel
4683557a5f [InstCombine] add tests for shl nsw with icmp eq/ne; NFCI
These should be fixed with D28406.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292441 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-18 21:31:21 +00:00
Simon Pilgrim
c2e261218f [InstCombine][AVX2] Add DemandedElts support for VPERMD/VPERMPS shuffles
Simplify a vpermv shuffle mask based on the elements of the mask that are actually demanded.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292371 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-18 14:47:49 +00:00
Simon Pilgrim
e22dda95c0 [InstCombine][AVX2] Tests showing missed opportunities to pass demanded elts through a vpermd/vpermps shuffle
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292368 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-18 14:23:06 +00:00
Sanjay Patel
bf51c92663 [InstCombine] add tests to show missed shrinkage; NFC
A patch to partially solve this:
https://reviews.llvm.org/D28625


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292296 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-18 00:03:23 +00:00
Sanjay Patel
e9d3b46a1d [InstCombine] add tests for shl nsw + icmp sle; NFC
We want to handle these cases similarly to icmp sgt, so add the tests for it.
See: https://reviews.llvm.org/D28406


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292248 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-17 20:15:26 +00:00
Sanjay Patel
3ecd20b357 [ValueTracking] recognize a 'not' of an assumed condition as false
Also, add the corresponding match to the AssumptionCache's 'Affected Values' list.

Differential Revision: https://reviews.llvm.org/D28485



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292239 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-17 18:15:49 +00:00
David Majnemer
64f84982ee [InstCombine] Fold ((C1 OP zext(X)) & C2) -> zext((C1 OP X) & C2)
This further extends r292179 to support additional binary operators
beyond subtraction.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292238 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-17 18:08:06 +00:00
Chad Rosier
7eb6751ff6 [ValueTracking] Extend known bits to understand @llvm.bitreverse.
Differential Revision: https://reviews.llvm.org/D28780

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292233 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-17 17:23:51 +00:00
Simon Pilgrim
04f56107c5 [InstCombine][X86][AVX] Add DemandedElts support for VPERMILPD/VPERMILPS instructions
Simplify a vpermilvar shuffle mask based on the elements of the mask that are actually demanded.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292209 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-17 11:35:03 +00:00
Sanjoy Das
4b48551490 [InstCombine] Don't DSE across readnone functions that may throw
Summary: Depends on D28740

Reviewers: dberlin, chandlerc, hfinkel, majnemer

Subscribers: mcrosier, llvm-commits

Differential Revision: https://reviews.llvm.org/D28742

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292197 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-17 05:45:09 +00:00
David Majnemer
4b66daa8cc [InstCombine] Fold ((C1-zext(X)) & C2) -> zext((C1-X) & C2)
This is valid if C2 fits within the bitwidth of X thanks to two's
complement modulo arithmetic.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292179 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-17 00:45:57 +00:00
Matt Arsenault
3802a656d3 Add comment to test file I forgot to save
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292178 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-17 00:35:28 +00:00
Matt Arsenault
3bd79e8a80 SimplifyLibCalls: Remove checks for fabs
Use the intrinsic instead of emitting the libcall which
will be replaced by the intrinsic.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292176 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-17 00:30:31 +00:00
Matt Arsenault
5276f9a934 SimplifyLibCalls: Replace fabs libcalls with intrinsics
Add missing fabs(fpext) optimzation that worked with the call,
and also fixes it creating a second fpext when there were multiple
uses.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292172 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-17 00:10:40 +00:00
Simon Pilgrim
663d71421c [InstCombine][AVX] Tests showing missed opportunities to pass demanded elts through a permilpd/permilps shuffle mask
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292165 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-16 21:34:22 +00:00
Sanjay Patel
2222ec4bc9 [InstCombine] use m_APInt to allow shift-shift folds for vectors with splat constants
Some existing 'FIXME' tests are still not folded because of splat holes in value tracking.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292151 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-16 19:35:45 +00:00
Sanjay Patel
63bb8f30ce [InstCombine] add tests to show missed vector folds; NFC
The shift-shift possibilities became easier to see after:
https://reviews.llvm.org/rL292145



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292150 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-16 19:23:34 +00:00
Simon Pilgrim
50d76a80ed [InstCombine][SSE] Tests showing missed opportunities to pass demanded elts through a packss/packus truncation
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292144 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-16 17:26:23 +00:00
Simon Pilgrim
07d3c0f01c [InstCombine][SSE] Add DemandedElts support for PSHUFB instructions
Simplify a pshufb shuffle mask based on the elements of the mask that are actually demanded.

Differential Revision: https://reviews.llvm.org/D28745

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292101 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-16 11:30:41 +00:00
Sanjay Patel
5ec1d71357 [InstCombine] add tests to show missed vector folds; NFC
Also, add comments and remove bogus comment.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292082 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-15 23:45:03 +00:00
Simon Pilgrim
4354d8859a [InstCombine][SSE] Tests showing missed opportunities to pass demanded elts through a pshufb shuffle mask
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292072 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-15 17:49:04 +00:00
Sanjay Patel
f6be6abb81 [InstCombine] use m_APInt to allow ashr folds for vectors with splat constants
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292064 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-15 16:38:19 +00:00
Sanjay Patel
b41dc00dd6 [InstCombine] add explanatory comments to tests; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292063 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-15 16:22:26 +00:00
Chandler Carruth
340ad683c8 [PM] Fix instcombine's analysis preservation in the new pass manager to
cover domtree and alias analysis. These are the pretty clear analyses
that we would always want to survive this pass.

To make these survive, we also need to preserve the assumption cache.

Added a test that verifies the important bits of this preservation.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292037 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-14 23:25:22 +00:00
Sanjay Patel
1849414f3e [InstCombine] add test to show missed vector fold; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292035 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-14 23:12:29 +00:00
Sanjay Patel
3d039197d7 [InstCombine] optimize unsigned icmp of increment
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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291975 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-13 23:25:46 +00:00
Sanjay Patel
534e635d1b [InstCombine] use m_APInt to allow lshr folds for vectors with splat constants
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291972 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-13 23:04:10 +00:00
Sanjay Patel
e71a092ac9 [InstCombine / InstSimplify] add and move tests for lshr transforms; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291970 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-13 22:54:12 +00:00
Sanjay Patel
093d956dc6 [InstCombine] use m_APInt to allow shl folds for vectors with splat constants
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291934 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-13 18:39:09 +00:00
Sanjay Patel
19e50b839a [InstCombine] add tests to show missing transforms for vector shl; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291926 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-13 18:27:23 +00:00
Sanjay Patel
16c5e12d3a [InstCombine] if the condition of a select may be known via assumes, 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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291915 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-13 17:02:42 +00:00
Matt Arsenault
1f4353fb62 InstSimplify: Eliminate fabs on known positive
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291624 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-11 00:33:24 +00:00
Matt Arsenault
3aa9c7e336 InstCombine: fdiv -x, -y -> fdiv x, y
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291611 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-10 23:08:54 +00:00
Davide Italiano
b614cd308d [SimplifyLibCalls] Propagate fast math flags while optimizing pow().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291577 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-10 18:02:05 +00:00
Davide Italiano
3cb206f57f [SimplifyLibCalls] pow(x, -0.5) -> 1.0 / sqrt(x).
Differential Revision:  https://reviews.llvm.org/D28479

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291486 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-09 21:55:23 +00:00
Sanjay Patel
65d1e15e7c [InstCombine] add test to show missed fold using llvm.assume; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291472 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-09 20:18:30 +00:00
Sanjay Patel
fe1696d23d [InstCombine] regenerate checks; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291469 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-09 19:43:26 +00:00
Sanjay Patel
fdda3fb770 [InstCombine] regenerate checks; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291464 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-09 19:18:46 +00:00
Sanjay Patel
99555b7a44 [InstCombine] remove unnecessary attribute comments from test files; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291463 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-09 19:13:38 +00:00
Matt Arsenault
071eccb255 SimplifyLibCalls: Remove incorrect optimization of fabs
fabs(x * x) is not generally safe to assume x is positive if x is a NaN.
This is also less general than it could be, so this will be replaced
with a transformation on the intrinsic.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291359 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-07 19:55:12 +00:00
David Majnemer
ef654a7ee6 [InstSimplify] Optimize away urems in the presence of range metadata
We know that urem %V, C can be optimized away to %V if %V is ult C.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291282 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-06 21:23:51 +00:00
Sanjay Patel
e760878a95 [InstCombine] add a vector version of a test added in r291262; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291265 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-06 19:14:05 +00:00
Sanjay Patel
6435c8a3b0 [InstCombine] move and add tests for icmp + shl nsw; NFC
As discussed here:
http://lists.llvm.org/pipermail/llvm-dev/2017-January/108749.html
...we should be able to better optimize this pattern.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291262 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-06 18:57:54 +00:00
Matt Arsenault
6c6903a8c4 InstCombine: Fold cos(-x) -> cos(x)
Also cos(fabs(x)) -> cos(x)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291022 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-04 22:49:03 +00:00
David Majnemer
cc80c5c073 [InstCombine] Add a test for r290733
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290929 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-04 02:21:37 +00:00
David Majnemer
7f769abef4 [InstCombine] Move casts around shift operations
It is possible to perform a left shift before zero extending if the
shift would only shift out zeros.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290928 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-04 02:21:34 +00:00
David Majnemer
7a2e65f6d7 [InstCombine] Combine adds across a zext
We can perform the following:
(add (zext (add nuw X, C1)), C2) -> (zext (add nuw X, C1+C2))

This is only possible if C2 is negative and C2 is greater than or equal to negative C1.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290927 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-04 02:21:31 +00:00
Matt Arsenault
d0222fed31 InstCombine: Fold fabs on select of constants
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290913 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-03 22:40:34 +00:00
Sanjay Patel
3b6c9c19a0 [InstCombine] tighten checks for tests of assume -> metadata transform; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290903 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-03 19:32:11 +00:00
Matt Arsenault
f61ad6ec11 InstCombine: Add fma with constant transforms
DAGCombine already does these.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290860 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-03 04:32:35 +00:00
Matt Arsenault
ef6bacf05a InstCombine: Add fma + fabs/fneg transforms
fma (fneg x), (fneg y), z -> fma x, y, z
fma (fabs x), (fabs x), z -> fma x, x, z

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290859 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-03 04:32:31 +00:00
Sanjay Patel
5b08d8331e [InstCombine] add explanatory comment to test; NFC
The test was added at r290797, and a patch to enable the transform is proposed in D28204.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290798 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-01 18:20:49 +00:00
Sanjay Patel
b3a13c4218 [InstCombine] add test to show potential nonnull attribute propagation; NFC
This will change with the current draft of:
https://reviews.llvm.org/D28204


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290797 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-01 17:18:00 +00:00
Craig Topper
67125e9fcc [InstCombine][AVX-512] Teach InstCombine that llvm.x86.avx512.vcomi.sd and llvm.x86.avx512.vcomi.ss don't use the upper elements of their input.
This was already done for the SSE/SSE2 version of the intrinsics.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290776 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-31 00:45:06 +00:00
Craig Topper
bcb43e4e79 [InstCombine] Fix some of the AVX-512 scalar arithmetic test cases to do a better job of testing what they intended to test.
The accidentally had trivially dead code. Also needed to adjust the rounding mode to not CUR_DIRECTION so the intrinsics don't get converted to native operations before going through SimplifyDemandedVectorElts.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290702 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-29 02:29:04 +00:00
Michael Kuperstein
04912c8225 [InstCombine] Canonicalize insert splat sequences into an insert + shuffle
This adds a combine that canonicalizes a chain of inserts which broadcasts
a value into a single insert + a splat shufflevector.

This fixes PR31286.

Differential Revision: https://reviews.llvm.org/D27992


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290641 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-28 00:18:08 +00:00
George Burgess IV
3500d08b4b [Analysis] Ignore nobuiltin on allocsize function calls.
We currently ignore the `allocsize` attribute on functions calls with
the `nobuiltin` attribute when trying to lower `@llvm.objectsize`. We
shouldn't care about `nobuiltin` here: `allocsize` is explicitly added
by the user, not inferred based on a function's symbol.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290588 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-27 06:32:14 +00:00
Craig Topper
b7ae55eb2c [InstCombine][X86] Add DemandedElts support for 512-bit PMULDQ/PMULUDQ instructions
PMULDQ/PMULUDQ vXi64 instructions only use the even numbered v2Xi32 input elements which SimplifyDemandedVectorElts should try and use.

This builds on r290554 which added supported for 128 and 256-bit.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290582 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-27 05:30:09 +00:00
Craig Topper
e8c9abc07e [AVX-512][InstCombine] Teach InstCombine to turn masked scalar add/sub/mul/div with rounding intrinsics into normal IR operations if the rounding mode is CUR_DIRECTION.
An earlier commit added support for unmasked scalar operations. At that time isel wouldn't generate an optimal sequence for masked operations, but that has now been fixed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290566 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-27 01:56:30 +00:00
Craig Topper
de9bd8fc0c [InstCombine][AVX-512] Add masked scalar add/sub/mul/div intrinsic test cases that don't have a CUR_DIRECTION rounding mode.
The CUR_DIRECTION case will be optimized in a future commit so this provides coverage for the other cases.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290565 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-27 01:56:27 +00:00
Craig Topper
3900e637a2 [AVX-512][InstCombine] Teach InstCombine to turn packed add/sub/mul/div with rounding intrinsics into normal IR operations if the rounding mode is CUR_DIRECTION.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290559 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-27 00:23:16 +00:00
Simon Pilgrim
915b45f09f [InstCombine][X86] Add DemandedElts support for PMULDQ/PMULUDQ instructions
PMULDQ/PMULUDQ vXi64 instructions only use the even numbered v2Xi32 input elements which SimplifyDemandedVectorElts should try and use.

Differential Revision: https://reviews.llvm.org/D28119

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290554 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-26 23:28:17 +00:00
Craig Topper
a7c4539a02 [AVX-512][InstCombine] Teach InstCombine to turn scalar add/sub/mul/div with rounding intrinsics into normal IR operations if the rounding mode is CUR_DIRECTION.
Summary:
I only do this for unmasked cases for now because isel is failing to fold the mask. I'll try to fix that soon.

I'll do the same thing for packed add/sub/mul/div in a future patch.

Reviewers: delena, RKSimon, zvi, craig.topper

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D27879

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290535 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-26 06:33:19 +00:00
Craig Topper
e6e82fb3ab [AVX-512][InstCombine] Teach InstCombine to converted masked vpermv intrinsics into shufflevector instructions
Summary:
This patch adds support for converting the masked vpermv intrinsics into shufflevector instructions if the indices are constants.

We also need to wrap a select instruction around the shuffle to take care of the masking part. InstCombine will take care of optimizing the select if the mask is constant so I didn't bother checking for that.

Reviewers: zvi, delena, spatel, RKSimon

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D27825

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290530 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-25 23:58:57 +00:00
Simon Pilgrim
8ebe3e8df4 [InstCombine][X86] Add tests showing missed opportunities to simplify PMULUDQ/PMULDQ inputs.
PMULUDQ/PMULDQ - only the even elements (0, 2, 4, 6) of the vXi32 inputs are required.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290502 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-24 17:30:19 +00:00
David Majnemer
6be18b9049 Revert "[InstCombine] New opportunities for FoldAndOfICmp and FoldXorOfICmp"
This reverts commit r289813, it caused PR31449.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290266 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-21 19:21:59 +00:00
Sanjay Patel
1fd371a473 [InstCombine] use commutative matcher for pattern with commutative operators
This is a case that was missed in:
https://reviews.llvm.org/rL290067
...and it would regress if we fix operand complexity (PR28296).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290127 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-19 18:35:37 +00:00
Sanjay Patel
63e1cbe0bb [InstCombine] add folds for icmp (umin|umax X, Y), X
This is a follow-up to:
https://reviews.llvm.org/rL289855 (https://reviews.llvm.org/D27531)
https://reviews.llvm.org/rL290111


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290118 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-19 17:32:37 +00:00
Sanjay Patel
21b74be87d [InstCombine] add folds for icmp (smax X, Y), X
This is a follow-up to:
https://reviews.llvm.org/rL289855 (D27531)



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290111 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-19 16:28:53 +00:00
Daniel Jasper
8de3a54f07 Revert @llvm.assume with operator bundles (r289755-r289757)
This creates non-linear behavior in the inliner (see more details in
r289755's commit thread).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290086 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-19 08:22:17 +00:00
Sanjay Patel
6fd764e6d9 [InstCombine] use commutative matchers for patterns with commutative operators
Background/motivation - I was circling back around to:
https://llvm.org/bugs/show_bug.cgi?id=28296

I made a simple patch for that and noticed some regressions, so added test cases for
those with rL281055, and this is hopefully the minimal fix for just those cases.

But as you can see from the surrounding untouched folds, we are missing commuted patterns
all over the place, and of course there are no regression tests to cover any of those cases.

We could sprinkle "m_c_" dust all over this file and catch most of the missing folds, but 
then we still wouldn't have test coverage, and we'd still miss some fraction of commuted 
patterns because they require adjustments to the match order.

I'm aware of the concern about the potential compile-time performance impact of adding 
matches like this (currently being discussed on llvm-dev), but I don't think there's any
evidence yet to suggest that handling commutative pattern matching more thoroughly is not
a worthwhile goal of InstCombine.

Differential Revision: https://reviews.llvm.org/D24419


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290067 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-18 18:49:48 +00:00
Sanjay Patel
f250e34d2d [InstCombine] auto-generate checks; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289959 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-16 16:58:54 +00:00
Davide Italiano
7a05aeb9e2 [SimplifyLibCalls] Add a test to make sure we lower fls(0) correctly.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289895 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-15 23:48:07 +00:00
Davide Italiano
d956fc2438 [SimplifyLibCalls] Lower fls() to llvm.ctlz().
Differential Revision:  https://reviews.llvm.org/D14590

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289894 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-15 23:45:11 +00:00
Sanjay Patel
8ca87b1e6e [InstCombine] add folds for icmp (smin X, Y), X
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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289855 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-15 19:13:37 +00:00
Ehsan Amiri
7b626dfd62 [InstCombine] New opportunities for FoldAndOfICmp and FoldXorOfICmp
A number of new patterns for simplifying and/xor of icmp:

(icmp ne %x, 0) ^ (icmp ne %y, 0) => icmp ne %x, %y if the following is true:
1- (%x = and %a, %mask) and (%y = and %b, %mask)
2- %mask is a power of 2.

(icmp eq %x, 0) & (icmp ne %y, 0) => icmp ult %x, %y if the following is true:
1- (%x = and %a, %mask1) and (%y = and %b, %mask2)
2- Let %t be the smallest power of 2 where %mask1 & %t != 0. Then for any
   %s that is a power of 2 and %s & %mask2 != 0, we must have %s <= %t.
For example if %mask1 = 24 and %mask2 = 16, setting %s = 16 and %t = 8
violates condition (2) above. So this optimization cannot be applied.




git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289813 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-15 12:25:13 +00:00
Craig Topper
d941d3f22f [AVX-512][InstCombine] Add masked scalar FMA intrinsics to SimplifyDemandedVectorElts.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289759 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-15 03:49:45 +00:00
Hal Finkel
fe647d2183 Make processing @llvm.assume more efficient by using operand bundles
There was an efficiency problem with how we processed @llvm.assume in
ValueTracking (and other places). The AssumptionCache tracked all of the
assumptions in a given function. In order to find assumptions relevant to
computing known bits, etc. we searched every assumption in the function. For
ValueTracking, that means that we did O(#assumes * #values) work in InstCombine
and other passes (with a constant factor that can be quite large because we'd
repeat this search at every level of recursion of the analysis).

Several of us discussed this situation at the last developers' meeting, and
this implements the discussed solution: Make the values that an assume might
affect operands of the assume itself. To avoid exposing this detail to
frontends and passes that need not worry about it, I've used the new
operand-bundle feature to add these extra call "operands" in a way that does
not affect the intrinsic's signature. I think this solution is relatively
clean. InstCombine adds these extra operands based on what ValueTracking, LVI,
etc. will need and then those passes need only search the users of the values
under consideration. This should fix the computational-complexity problem.

At this point, no passes depend on the AssumptionCache, and so I'll remove
that as a follow-up change.

Differential Revision: https://reviews.llvm.org/D27259

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289755 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-15 02:53:42 +00:00
Craig Topper
b1003083d7 [X86][InstCombine] Handle demanded elements for operand of AVX-512 scalar floating point to integer conversion intrinsics.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289639 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-14 07:46:12 +00:00
Craig Topper
2eef9bcab6 [X86][InstCombine] Teach SimplifyDemandedVectorElts to handle masked scalar add/sub/mul/div/max/min intrinsics better.
Now we can remove these intrinsics if element 0 isn't used. Also fix undef element tracking.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289636 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-14 06:06:58 +00:00
Craig Topper
f19ce9bb49 [X86][InstCombine] Fix SimplifyDemandedVectorElts to handle frcz scalar intrinsics correctly.
Only the lower bits of the input element are used. And only the lower element can be undef since the upper bits are zeroed.

Have InstCombineCalls call SimplifyDemandedVectorElts for these intrinsics to reuse this support.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289523 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-13 07:45:45 +00:00
Sanjay Patel
123996f5e7 remove stale FIXME note from test; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289445 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-12 16:20:21 +00:00
Sanjay Patel
bbe630400d [InstCombine] fix bug when offsetting case values of a switch (PR31260)
We could truncate the condition and then try to fold the add into the
original condition value causing wrong case constants to be used.

Move the offset transform ahead of the truncate transform and return
after each transform, so there's no chance of getting confused values.

Fix for:
https://llvm.org/bugs/show_bug.cgi?id=31260


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289442 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-12 16:13:52 +00:00
Sanjay Patel
3ca6ce4aa6 [InstCombine] add test to show PR31260 miscompile; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289437 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-12 15:28:44 +00:00
Craig Topper
e25a2790d2 [InstCombine][XOP] The instructions for the scalar frcz intrinsics are defined to put 0 in the upper bits, not pass bits through like other intrinsics. So we should return a zero vector instead.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289411 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-11 22:32:38 +00:00
Sanjoy Das
a942d77488 [Verifier] Add verification for TBAA metadata
Summary:
This change adds some verification in the IR verifier around struct path
TBAA metadata.

Other than some basic sanity checks (e.g. we get constant integers where
we expect constant integers), this checks:

 - That by the time an struct access tuple `(base-type, offset)` is
   "reduced" to a scalar base type, the offset is `0`.  For instance, in
   C++ you can't start from, say `("struct-a", 16)`, and end up with
   `("int", 4)` -- by the time the base type is `"int"`, the offset
   better be zero.  In particular, a variant of this invariant is needed
   for `llvm::getMostGenericTBAA` to be correct.

 - That there are no cycles in a struct path.

 - That struct type nodes have their offsets listed in an ascending
   order.

 - That when generating the struct access path, you eventually reach the
   access type listed in the tbaa tag node.

Reviewers: dexonsmith, chandlerc, reames, mehdi_amini, manmanren

Subscribers: mcrosier, llvm-commits

Differential Revision: https://reviews.llvm.org/D26438

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289402 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-11 20:07:15 +00:00
Craig Topper
98435b8bdf [X86][InstCombine] Add support for scalar FMA intrinsics to SimplifyDemandedVectorElts.
This teaches SimplifyDemandedElts that the FMA can be removed if the lower element isn't used. It also teaches it that if upper elements of the first operand aren't used then we can simplify them.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289377 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-11 08:54:52 +00:00
Craig Topper
70493cff6f [X86][InstCombine] Add the test cases for r289370, r289371, and r289372.
I forgot to add the new files before commiting.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289374 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-11 08:00:51 +00:00
Craig Topper
f3e3617e77 [AVX-512][InstCombine] Add 512-bit vpermilvar intrinsics to InstCombineCalls to match 128 and 256-bit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289354 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-11 01:59:36 +00:00
Craig Topper
7c8796bdf5 [X86][InstCombine] Teach InstCombineCalls to turn pshufb intrinsic into a shufflevector if the indices are constant.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289348 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-11 00:23:50 +00:00
Sanjay Patel
c828f5b04a [InstCombine] add tests for umin+icmp; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289157 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-08 23:44:58 +00:00
Sanjay Patel
d0dc2aae8c [InstCombine] add tests for umax+icmp; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289156 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-08 23:36:57 +00:00
Sanjay Patel
0261b12fff [InstCombine] add tests for smax+icmp; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289151 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-08 23:16:06 +00:00
Matt Arsenault
98b1edd6bb InstCombine: Fold bitcast of vector to FP scalar
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288978 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-07 20:56:11 +00:00
Sanjay Patel
8b90b13aa1 [InstCombine] add tests for smin+icmp; NFC
The tests that already work are folded in InstSimplify, so those
tests should be redundant and we can remove them if they don't
seem worthwhile for completeness.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288957 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-07 18:56:55 +00:00
Sanjay Patel
20e9431b19 [InstCombine] change select type to eliminate bitcasts
This solves a secondary problem seen in PR6137:
https://llvm.org/bugs/show_bug.cgi?id=6137#c6

This is similar to the bitwise logic op fold added with:
https://reviews.llvm.org/rL287707

And like that patch, I'm artificially restricting the
transform from vector <-> scalar types until we're sure
that the backend can handle that. 


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288584 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-03 15:25:16 +00:00
Simon Pilgrim
88afddf69a [InstCombine] Add vector urem tests
Demonstrate missed opportunity for urem -> and combine for powerof2 or zero non-uniform constant dividers

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288510 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-02 17:16:21 +00:00
Simon Pilgrim
d2c7981604 [InstCombine] Regenerate vector srem tests
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288509 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-02 17:12:56 +00:00
Philip Reames
ed7960709b [PR29121] Don't fold if it would produce atomic vector loads or stores
The instcombine code which folds loads and stores into their use types can trip up if the use is a bitcast to a type which we can't directly load or store in the IR. In principle, such types shouldn't exist, but in practice they do today. This is a workaround to avoid a bug while we work towards the long term goal.

Differential Revision: https://reviews.llvm.org/D24365



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288415 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-01 20:17:06 +00:00
Sanjay Patel
b34fe0f02f [InstCombine] allow more narrowing transforms for logic ops
We had a limited version of this for scalar 'and'; this expands
the transform to 'or' and 'xor' and allows vectors types too.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288273 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-30 20:48:54 +00:00
Sanjay Patel
ba32f788d8 [InstCombine] add tests to show potentially missed logic+trunc transforms; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288270 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-30 20:20:49 +00:00
Sanjay Patel
785e64db06 [InstCombine] update test to use FileCheck and auto-generate checks; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288261 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-30 18:49:56 +00:00
Sanjay Patel
5ed39f2608 [InstCombine] auto-generate checks for select+bitwise logic tests; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288254 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-30 17:07:21 +00:00
Sanjay Patel
52894d83e1 [InstCombine] add test to show missing vector optimization; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287982 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-26 16:13:23 +00:00
Sanjay Patel
adc3b91add [InstCombine] don't drop metadata in FoldOpIntoSelect()
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287980 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-26 15:23:20 +00:00
Sanjay Patel
fe998e6ec2 [InstCombine] change bitwise logic type to eliminate bitcasts
In PR27925:
https://llvm.org/bugs/show_bug.cgi?id=27925

...we proposed adding this fold to eliminate a bitcast. In D20774, there was 
some concern about changing the type of a bitwise op as well as creating 
bitcasts that might not be free for a target. However, if we're strictly 
eliminating an instruction (by limiting this to one-use ops), then we should 
be able to do this in InstCombine.

But we're cautiously restricting the transform for now to vector types to
avoid possible backend problems. A transform to make sure the logic op is
legal for the target should be added to reverse this transform and improve
codegen.

Differential Revision: https://reviews.llvm.org/D26641



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287707 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-22 22:05:48 +00:00
Sanjay Patel
fea0530bd5 [InstCombine] canonicalize min/max constant to select's false value
This is a first step towards canonicalization and improved folding/codegen
for integer min/max as discussed here:
http://lists.llvm.org/pipermail/llvm-dev/2016-November/106868.html

Here, we're just matching the simplest min/max patterns and adjusting the
icmp predicate while swapping the select operands.

I've included FIXME tests in test/Transforms/InstCombine/select_meta.ll
so it's easier to see how this might be extended (corresponds to the TODO
comment in the code). That's also why I'm using matchSelectPattern()
rather than a simpler check; once the backend is patched, we can just 
remove some of the restrictions to allow the obfuscated min/max patterns
in the FIXME tests to be matched.

Differential Revision: https://reviews.llvm.org/D26525


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287585 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-21 22:04:14 +00:00
Yaxun Liu
f570b5fd16 Fix known zero bits for addrspacecast.
Currently LLVM assumes that a pointer addrspacecasted to a different addr space is equivalent to trunc or zext bitwise, which is not true. For example, in amdgcn target, when a null pointer is addrspacecasted from addr space 4 to 0, its value is changed from i64 0 to i32 -1.

This patch teaches LLVM not to assume known bits of addrspacecast instruction to its operand.

Differential Revision: https://reviews.llvm.org/D26803


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287545 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-21 15:42:31 +00:00
Sanjay Patel
c4506a3311 [InstCombine] add tests to show likely unwanted select widening; NFC
This is a prerequisite patch for D26556:
https://reviews.llvm.org/D26556

...because there was no direct coverage for these folds (which in some cases are adding instructions).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287400 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-18 23:22:00 +00:00
Craig Topper
35b775d13a [InstCombine][AVX-512] Teach InstCombineCalls how to handle the intrinsics for variable shift with 16-bit elements.
This is a straightforward extension of the existing support for 32/64-bit element types. Just needed to add the additional instrinsics to the switches.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287316 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-18 06:04:33 +00:00
Craig Topper
614df99de4 [X86] Remove the scalar intrinsics for fadd/fsub/fdiv/fmul
Summary: These intrinsics have been unused for clang for a while. This patch removes them. We auto upgrade them to extractelements, a scalar operation and then an insertelement. This matches the sequence used by clangs intrinsic file.

Reviewers: zvi, delena, RKSimon

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D26660

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287083 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-16 05:24:10 +00:00
Sanjay Patel
33942aedc5 [InstCombine] add tests for bitcasted selects; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286978 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-15 16:01:16 +00:00
Sanjay Patel
34e48658bb [InstCombine] add tests to show missing bitcast folds
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286900 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-14 22:44:06 +00:00
Craig Topper
e59ef16ac1 [InstCombine][AVX-512] Teach InstCombineCalls to handle the new unmasked AVX-512 variable shift intrinsics.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286755 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-13 07:26:19 +00:00
Craig Topper
eb14a74d58 [InstCombine][AVX-512] Expand vector shift handling to work on the AVX-512 shift by immediate and shift by single value.
This does not include support for the AVX-512 variable shifts. That will be coming in a future patch.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286739 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-13 01:51:55 +00:00
Sanjay Patel
8d3ad734d2 [InstCombine] update test to use FileCheck; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286668 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 23:12:46 +00:00
Sanjay Patel
a27bda70c2 [InstCombine] add tests to show size-increasing select transforms
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286619 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-11 19:37:54 +00:00
Sanjay Patel
80dc268da9 [InstCombine] auto-generate better checks; NFC
Note that the existing metadata checking was re-added by hand because the 
script doesn't currently know how to generate checks for lines outside of 
functions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286460 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-10 14:58:17 +00:00
Sanjay Patel
9c5e4bac4a [InstCombine] avoid infinite loop from shuffle-extract-insert sequence (PR30923)
Removing the limitation in visitInsertElementInst() causes several regressions
because we're not prepared to fold sequences of shuffles or inserts and extracts
separated by shuffles. Fixing that appears to be a difficult mission because we
are purposely trying to avoid creating shuffles with arbitrary shuffle masks
because some targets may choke on those.

https://llvm.org/bugs/show_bug.cgi?id=30923


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286423 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-10 00:15:14 +00:00
Sanjay Patel
b347251bf7 [InstCombine] regenerate checks; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286402 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-09 22:21:58 +00:00
Sanjay Patel
c4a40a2d62 [InstCombine] regenerate checks; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286399 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-09 21:41:34 +00:00
Sanjay Patel
6382ee0e42 [InstCombine] fix profitability equation for max-of-nots transform
As the test change shows, we can increase the critical path by adding
a 'not' instruction, so make sure that we're actually removing an
instruction if we do this transform.

This transform could also cause us to miss folds of min/max pairs.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286315 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-09 00:13:11 +00:00
Davide Italiano
9579593784 [LibcallsShrinkWrap] This pass doesn't preserve the CFG.
For example, it invalidates the domtree, causing assertions
in later passes which need dominator infos. Make it preserve
GlobalsAA, as suggested by Eli.

Differential Revision:  https://reviews.llvm.org/D26381

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286271 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-08 19:18:20 +00:00
Sanjay Patel
9feaaa3644 [InstCombine] move min/max tests to min/max test file; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286256 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-08 18:12:19 +00:00
Sanjay Patel
f153cd7405 [InstCombine] update checks; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286255 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-08 18:06:14 +00:00
Sanjay Patel
901ccced28 [InstCombine] allow splat vector folds in adjustMinMax() (retry r285732)
This was reverted at r285866 because there was a crash handling a scalar
select of vectors. I added a check for that pattern and a test case based
on the example provided in the post-commit thread for r285732.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286113 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-07 15:52:45 +00:00
Greg Bedwell
2ad749ea5e Revert "[InstCombine] allow splat vector folds in adjustMinMax()"
This reverts commit r285732.

This change introduced a new assertion failure in the following
testcase at -O2:

typedef short __v8hi __attribute__((__vector_size__(16)));
__v8hi foo(__v8hi &V1, __v8hi &V2, unsigned mask) {
  __v8hi Result = V1;
  if (mask & 0x80)
    Result[0] = V2[0];
  return Result;
}

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285866 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-02 23:17:05 +00:00
Sanjay Patel
b40f34e4b3 [InstCombine] allow splat vector folds in adjustMinMax()
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285732 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-01 20:08:02 +00:00
Sanjay Patel
e7291efa87 [InstCombine] Fold nuw left-shifts in ugt/ule comparisons.
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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285729 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-01 19:19:29 +00:00
Sanjay Patel
ee817c2c96 [InstCombine] add vector tests for ext+adjust min/max
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285713 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-01 17:34:29 +00:00
Sanjay Patel
eee7c89f77 [InstCombine] move/fix tests for adjusted min/max
I think the former 'test50' had a typo making it functionally equivalent
to the former 'test49'; changed the predicate to provide more coverage.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285706 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-01 16:39:30 +00:00
Sanjay Patel
caa8396841 [InstCombine] fix tests for adjusted min/max
1. Delete identical tests
2. Rename tests to reflect actual functionality
3. Add comments
4. Add unsigned variants
5. Add vector variants with FIXME comments
6. Rename test file


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285699 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-01 15:48:30 +00:00
Simon Pilgrim
cf8d4833fd [InstCombine] Folding of shifts by the sum of positive values
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285696 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-01 15:40:30 +00:00