112 Commits

Author SHA1 Message Date
Craig Topper 7e1904e9c8 Recommit r317510 "[InstCombine] Pull shifts through a select plus binop with constant"
The hexagon test should be fixed now.

Original commit message:

This pulls shifts through a select+binop with a constant where the select conditionally executes the binop. We already do this for just the binop, but not with the select.

This can allow us to get the select closer to other selects to enable removing one.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317600 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-07 18:47:24 +00:00
Hans Wennborg e209a1a12d Revert r317510 "[InstCombine] Pull shifts through a select plus binop with constant"
This broke the CodeGen/Hexagon/loop-idiom/pmpy-mod.ll test on a bunch of buildbots.

> This pulls shifts through a select+binop with a constant where the select conditionally executes the binop. We already do this for just the binop, but not with the select.
>
> This can allow us to get the select closer to other selects to enable removing one.
>
> Differential Revision: https://reviews.llvm.org/D39222
>
> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317510 91177308-0d34-0410-b5e6-96231b3b80d8

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317518 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-06 22:28:02 +00:00
Craig Topper aceaaf0aec [InstCombine] Pull shifts through a select plus binop with constant
This pulls shifts through a select+binop with a constant where the select conditionally executes the binop. We already do this for just the binop, but not with the select.

This can allow us to get the select closer to other selects to enable removing one.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317510 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-06 21:07:22 +00:00
Amjad Aboud 0388fb65f3 [InstCombine] Added support for (X >>s C) << C --> X & (-1 << C)
Differential Revision: https://reviews.llvm.org/D36743


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310949 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-15 19:33:14 +00:00
Craig Topper 996d9b5480 [ValueTracking] Correct early out in computeKnownBitsFromOperator to work with non power of 2 bit widths
There's an early out that's trying to detect when we don't know any bits that make up the legal range of a shift. The code subtracts one from BitWidth which creates a mask in the lower bits for power of 2 bit widths. This is then ANDed with the known bits to see if any of those bits are known. If the bit width isn't a power of 2 this creates a non-sensical mask.

This patch corrects this by rounding up to a power of 2 before doing the subtract and mask.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305400 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-14 17:04:59 +00:00
Sanjay Patel e29c6aab81 [InstCombine] allow shl+shr demanded bits folds with splat constants
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300911 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-20 22:33:54 +00:00
Sanjay Patel c086bdaf50 [InstCombine] add tests for shl+shr demanded bits splat vector folds; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300907 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-20 22:18:47 +00:00
Sanjay Patel a24f137360 [InstCombine] allow shl demanded bits folds with splat constants
More fixes are needed to enable the helper SimplifyShrShlDemandedBits().



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300898 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-20 21:33:02 +00:00
Sanjay Patel f0d51838c5 [InstCombine] allow ashr/lshr demanded bits folds with splat constants
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300888 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-20 20:59:02 +00:00
Sanjay Patel cef604c5bb [InstCombine] add tests for demanded bits ashr/lshr splat constants; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300884 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-20 20:44:54 +00:00
Sanjay Patel 126da6d52b [InstCombine] enable (X <<nsw C1) >>s C2 --> X <<nsw (C1 - C2) for vectors with splat constants
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293570 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-30 23:35:52 +00:00
Sanjay Patel deb5ed0b1a [InstCombine] add vector test for (X <<nsw C1) >>s C2 --> X <<nsw (C1 - C2); NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293566 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-30 23:26:17 +00:00
Sanjay Patel 222619278d [InstCombine] enable more lshr(shl X, C1), C2 folds for vectors with splat constants
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293562 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-30 23:01:05 +00:00
Sanjay Patel fdcb936596 [InstCombine] add tests for more shift-shift patterns; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293555 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-30 22:24:36 +00:00
Sanjay Patel 1790b5fe1c [InstCombine] enable (X >>?exact C1) << C2 --> X >>?exact (C1-C2) for vectors with splat constants
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293524 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-30 18:40:23 +00:00
Sanjay Patel 913f418dfb [InstCombine] add vector splat tests for (X >>?exact C1) << C2 --> X >>?exact (C1-C2); NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293517 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-30 18:17:14 +00:00
Sanjay Patel 093eb4f6ff [InstCombine] enable (X <<nsw C1) >>s C2 --> X <<nsw (C1-C2) for vectors with splat constants
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293507 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-30 17:19:32 +00:00
Sanjay Patel f406e8165b [InstCombine] fixed to propagate 'exact' on lshr
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!



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293498 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-30 16:53:03 +00:00
Sanjay Patel c15acfb9b1 [InstCombine] add 'exact' to lshr to show that it got dropped; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293496 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-30 16:38:49 +00:00
Sanjay Patel 00794ce70d [InstCombine] enable lshr(shl X, C1), C2 folds for vectors with splat constants
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293489 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-30 16:11:40 +00:00
Sanjay Patel c8ac2767b6 [InstCombine] add tests for shift-shift patterns; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293487 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-30 15:54:50 +00:00
Sanjay Patel 3a412958e7 [InstCombine] enable (X >>?,exact C1) << C2 --> X << (C2 - C1) for vectors with splats
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293435 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-29 17:11:18 +00:00
Sanjay Patel c7576ae80d [InstCombine] add tests for shl(shr X, C1), C2 transforms; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293434 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-29 16:52:59 +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 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
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 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
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
Sanjay Patel bb4b1d9adf [InstCombine] use m_APInt to allow icmp X, C folds for splat constant vectors
isSignBitCheck could be changed to take a pointer param to avoid the 'UnusedBit' ugliness.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281231 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-12 16:25:41 +00:00
Sanjay Patel 3e9ba2b6c4 [InstCombine] add tests to show missing vector folds
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281219 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-12 15:51:42 +00:00
Sanjay Patel 2c15995350 [InstCombine] use m_APInt to allow icmp (and X, Y), C folds for splat constant vectors
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279937 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-28 18:18:00 +00:00
Sanjay Patel 66b84ccb05 [InstCombine] use m_APInt to allow icmp eq/ne (shr X, C2), C folds for splat constant vectors
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279677 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-24 22:22:06 +00:00
Sanjay Patel 207248202b remove FIXME comment; fixed by previous commit
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279400 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-21 16:40:42 +00:00
Sanjay Patel ecce337063 [InstCombine] use m_APInt to allow icmp (shl X, Y), C folds for splat constant vectors, part 3
This is a partial enablement (move the ConstantInt guard down).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279399 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-21 16:35:34 +00:00
Sanjay Patel 8454221022 [InstCombine] add tests for missing vector icmp folds
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278768 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-16 00:48:38 +00:00
Sanjay Patel a451d6b7d4 [InstCombine] add test for missing vector icmp fold
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278708 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-15 18:39:54 +00:00
Sanjay Patel 3d09ca24ae minimize test
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278707 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-15 18:35:44 +00:00
Sanjay Patel cc96a8ce86 remove unnecessary IR comments about uses
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278705 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-15 18:32:50 +00:00
Sanjay Patel 8b850ac940 [InstCombine] add tests for missing vector icmp folds
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278704 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-15 18:26:56 +00:00
Sanjay Patel bc87c37f6b [InstCombine] add test for missing vector icmp fold
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278635 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-14 22:29:27 +00:00
Sanjay Patel 56708009f1 [ValueTracking, InstCombine] extend isKnownToBeAPowerOfTwo() to handle vector splat constants
We could try harder to handle non-splat vector constants too, 
but that seems much rarer to me.

Note that the div test isn't resolved because there's a check
for isIntegerTy() guarding that transform.

Differential Revision: http://reviews.llvm.org/D20497



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270369 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-22 15:41:53 +00:00
Sanjay Patel 45022fd14b add test for vector shift
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270284 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-20 22:08:16 +00:00
Sanjay Patel e3b561ea48 [InstCombine] regenerate checks
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268245 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-02 15:32:10 +00:00
Rafael Espindola a2197f8f51 Have a single way for creating unique value names.
We had two code paths. One would create names like "foo.1" and the other
names like "foo1".

For globals it is important to use "foo.1" to help C++ name demangling.
For locals there is no strong reason to go one way or the other so I
kept the most common mangling (foo1).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253804 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-22 00:16:24 +00:00
Sunil Srivastava 561c44fc33 Changed renaming of local symbols by inserting a dot vefore the numeric suffix.
One code change and several test changes to match that
details in http://reviews.llvm.org/D9481


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237150 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-12 16:47:30 +00:00
David Majnemer 72c6bdbf70 ConstantFold, InstSimplify: undef >>a x can be either -1 or 0, choose 0
Zero is usually a nicer constant to have than -1.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223969 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-10 21:58:15 +00:00
Ankur Garg df35082f20 [test/Transforms/InstCombine/shift.ll] Removed duplicate test cases. NFC.
Removed some duplicate test cases from the file /test/Transforms/InstCombine/shift.ll.

test54 and test57 were duplicates of each other.
test55 and test58 were duplicates of each other.

(Removed test57 and test58)



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223767 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09 10:35:19 +00:00
Sonam Kumari a585ec7f7f Removal Of Duplicate Test Case from shift.ll file
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223648 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-08 09:40:43 +00:00
Matt Arsenault 448a1a0734 Revert "Revert r206045, "Fix shift by constants for vector.""
Fix cases where the Value itself is used, and not the constant value.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206214 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-14 21:50:37 +00:00