2609 Commits

Author SHA1 Message Date
Craig Topper
c4130de547 [DAGCombiner] Discard pointer info when combining extract_vector_elt of a vector load when the index isn't constant
Summary:
If the index isn't constant, this transform inserts a multiply and an add on the index to calculating the base pointer for a scalar load. But we still create a memory operand with an offset of 0 and the size of the scalar access. But the access is really to an unknown offset within the original access size.

This can cause the machine scheduler to incorrectly calculate dependencies between this load and other accesses. In the case we saw, there was a 32 byte vector store that was split into two 16 byte stores, one with offset 0 and one with offset 16. The size of the memory operand for both was 16. The scheduler correctly detected the alias with the offset 0 store, but not the offset 16 store.

This patch discards the pointer info so we don't incorrectly detect aliasing. I wasn't sure if we could keep using the original offset and size without risking some other transform on the load changing the size.

I tried to reduce a test case, but there's still a lot of memory operations needed to get the scheduler to do the bad reordering. So it looked pretty fragile to maintain.

Reviewers: efriedma

Reviewed By: efriedma

Subscribers: arphaman, llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353124 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-05 00:22:23 +00:00
Simon Pilgrim
cd297b5b93 [DAGCombine] Add ADD(SUB,SUB) combines
Noticed while investigating PR40483, and fixes the basic test case from the bug - but not a more general case.

We're pretty weak at dealing with ADD/SUB combines compared to the SimplifyAssociativeOrCommutative/SimplifyUsingDistributiveLaws abilities that InstCombine can manage.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353044 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-04 13:44:49 +00:00
Simon Pilgrim
5893e44c14 [SDAG] Add SDNode/SDValue getConstantOperandAPInt helper. NFCI.
We already have the getConstantOperandVal helper which returns a uint64_t, but along comes the fuzzer and inserts a i128 -1 constant or something and the whole thing asserts.......

I've updated a few obvious cases, and tried to make use of the const reference where possible, but there's more to do. A number of existing oss-fuzz tickets should be fixed if we start using APInt and perform value clamping where necessary.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352961 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-02 17:35:06 +00:00
Guozhi Wei
7d44f47479 [DAGCombine] Avoid CombineZExtLogicopShiftLoad if there is free ZEXT
This patch fixes pr39098.

For the attached test case, CombineZExtLogicopShiftLoad can optimize it to

t25: i64 = Constant<1099511627775>
t35: i64 = Constant<0>
  t0: ch = EntryToken
t57: i64,ch = load<(load 4 from `i40* undef`, align 8), zext from i32> t0, undef:i64, undef:i64
    t58: i64 = srl t57, Constant:i8<1>
  t60: i64 = and t58, Constant:i64<524287>
t29: ch = store<(store 5 into `i40* undef`, align 8), trunc to i40> t57:1, t60, undef:i64, undef:i64

But later visitANDLike transforms it to

t25: i64 = Constant<1099511627775>
t35: i64 = Constant<0>
  t0: ch = EntryToken
t57: i64,ch = load<(load 4 from `i40* undef`, align 8), zext from i32> t0, undef:i64, undef:i64
      t61: i32 = truncate t57
    t63: i32 = srl t61, Constant:i8<1>
  t64: i32 = and t63, Constant:i32<524287>
t65: i64 = zero_extend t64
    t58: i64 = srl t57, Constant:i8<1>
  t60: i64 = and t58, Constant:i64<524287>
t29: ch = store<(store 5 into `i40* undef`, align 8), trunc to i40> t57:1, t60, undef:i64, undef:i64

And it triggers CombineZExtLogicopShiftLoad again, causes a dead loop.

Both forms should generate same instructions, CombineZExtLogicopShiftLoad generated IR looks cleaner. But it looks more difficult to prevent visitANDLike to do the transform, so I prevent CombineZExtLogicopShiftLoad to do the transform if the ZExt is free.

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352792 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-31 20:46:42 +00:00
Nirav Dave
6980a884f1 [DAG] Aggressively cleanup dangling node in CombineZExtLogicopShiftLoad.
While dangling nodes will eventually be pruned when they are
considered, leaving them disables combines requiring single-use.

Reviewers: Carrot, spatel, craig.topper, RKSimon, efriedma

Subscribers: hiraditya, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352784 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-31 19:35:14 +00:00
Sanjay Patel
b880916519 [DAGCombiner] sub X, 0/1 --> add X, 0/-1
This extends the existing transform for:
add X, 0/1 --> sub X, 0/-1
...to allow the sibling subtraction fold.

This pattern could regress with the proposed change in D57401.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352680 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-30 22:41:35 +00:00
Sanjay Patel
935be04820 [DAGCombiner] fold extract_subvector of extract_subvector
This is the sibling fold for insert-of-insert that was added with D56604.

Now that we have x86 shuffle narrowing (D57156), this change shows improvements for 
lots of AVX512 reduction code (not sure that we would ever expect extract-of-extract otherwise).

There's a small regression in some of the partial-permute tests (extracting followed by splat).
That is tracked by PR40500:
https://bugs.llvm.org/show_bug.cgi?id=40500

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352528 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-29 19:13:39 +00:00
Michael Berg
df80dbdabc [NFC] TLI query with default(on) behavior wrt DAG combines for fmin/fmax target control
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352396 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-28 18:03:08 +00:00
Sam Parker
798bb55987 [DAGCombine] Enable more pre-indexed stores
The current check in CombineToPreIndexedLoadStore is too
conversative, preventing a pre-indexed store when the base pointer
is a predecessor of the value being stored. Instead, we should check
the pointer operand of the store.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351933 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-23 09:11:49 +00:00
Sanjay Patel
e5439d5457 [DAGCombiner] narrow vector binop with 2 insert subvector operands
vecbo (insertsubv undef, X, Z), (insertsubv undef, Y, Z) --> insertsubv VecC, (vecbo X, Y), Z

This is another step in generic vector narrowing. It's also a step towards more horizontal op 
formation specifically for x86 (although we still failed to match those in the affected tests).

The scalarization cases are also not optimal (we should be scalarizing those), but it's still 
an improvement to use a narrower vector op when we know part of the result must be constant 
because both inputs are undef in some vector lanes.

I think a similar match but checking for a constant operand might help some of the cases in 
D51553.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351825 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-22 14:24:13 +00:00
Sanjay Patel
b9d3157bde [DAGCombiner] fix crash when converting build vector to shuffle
The regression test is reduced from the example shown in D56281.
This does raise a question as noted in the test file: do we want
to handle this pattern? I don't have a motivating example for
that on x86 yet, but it seems like we could have that pattern 
there too, so we could avoid the back-and-forth using a shuffle.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351753 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-21 17:30:14 +00:00
Chandler Carruth
6b547686c5 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351636 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-19 08:50:56 +00:00
Florian Hahn
50070e7744 [SelectionDAG] Split very large token factors for chained stores to 64k chunks.
Similar to D55073. Without this change, the DAG combiner crashes on code
with more than 64k of stores in a single basic block that form parallelizable
chains.

No test case, as it would be very IR file.

Reviewed By: RKSimon

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351571 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-18 18:37:38 +00:00
Sam Parker
b95047e990 [DAGCombine] Fix ReduceLoadWidth for shifted offsets
ReduceLoadWidth can trigger using a shifted mask is used and this
requires that the function return a shl node to correct for the
offset. However, the way that this was implemented meant that the
returned result could be an existing node, which would be incorrect.
This fixes the method of inserting the new node and replacing uses.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351310 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-16 08:40:12 +00:00
Sanjay Patel
f764968e17 [DAGCombiner] reduce buildvec of zexted extracted element to shuffle
The motivating case for this is shown in the first regression test. We are 
transferring to scalar and back rather than just zero-extending with 'vpmovzxdq'.

That's a special-case for a more general pattern as shown here. In all tests, 
we're avoiding the vector-scalar-vector moves in favor of vector ops.

We aren't producing optimal shuffle code in some cases though, so the patch is
limited to reduce regressions.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351198 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-15 16:11:05 +00:00
Simon Pilgrim
e84a99a487 [DAGCombiner] Add (sub_sat x, x) -> 0 combine
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351073 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-14 15:43:34 +00:00
Simon Pilgrim
70291ab191 [DAGCombiner] Enable sub saturation constant folding
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351072 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-14 15:28:53 +00:00
Simon Pilgrim
cfe0eb0ee4 [DAGCombiner] Add add/sub saturation undef handling
Match ConstantFolding.cpp:
(add_sat x, undef) -> -1
(sub_sat x, undef) -> 0

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351070 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-14 14:16:24 +00:00
Simon Pilgrim
1041c737ca [DAGCombiner] Enable add saturation constant folding
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351060 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-14 12:34:31 +00:00
Simon Pilgrim
fc46ecd5d4 [DAGCombiner] Add add saturation constant folding tests.
Exposes an issue with sadd_sat for computeOverflowKind, so I've disabled it for now.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351057 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-14 12:12:42 +00:00
Simon Pilgrim
e78bbef5db [DAGCombiner] If add_sat(x,y) can't overflow -> add(x,y)
NOTE: We need more powerful signed overflow detection in computeOverflowKind

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351026 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-13 22:08:26 +00:00
Simon Pilgrim
5fba77096a Fix unused variable warning. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351025 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-13 21:53:12 +00:00
Simon Pilgrim
75e47eac7c [DAGCombiner] Some very basic add/sub saturation combines.
Handle combines with zero and constant canonicalization for adds.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351024 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-13 21:50:24 +00:00
Sanjay Patel
e252cc3f67 [DAGCombiner] fold insert_subvector of insert_subvector
This pattern:

    t33: v8i32 = insert_subvector undef:v8i32, t35, Constant:i64<0>
  t21: v16i32 = insert_subvector undef:v16i32, t33, Constant:i64<0>

...shows up in PR33758:
https://bugs.llvm.org/show_bug.cgi?id=33758
...although this patch doesn't make any difference to the final result on that yet.

In the affected tests here, it looks like it just makes RA wiggle. But we might 
as well squash this to prevent it interfering with other pattern-matching.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351008 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-12 15:12:28 +00:00
Sanjay Patel
e38897a6d0 [DAGCombiner] simplify code; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350844 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-10 16:47:42 +00:00
Sanjay Patel
7f75372216 [DAGCombiner][x86] scalarize binop followed by extractelement
As noted in PR39973 and D55558:
https://bugs.llvm.org/show_bug.cgi?id=39973
...this is a partial implementation of a fold that we do as an IR canonicalization in instcombine:

// extelt (binop X, Y), Index --> binop (extelt X, Index), (extelt Y, Index)

We want to have this in the DAG too because as we can see in some of the test diffs (reductions), 
the pattern may not be visible in IR.

Given that this is already an IR canonicalization, any backend that would prefer a vector op over 
a scalar op is expected to already have the reverse transform in DAG lowering (not sure if that's
a realistic expectation though). The transform is limited with a TLI hook because there's an
existing transform in CodeGenPrepare that tries to do the opposite transform.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350354 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-03 21:31:16 +00:00
Craig Topper
4bdf65768e [DAGCombiner] After performing the division by constant optimization for a DIV or REM node, replace the users of the corresponding REM or DIV node if it exists.
Currently we expand the two nodes separately. This gives DAG combiner an opportunity to optimize the expanded sequence taking into account only one set of users. When we expand the other node we'll create the expansion again, but might not be able to optimize it the same way. So the nodes won't CSE and we'll have two similarish sequences in the same basic block. By expanding both nodes at the same time we'll avoid prematurely optimizing the expansion until both the division and remainder have been replaced.

Improves the test case from PR38217. There may be additional opportunities after this.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350239 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-02 18:19:07 +00:00
Craig Topper
6529ef607e [DAGCombiner][X86][PowerPC] Teach visitSIGN_EXTEND_INREG to fold (sext_in_reg (aext/sext x)) -> (sext x) when x has more than 1 sign bit and the sext_inreg is from one of them.
If x has multiple sign bits than it doesn't matter which one we extend from so we can sext from x's msb instead.

The X86 setcc-combine.ll changes are a little weird. It appears we ended up with a (sext_inreg (aext (trunc (extractelt)))) after type legalization. The sext_inreg+aext now gets optimized by this combine to leave (sext (trunc (extractelt))). Then we visit the trunc before we visit the sext. This ends up changing the truncate to an extractvectorelt from a bitcasted vector. I have a follow up patch to fix this.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350235 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-02 17:58:27 +00:00
Craig Topper
99afb2d8c8 [DAGCombiner] Add missing one use check on the shuffle in the bitcast(shuffle(bitcast(s0),bitcast(s1))) -> shuffle(s0,s1) transform.
Found while trying out some other changes so I don't really have a test case.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350172 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-31 05:40:46 +00:00
Sanjay Patel
70157e3981 [DAGCombiner] limit shuffle to extend transform (PR40146)
It's dangerous to knowingly create an illegal vector type
no matter what stage of combining we're in.

This prevents the missed folding/scalarization seen in:
https://bugs.llvm.org/show_bug.cgi?id=40146


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350034 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-23 20:48:31 +00:00
Sanjay Patel
5d87a4a699 [DAGCombiner] allow hoisting vector bitwise logic ahead of extends
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350032 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-23 19:58:16 +00:00
Sanjay Patel
4452b74d57 [DAGCombiner] allow narrowing of add followed by truncate
trunc (add X, C ) --> add (trunc X), C'

If we're throwing away the top bits of an 'add' instruction, do it in the narrow destination type.
This makes the truncate-able opcode list identical to the sibling transform done in IR (in instcombine).

This change used to show regressions for x86, but those are gone after D55494. 
This gets us closer to deleting the x86 custom function (combineTruncatedArithmetic) 
that does almost the same thing.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350006 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-22 17:10:31 +00:00
Sanjay Patel
d77e346b12 [DAGCombiner] simplify code leading to scalarizeExtractedVectorLoad; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349958 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-21 21:26:30 +00:00
Simon Pilgrim
ad5be70b1a [SelectionDAG] Always use the version of computeKnownBits that returns a value. NFCI.
Continues the work started by @bogner in rL340594 to remove uses of the KnownBits output paramater version.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349907 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-21 14:56:18 +00:00
Eli Friedman
8e797de70d [ARM] Complete the Thumb1 shift+and->shift+shift transforms.
This saves materializing the immediate.  The additional forms are less
common (they don't usually show up for bitfield insert/extract), but
they're still relevant.

I had to add a new target hook to prevent DAGCombine from reversing the
transform. That isn't the only possible way to solve the conflict, but
it seems straightforward enough.

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349857 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-20 23:39:54 +00:00
Craig Topper
f41808d09e [DAGCombiner] Fix a place that was creating a SIGN_EXTEND with an extra operand.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349726 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-20 05:28:06 +00:00
Simon Pilgrim
0d195adc70 [SelectionDAG] Optional handling of UNDEF elements in matchBinaryPredicate (part 2 of 2)
Now that SimplifyDemandedBits/SimplifyDemandedVectorElts is simplifying vector elements, we're seeing more constant BUILD_VECTOR containing undefs.

This patch provides opt-in support for UNDEF elements in matchBinaryPredicate, passing NULL instead of the result ConstantSDNode* argument.

I've updated the (or (and X, c1), c2) -> (and (or X, c2), c1|c2) fold to demonstrate its use, which I believe is safe for undef cases.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349629 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-19 14:09:38 +00:00
Simon Pilgrim
cd3782549e [TargetLowering] Fix propagation of undefs in zero extension ops (PR40091)
As described on PR40091, we have several places where zext (and zext_vector_inreg) fold an undef input into an undef output. For zero extensions this is incorrect as the output should guarantee to least have the new upper bits set to zero.

SimplifyDemandedVectorElts is the worst offender (and its the most likely to cause new undefs to appear) but DAGCombiner's tryToFoldExtendOfConstant has a similar issue.

Thanks to @dmgreen for catching this.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349625 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-19 13:37:59 +00:00
Sanjay Patel
c5f4a842ff [DAGCombiner] allow hoisting vector bitwise logic ahead of truncates
The transform performs a bitwise logic op in a wider type followed by
truncate when both inputs are truncated from the same source type:
logic_op (truncate x), (truncate y) --> truncate (logic_op x, y)

There are a bunch of other checks that should prevent doing this when 
it might be harmful.

We already do this transform for scalars in this spot. The vector 
limitation was shared with a check for the case when the operands are 
extended. I'm not sure if that limit is needed either, but that would 
be a separate patch.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349303 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-16 14:57:04 +00:00
Simon Pilgrim
c1aee892b9 [SelectionDAG] Add FSHL/FSHR support to computeKnownBits
Also exposes an issue in DAGCombiner::visitFunnelShift where we were assuming the shift amount had the result type (after legalization it'll have the targets shift amount type).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349298 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-16 13:33:37 +00:00
Craig Topper
6d356c8850 [DAGCombiner][X86] Prevent visitSIGN_EXTEND from returning N when (sext (setcc)) already has the target desired type for the setcc
Summary:
If the setcc already has the target desired type we can reach the getSetCC/getSExtOrTrunc after the MatchingVecType check with the exact same types as the nodes we started with. This causes those causes VsetCC to be CSEd to N0 and the getSExtOrTrunc will CSE to N. When we return N, the caller will think that meant we called CombineTo and did our own worklist management. But that's not what happened. This prevents target hooks from being called for the node.

To fix this, I've now returned SDValue if the setcc is already the desired type. But to avoid some regressions in X86 I've had to disable one of the target combines that wasn't being reached before in the case of a (sext (setcc)). If we get vector widening legalization enabled that entire function will be deleted anyway so hopefully this is only for the short term.

Reviewers: RKSimon, spatel

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349137 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-14 08:28:24 +00:00
Sanjay Patel
1b4867a8d9 [DAGCombiner] clean up visitEXTRACT_VECTOR_ELT
This isn't quite NFC, but I don't know how to expose
any outward diffs from these changes. Mostly, this
was confusing because it used 'VT' to refer to the
operand type rather the usual type of the input node.

There's also a large block at the end that is dedicated 
solely to matching loads, but that wasn't obvious. This
could probably be split up into separate functions to
make it easier to see. 

It's still not clear to me when we make certain transforms 
because the legality and constant conditions are 
intertwined in a way that might be improved.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349095 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-14 00:09:08 +00:00
Sanjay Patel
ad397e7b26 [DAGCombiner] after simplifying demanded elements of vector operand of extract, revisit the extract; 2nd try
This is a retry of rL349051 (reverted at rL349056). I changed the check for dead-ness from
number of uses to an opcode test for DELETED_NODE based on existing similar code.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349058 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-13 17:05:01 +00:00
Sanjay Patel
82ad560a7e revert rL349051: [DAGCombiner] after simplifying demanded elements of vector operand of extract, revisit the extract
This causes an address sanitizer bot failure:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/27187/steps/check-llvm%20asan/logs/stdio


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349056 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-13 16:32:44 +00:00
Sanjay Patel
aab76e7c51 [DAGCombiner] after simplifying demanded elements of vector operand of extract, revisit the extract
Differential Revision: https://reviews.llvm.org/D55655


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349051 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-13 15:44:26 +00:00
Simon Pilgrim
d1643f97ea [DAGCombine] Moved X86 rotate_amount % bitwidth == 0 early out to DAGCombiner
Remove common code from custom lowering (code is still safe if somehow a zero value gets used).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349028 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-13 12:23:32 +00:00
Simon Pilgrim
30304feaba [DAGCombiner] Remove unnecessary recursive DAGCombiner::visitINSERT_SUBVECTOR call.
As discussed on D55511, this caused an issue if the inner node deletes a node that the outer node depends upon. As it doesn't affect any lit-tests and I've only been able to expose this with the D55511 change I'm committing this now.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348781 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-10 18:18:50 +00:00
Francis Visoiu Mistrih
981341ad1a [DAGCombiner] Use the result value type in visitCONCAT_VECTORS
This triggers an assert when combining concat_vectors of a bitcast of
merge_values.

With asserts disabled, it fails to select:
fatal error: error in backend: Cannot select: 0x7ff19d000e90: i32 = any_extend 0x7ff19d000ae8
  0x7ff19d000ae8: f64,ch = CopyFromReg 0x7ff19d000c20:1, Register:f64 %1
    0x7ff19d000b50: f64 = Register %1
In function: d

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348759 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-10 14:31:34 +00:00
Sanjay Patel
5d35502198 [DAGCombiner] re-enable truncation of binops
This is effectively re-committing the changes from:
rL347917 (D54640)
rL348195 (D55126)
...which were effectively reverted here:
rL348604
...because the code had a bug that could induce infinite looping
or eventual out-of-memory compilation.

The bug was that this code did not guard against transforming
opaque constants. More details are in the post-commit mailing
list thread for r347917. A reduced test for that is included
in the x86 bool-math.ll file. (I wasn't able to reduce a PPC
backend test for this, but it was almost the same pattern.)

Original commit message for r347917:

The motivating case for this is shown in:
https://bugs.llvm.org/show_bug.cgi?id=32023
and the corresponding rot16.ll regression tests.

Because x86 scalar shift amounts are i8 values, we can end up with trunc-binop-trunc
sequences that don't get folded in IR.

As the TODO comments suggest, there will be regressions if we extend this (for x86,
we mostly seem to be missing LEA opportunities, but there are likely vector folds
missing too). I think those should be considered existing bugs because this is the
same transform that we do as an IR canonicalization in instcombine. We just need
more tests to make those visible independent of this patch.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348706 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-08 16:07:38 +00:00
Sanjay Patel
d19f12b58f [DAGCombiner] split trunc from extend in hoistLogicOpWithSameOpcodeHands; NFC
This duplicates several shared checks, but we need to split
this up to fix underlying bugs in smaller steps.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348627 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-07 18:51:08 +00:00