561 Commits

Author SHA1 Message Date
Sanjay Patel
7ae81d5c8b [InstCombine] allow icmp (and X, C2), C1 folds for splat constant vectors
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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280637 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-04 20:58:27 +00:00
Sanjay Patel
e57e8b4c4c [InstCombine] recode icmp fold in a vector-friendly way; NFC
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.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280627 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-04 14:32:15 +00:00
Sanjay Patel
36ff41aa37 [InstCombine] remove fold of an icmp pattern that should never happen
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 


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280370 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-01 14:20:43 +00:00
Sanjay Patel
8aee946406 [InstCombine] allow icmp (shr exact X, C2), C fold for splat constant vectors
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280300 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-31 22:18:43 +00:00
Sanjay Patel
bfcd22b81a [InstCombine] allow icmp (div X, Y), C folds for splat constant vectors
Converting all of the overflow ops to APInt looked risky, so I've left that as a TODO.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280299 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-31 21:57:21 +00:00
Sanjay Patel
ebc9efbb36 [InstCombine] change insertRangeTest() to use APInt instead of Constant; NFCI
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280282 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-31 19:49:56 +00:00
Sanjay Patel
f097e134b1 [InstCombine] replace divide-by-constant checks with asserts; NFC
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280115 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-30 17:31:34 +00:00
Sanjay Patel
558d668cc4 [InstCombine] clean up foldICmpDivConstant; NFCI
1. Fix comments to match variable names
2. Remove redundant CmpRHS variable
3. Add FIXME to replace some checks with asserts


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280112 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-30 17:10:49 +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
d96bcc0e97 [InstCombine] add helper function for icmp (and (sh X, Y), C2), C1 ; NFC
Like other recent changes near here, the goal is to allow vector types for
all of these folds. Splitting things up makes it easier to incrementally 
enhance the code and easier to read.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279851 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-26 18:28:46 +00:00
Sanjay Patel
c3dc8a9df0 [InstCombine] clean up foldICmpAndConstConst(); NFC
1. Early exit to reduce indent
2. Fix comments and variable names to match
3. Reformat comments / clang-format code


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279837 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-26 17:15:22 +00:00
Sanjay Patel
a14798a5aa [InstCombine] add helper function for folding of icmp (and X, C2), C; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279834 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-26 16:42:33 +00:00
Sanjay Patel
f222adf433 [InstCombine] rename variables in foldICmpAndConstant(); NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279831 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-26 16:14:06 +00:00
Sanjay Patel
dada7d489d [InstCombine] rename variables in foldICmpDivConstant(); NFC
Removing the redundant 'CmpRHSV' local variable exposes a bug in the caller
foldICmpShrConstant() - it was sending in the div constant instead of the
cmp constant. But I have not been able to expose this in a regression test
yet - the affected folds all appear to be handled before we ever reach this
code. I'll keep trying to find a case as I make changes to allow vector folds
in both functions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279828 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-26 15:53:01 +00:00
Sanjay Patel
1b1bb955bb [InstCombine] move foldICmpDivConstConst() contents to foldICmpDivConstant(); NFCI
There was no logic in foldICmpDivConstant, so no need for a separate function.
The code is directly copy/pasted, so further cleanups to follow.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279685 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-24 23:03:36 +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
b403b76460 [InstCombine] add assert and explanatory comment for fold removed in r279568; NFC
I deleted a fold from InstCombine at:
https://reviews.llvm.org/rL279568

because it (like any InstCombine to a constant?) should always happen in InstSimplify,
however, it's not obvious what the assumptions are in the remaining code.

Add a comment and assert to make it clearer.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279626 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-24 13:55:55 +00:00
Sanjay Patel
35f70a7129 [InstCombine] use local variables for repeated values; NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279578 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-23 22:05:55 +00:00
Sanjay Patel
e9aa7e0db9 [InstCombine] move foldICmpShrConstConst() contents to foldICmpShrConst(); NFCI
There will only be 3 lines of code in foldICmpShrConst() when the cleanup is done,
so it doesn't make much sense to have a separate function for a single fold.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279575 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-23 21:25:13 +00:00
Sanjay Patel
4cc20beb70 [InstCombine] remove icmp shr folds that are already handled by InstSimplify
AFAICT, these already worked in all cases for scalar types, and I enhanced
the code to work for vector types in:
https://reviews.llvm.org/rL279543


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279568 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-23 21:01:35 +00:00
Sanjay Patel
0fd3c95310 [InstCombine] change param type from Instruction to BinaryOperator for icmp helpers; NFCI
This saves some casting in the helper functions and eases some further refactoring.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279478 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-22 21:24:29 +00:00
Sanjay Patel
e3ecb56f22 [InstCombine] use m_APInt to allow icmp (shr exact X, Y), 0 folds for splat constant vectors
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279472 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-22 20:45:06 +00:00
Sanjay Patel
a690e12aba [InstCombine] use m_APInt to allow icmp (shl X, Y), C folds for splat constant vectors, part 4
This concludes the fixes for icmp+shl in this series:
https://reviews.llvm.org/rL279339
https://reviews.llvm.org/rL279398
https://reviews.llvm.org/rL279399



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279401 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-21 17:10:07 +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
a5d876194d [InstCombine] use m_APInt to allow icmp (shl X, Y), C folds for splat constant vectors, part 2
This is a partial enablement (move the ConstantInt guard down).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279398 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-21 16:28:22 +00:00
Sanjay Patel
e01d0578ca [InstCombine] use APInt instead of ConstantInt in isSignBitCheck(); NFCI
The callers still have ConstantInt guards, so there is no functional change
intended from this change. But relaxing the callers will allow more folds
for vector types.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279396 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-21 15:07:45 +00:00
Sanjay Patel
177fbef1aa [InstCombine] use m_APInt to allow icmp (shl X, Y), C folds for splat constant vectors, part 1
This is a partial enablement (move the ConstantInt guard down) because there are many
different folds here and one of the later ones will require reworking 'isSignBitCheck'.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279339 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-19 22:33:26 +00:00
Sanjay Patel
5eb5a080aa [InstCombine] remove an icmp fold that is already handled by InstSimplify
Specifically, this is done near the end of "SimplifyICmpInst" using 
computeKnownBits() as the broader solution. There are even vector
tests (yay!) for this in test/Transforms/InstSimplify/compare.ll.

I considered putting an assert here instead of just deleting, but
then we could assert every possible fold in InstSimplify in 
InstCombine, so...less is more?


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279300 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-19 19:03:07 +00:00
Sanjay Patel
0cb38859e1 [InstCombine] use local variables to reduce code in foldICmpShlConstant; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279282 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-19 17:34:05 +00:00
Sanjay Patel
f5027c2a06 [InstCombine] rename variables in foldICmpShlConstant(); NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279279 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-19 17:20:37 +00:00
Reid Kleckner
baeb19c0b9 Fix regression in InstCombine introduced by r278944
The intended transform is:
  // Simplify icmp eq (or (ptrtoint P), (ptrtoint Q)), 0
  // -> and (icmp eq P, null), (icmp eq Q, null).

P and Q are both pointer types, but may have different types. We need
two calls to getNullValue() to make the icmps.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279271 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-19 16:53:18 +00:00
Sanjay Patel
1238f8d56b [InstCombine] use m_APInt to allow icmp (shl 1, Y), C folds for splat constant vectors
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279266 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-19 16:12:16 +00:00
Sanjay Patel
ee783de739 [InstCombine] use m_APInt to allow icmp X, C folds for splat constant vectors
Of course, we really need to refactor and fix all of the cmp predicates, 
but this one is interesting because without it, we later perform an 
information-losing transform of icmp (shl 1, Y), C, and we can't recover
the better fold.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279263 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-19 15:40:44 +00:00
Sanjay Patel
c5ef0e6004 [InstCombine] add helper function for folds of icmp (shl 1, Y), C; NFCI
Clean up the existing code by:
1. Renaming variables
2. Adding local variables
3. Making it vector-safe

This is still guarded by a ConstantInt check, so no functional change is intended.
But this should be ready to go: if we move the ConstantInt check down, all of
these folds should do the right thing for vector types.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279150 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-18 21:28:30 +00:00
Sanjay Patel
d87f299ea2 [InstCombine] use m_APInt to allow icmp (trunc X, Y), C folds for splat constant vectors
This is a sibling of:
https://reviews.llvm.org/rL278859
https://reviews.llvm.org/rL278935
https://reviews.llvm.org/rL278945
https://reviews.llvm.org/rL279066
https://reviews.llvm.org/rL279077
https://reviews.llvm.org/rL279101


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279133 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-18 20:28:54 +00:00
Sanjay Patel
f17a9b62af [InstCombine] clean up foldICmpTruncConstant(); NFCI
1. Fix variable names
2. Add local variables to reduce code


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279132 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-18 20:25:16 +00:00
Sanjay Patel
030db6490a [InstCombine] use m_APInt to allow icmp (udiv X, Y), C folds for splat constant vectors
This is a sibling of:
https://reviews.llvm.org/rL278859
https://reviews.llvm.org/rL278935
https://reviews.llvm.org/rL278945
https://reviews.llvm.org/rL279066
https://reviews.llvm.org/rL279077


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279101 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-18 17:55:59 +00:00
Sanjay Patel
1197bbfe90 [InstCombine] clean up foldICmpUDivConstant; NFC
1. Better variable names
2. Remove unnecessary check of ConstantInt


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279094 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-18 17:37:26 +00:00
Sanjay Patel
1759316b11 [InstCombine] use m_APInt to allow icmp (mul X, Y), C folds for splat constant vectors
This is a sibling of:
https://reviews.llvm.org/rL278859
https://reviews.llvm.org/rL278935
https://reviews.llvm.org/rL278945
https://reviews.llvm.org/rL279066



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279077 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-18 15:44:44 +00:00
Sanjay Patel
dd00c508c0 [InstCombine] use APInt in isSignTest instead of ConstantInt; NFC
This will enable vector splat folding, but NFC until the callers
have their ConstantInt restrictions removed.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279072 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-18 14:59:14 +00:00
Sanjay Patel
94dd772827 [InstCombine] use m_APInt to allow icmp (xor X, Y), C folds for splat constant vectors
This is a sibling of:
https://reviews.llvm.org/rL278859
https://reviews.llvm.org/rL278935
https://reviews.llvm.org/rL278945


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279066 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-18 14:10:48 +00:00
Justin Bogner
7d7a23e700 Replace a few more "fall through" comments with LLVM_FALLTHROUGH
Follow up to r278902. I had missed "fall through", with a space.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278970 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-17 20:30:52 +00:00
Sanjay Patel
4633e7e9b7 [InstCombine] more clean up of foldICmpXorConstant(); NFCI
Use m_APInt for the xor constant, but this is all still guarded by the initial
ConstantInt check, so no vector types should make it in here.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278957 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-17 19:45:18 +00:00
Sanjay Patel
422136324a [InstCombine] clean up foldICmpXorConstant(); NFCI
1. Change variable names
2. Use local variables to reduce code
3. Early exit to reduce indent



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278955 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-17 19:23:42 +00:00
Sanjay Patel
9df37461f6 [InstCombine] use m_APInt to allow icmp (or X, Y), C folds for splat constant vectors
This is a sibling of:
https://reviews.llvm.org/rL278859
https://reviews.llvm.org/rL278935


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278945 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-17 16:38:57 +00:00
Sanjay Patel
dae0b11041 [InstCombine] clean up foldICmpOrConstant(); NFCI
1. Change variable names
2. Use local variables to reduce code
3. Use ? instead of if/else
4. Use the APInt variable instead of 'RHS' so the removal of the FIXME code will be direct


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278944 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-17 16:30:43 +00:00
Sanjay Patel
3b03767801 [InstCombine] use m_APInt to allow icmp (add X, Y), C folds for splat constant vectors
This is a sibling of:
https://reviews.llvm.org/rL278859



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278935 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-17 15:24:30 +00:00
Justin Bogner
6673ea81f6 Replace "fallthrough" comments with LLVM_FALLTHROUGH
This is a mechanical change of comments in switches like fallthrough,
fall-through, or fall-thru to use the LLVM_FALLTHROUGH macro instead.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278902 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-17 05:10:15 +00:00
Sanjay Patel
7de66517ad [InstCombine] clean up foldICmpAddConstant(); NFCI
1. Fix variable names
2. Add local variables to reduce code
3. Fix code comments
4. Add early exit to reduce indentation
5. Remove 'else' after if -> return
6. Hoist common predicate


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278864 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-16 22:34:42 +00:00
Sanjay Patel
764b87be23 [InstCombine] use m_APInt to allow icmp (sub X, Y), C folds for splat constant vectors
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278859 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-16 21:53:19 +00:00