591 Commits

Author SHA1 Message Date
Peter Collingbourne
06115803f9 IR: Change the gep_type_iterator API to avoid always exposing the "current" type.
Instead, expose whether the current type is an array or a struct, if an array
what the upper bound is, and if a struct the struct type itself. This is
in preparation for a later change which will make PointerType derive from
Type rather than SequentialType.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288458 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-02 02:24:42 +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
20cfefb146 [InstCombine] Ensure that truncated int types are legal.
Fixes the FIXMEs in D25952 and rL285075.

Patch by bryant!

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285108 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-25 20:11:47 +00:00
Sanjay Patel
ce0f082662 [InstCombine] add test and code comment to show potentially misguided icmp trunc transform
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285075 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-25 15:16:39 +00:00
Sanjoy Das
f6a95d4da8 Remove duplicated code; NFC
ICmpInst::makeConstantRange does exactly the same thing as
ConstantRange::makeExactICmpRegion.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283059 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-02 00:09:57 +00:00
Sanjay Patel
1af818627a [InstCombine] add helper functions for visitICmpInst(); NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281743 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-16 16:10:22 +00:00
Sanjay Patel
f094f6229a [InstCombine] move folds for icmp (sh C2, Y), C1 in with other icmp+sh folds; NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281672 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-15 22:26:31 +00:00
Sanjay Patel
ea886051fe [InstCombine] allow icmp (shr/shl) folds for vectors
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281663 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-15 21:35:30 +00:00
David Majnemer
26eccc1ec7 [InstCombine] Do not RAUW a constant GEP
canRewriteGEPAsOffset expects to process instructions, not constants.

This fixes PR30342.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281650 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-15 20:10:09 +00:00
Sanjay Patel
71d3c34146 [InstCombine] simplify code; NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281644 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-15 19:04:55 +00:00
Sanjay Patel
d6d0906b44 fix function names; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281637 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-15 18:22:25 +00:00
Sanjay Patel
2473bf077d [InstCombine] allow icmp (sub nsw) folds for vectors
Also, clean up the code and comments for the existing folds in foldICmpSubConstant().


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281631 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-15 18:05:17 +00:00
Sanjay Patel
d2bd71f1d9 [InstCombine] remove duplicated fold ; NFCI
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281627 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-15 17:01:17 +00:00
Sanjay Patel
f71deb6fd3 [InstCombine] allow (icmp sgt smin(PosA, B), 0) fold for vectors
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281624 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-15 16:23:20 +00:00
Sanjay Patel
964ae1d5ee [InstCombine] clean up foldICmpWithConstant(); NFC
1. Early exit to reduce indent
2. Rename variables
3. Add local 'Pred' variable


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281615 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-15 15:11:12 +00:00
Sanjay Patel
80554382ca [InstCombine] add helper function for foldICmpWithConstant; NFC
This is a big glob of transforms that probably should work for vectors,
but currently they are disallowed because of ConstantInt guards.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281614 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-15 14:37:50 +00:00
Sanjay Patel
0ee16969ab [InstCombine] use m_APInt to allow icmp folds using known bits for splat constant vectors
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281613 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-15 14:15:47 +00:00
Sanjay Patel
0ebfb4ee10 [InstCombine] refactor eq/ne cases in foldICmpUsingKnownBits() ; NFCI
The pattern matching and transforms are identical; the cmp predicate just changes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281561 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-14 23:38:56 +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
7e05343232 fix formatting; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281220 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-12 15:52:28 +00:00
Sanjay Patel
29b1dcd7fc [InstCombine] add helper function for foldICmpUsingKnownBits; NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281217 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-12 15:24:31 +00:00
Sanjay Patel
c04a5a1fc4 fix formatting/typos; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281214 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-12 14:25:46 +00:00
Sanjay Patel
e117e50653 [InstCombine] clean up foldICmpBinOpEqualityWithConstant / foldICmpIntrinsicWithConstant ; NFC
1. Rename variables to be consistent with related/preceding code (may want to reorganize).
2. Fix comments/formatting.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281140 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-10 15:33:39 +00:00
Sanjay Patel
792a8eaf8c [InstCombine] rename and reorganize some icmp folding functions; NFC
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. 


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281139 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-10 15:03:44 +00:00
Sanjay Patel
1a60ab87dc [InstCombine] use m_APInt to allow icmp ult X, C folds for splat constant vectors
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281107 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-09 21:59:37 +00:00
Sanjay Patel
e0563b1a6c [InstCombine] return a vector-safe true/false constant
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?



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280964 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-08 16:54:02 +00:00
Sanjay Patel
774d87e2ea [InstCombine] use m_APInt to allow icmp (and (sh X, Y), C2), C1 folds for splat constant vectors
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280873 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-07 22:33:03 +00:00
Sanjay Patel
350a7a4120 [InstCombine] allow icmp (and X, C2), C1 folds for splat constant vectors
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280861 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-07 20:50:44 +00:00
Sanjay Patel
47e6904fe1 [InstCombine] don't assert that division-by-constant has been folded (PR30281)
This is effectively a revert of:
https://reviews.llvm.org/rL280115

And this should fix
https://llvm.org/bugs/show_bug.cgi?id=30281:



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280677 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-05 23:38:22 +00:00
Sanjay Patel
6704841232 [InstCombine] revert r280637 because it causes test failures on an ARM bot
http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15/builds/14952/steps/ninja%20check%201/logs/FAIL%3A%20LLVM%3A%3Aicmp.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280676 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-05 22:36:32 +00:00
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