228 Commits

Author SHA1 Message Date
Chen Zheng
ef1e756a76 [InstCombine] sdiv exact flag fixup.
Differential Revision: https://reviews.llvm.org/D60396


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357904 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-08 12:08:03 +00:00
Sanjay Patel
9551a63812 [InstCombine] form uaddsat from add+umin (PR14613)
This is the last step towards solving the examples shown in:
https://bugs.llvm.org/show_bug.cgi?id=14613

With this change, x86 should end up with psubus instructions
when those are available.

All known codegen issues with expanding the saturating intrinsics
were resolved with:
D59006 / rL356855

We also have some early evidence in D58872 that using the intrinsics
will lead to better perf. If some target regresses from this, custom
lowering of the intrinsics (as in the above for x86) may be needed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357012 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-26 17:50:08 +00:00
Sanjay Patel
26fe4b69c7 [InstCombine] fold adds of constants separated by sext/zext
This is part of a transform that may be done in the backend:
D13757
...but it should always be beneficial to fold this sooner in IR
for all targets.

https://rise4fun.com/Alive/vaiW

  Name: sext add nsw
  %add = add nsw i8 %i, C0
  %ext = sext i8 %add to i32
  %r = add i32 %ext, C1
  =>
  %s = sext i8 %i to i32
  %r = add i32 %s, sext(C0)+C1

  Name: zext add nuw
  %add = add nuw i8 %i, C0
  %ext = zext i8 %add to i16
  %r = add i16 %ext, C1
  =>
  %s = zext i8 %i to i16
  %r = add i16 %s, zext(C0)+C1

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355118 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-28 19:05:26 +00:00
Sanjay Patel
aaaa56c4e7 [InstCombine] canonicalize add/sub with bool
add A, sext(B) --> sub A, zext(B)

We have to choose 1 of these forms, so I'm opting for the
zext because that's easier for value tracking.

The backend should be prepared for this change after:
D57401
rL353433

This is also a preliminary step towards reducing the amount
of bit hackery that we do in IR to optimize icmp/select.
That should be waiting to happen at a later optimization stage.

The seeming regression in the fuzzer test was discussed in:
D58359

We were only managing that fold in instcombine by luck, and
other passes should be able to deal with that better anyway.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354748 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-24 16:57:45 +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
4d62074ac2 [InstCombine] Don't undo 0 - (X * Y) canonicalization when combining subs.
Otherwise instcombine gets stuck in a cycle. The canonicalization was
added in D55961.

This patch fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=12400

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351187 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-15 11:18:21 +00:00
Sanjay Patel
2aa873478d [InstCombine] name change: foldShuffledBinop -> foldVectorBinop; NFC
This function will deal with more than shuffles with D50992, and I 
have another potential per-element fold that could live here.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343692 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-03 15:20:58 +00:00
David Green
cf1b18658c [InstCombine] Fold ~A - Min/Max(~A, O) -> Max/Min(A, ~O) - A
This is an attempt to get out of a local-minimum that instcombine currently
gets stuck in. We essentially combine two optimisations at once, ~a - ~b = b-a
and min(~a, ~b) = ~max(a, b), only doing the transform if the result is at
least neutral. This involves using IsFreeToInvert, which has been expanded a
little to include selects that can be easily inverted.

This is trying to fix PR35875, using the ideas from Sanjay. It is a large
improvement to one of our rgb to cmy kernels.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343569 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-02 09:48:34 +00:00
Craig Topper
becd18d5a8 [InstCombine] Support (sub (sext x), (sext y)) --> (sext (sub x, y)) and (sub (zext x), (zext y)) --> (zext (sub x, y))
Summary:
If the sub doesn't overflow in the original type we can move it above the sext/zext.

This is similar to what we do for add. The overflow checking for sub is currently weaker than add, so the test cases are constructed for what is supported.

Reviewers: spatel

Reviewed By: spatel

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342335 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-15 18:54:10 +00:00
Sanjay Patel
fd837765bd [InstCombine] refactor mul narrowing folds; NFCI
Similar to rL342278:
The test diffs are all cosmetic due to the change in
value naming, but I'm including that to show that the
new code does perform these folds rather than something
else in instcombine.

D52075 should be able to use this code too rather than
duplicating all of the logic.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342292 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-14 22:23:35 +00:00
Sanjay Patel
d84a0a2c13 [InstCombine] add/use overflowing math helper functions; NFC
The mul case can already be refactored to use this similar to
rL342278.
The sub case is proposed in D52075.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342289 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-14 21:30:07 +00:00
Sanjay Patel
03a74f0299 [InstCombine] refactor add narrowing folds; NFCI
The test diffs are all cosmetic due to the change in
value naming, but I'm including that to show that the
new code does perform these folds rather than something
else in instcombine.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342278 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-14 20:40:46 +00:00
Craig Topper
9d207e5918 [InstCombine] Use dyn_cast instead of match(m_Constant). NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@341962 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-11 16:51:26 +00:00
Craig Topper
8e2acb78ca [InstCombine] Extend (add (sext x), cst) --> (sext (add x, cst')) and (add (zext x), cst) --> (zext (add x, cst')) to work for vectors
Differential Revision: https://reviews.llvm.org/D51236

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340796 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-28 02:02:29 +00:00
Andrea Di Biagio
aec303a986 [InstCombine] Remove unused method FAddCombine::createFDiv(). NFC
This commit fixes a (gcc 7.3.0) [-Wunused-function] warning caused by the
presence of unused method FaddCombine::createFDiv().
The last use of that method was removed at r339519.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340014 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-17 11:33:48 +00:00
Sanjay Patel
fa0e915a8e [InstCombine] fix/enhance fadd/fsub factorization
(X * Z) + (Y * Z) --> (X + Y) * Z
  (X * Z) - (Y * Z) --> (X - Y) * Z
  (X / Z) + (Y / Z) --> (X + Y) / Z
  (X / Z) - (Y / Z) --> (X - Y) / Z

The existing code that implemented these folds failed to 
optimize vectors, and it transformed code with multiple 
uses when it should not have.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339519 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-12 15:48:26 +00:00
Sanjay Patel
ccbe637eb2 [InstCombine] allow fsub+fmul FMF folds for vectors
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339368 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-09 18:42:12 +00:00
Sanjay Patel
2998722fb0 [InstCombine] reduce code duplication; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339349 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-09 15:07:13 +00:00
Sanjay Patel
6b0047a7da [InstCombine] fold fadd+fsub with common operand
This is a sibling to the simplify from:
https://reviews.llvm.org/rL339174


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339267 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-08 16:19:22 +00:00
Sanjay Patel
bd96310a2c [InstCombine] fold fsub+fsub with common operand
This is a sibling to the simplify from:
rL339171


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339266 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-08 16:04:48 +00:00
Sanjay Patel
752da31e95 [InstCombine] fold fneg into constant operand of fmul/fdiv
This accounts for the missing IR fold noted in D50195. We don't need any fast-math to enable the negation transform. 
FP negation can always be folded into an fmul/fdiv constant to eliminate the fneg.

I've limited this to one-use to ensure that we are eliminating an instruction rather than replacing fneg by a 
potentially expensive fdiv or fmul.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339248 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-08 14:29:08 +00:00
Fangrui Song
af7b1832a0 Remove trailing space
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h}

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338293 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-30 19:41:25 +00:00
Sanjay Patel
19a2e2a495 [InstCombine] try to fold 'add+sub' to 'not+add'
These are reassociated versions of the same pattern and
similar transforms as in rL338200 and rL338118.

The motivation is identical to those commits:
Patterns with add/sub combos can be improved using
'not' ops. This is better for analysis and may lead
to follow-on transforms because 'xor' and 'add' are
commutative/associative. It can also help codegen.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338221 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-29 18:13:16 +00:00
Sanjay Patel
bd68890e8f [InstCombine] try to fold 'sub' to 'not'
https://rise4fun.com/Alive/jDd

Patterns with add/sub combos can be improved using
'not' ops. This is better for analysis and may lead
to follow-on transforms because 'xor' and 'add' are 
commutative/associative. It can also help codegen.  


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338200 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-28 16:48:44 +00:00
Sanjay Patel
8a35df349b [InstCombine] return when SimplifyAssociativeOrCommutative makes a change
This bug was created by rL335258 because we used to always call instsimplify
after trying the associative folds. After that change it became possible
for subsequent folds to encounter unsimplified code (and potentially assert
because of it). 

Instead of carrying changed state through instcombine, we can just return 
immediately. This allows instsimplify to run, so we can continue assuming
that easy folds have already occurred.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336965 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-13 01:18:07 +00:00
Gil Rapaport
d7d68723b8 [InstCombine] (A + 1) + (B ^ -1) --> A - B
Turn canonicalized subtraction back into (-1 - B) and combine it with (A + 1) into (A - B).
This is similar to the folding already done for (B ^ -1) + Const into (-1 + Const) - B.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@335579 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-26 05:31:18 +00:00
Sanjay Patel
1a4304a132 [InstCombine] simplify binops before trying other folds
This is outwardly NFC from what I can tell, but it should be more efficient 
to simplify first (despite the name, SimplifyAssociativeOrCommutative does
not actually simplify as InstSimplify does - it creates/morphs instructions).

This should make it easier to refactor duplicated code that runs for all binops.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@335258 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-21 17:06:36 +00:00
Sanjay Patel
6a08b7888b [InstCombine] fold another shifty abs pattern to cmp+sel (PR36036)
The bug report:
https://bugs.llvm.org/show_bug.cgi?id=36036

...requests a DAG change for this, but an IR canonicalization
probably handles most cases. If we still want to match this
pattern in the backend, there's a proposal for that too:
D47831

Alive proofs including nsw/nuw cases that were first noted in:
D46988

https://rise4fun.com/Alive/Kmp

This patch is largely copied from the existing code that was
initially added with:
D40984
...but I didn't see much gain from trying to share code.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@334137 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-06 21:58:12 +00:00
Roman Lebedev
85b7bc9e52 [InstCombine] PR37603: low bit mask canonicalization
Summary:
This is [[ https://bugs.llvm.org/show_bug.cgi?id=37603 | PR37603 ]].

https://godbolt.org/g/VCMNpS
https://rise4fun.com/Alive/idM

When doing bit manipulations, it is quite common to calculate some bit mask,
and apply it to some value via `and`.

The typical C code looks like:
```
int mask_signed_add(int nbits) {
    return (1 << nbits) - 1;
}
```
which is translated into (with `-O3`)
```
define dso_local i32 @mask_signed_add(int)(i32) local_unnamed_addr #0 {
  %2 = shl i32 1, %0
  %3 = add nsw i32 %2, -1
  ret i32 %3
}
```

But there is a second, less readable variant:
```
int mask_signed_xor(int nbits) {
    return ~(-(1 << nbits));
}
```
which is translated into (with `-O3`)
```
define dso_local i32 @mask_signed_xor(int)(i32) local_unnamed_addr #0 {
  %2 = shl i32 -1, %0
  %3 = xor i32 %2, -1
  ret i32 %3
}
```

Since we created such a mask, it is quite likely that we will use it in `and` next.
And then we may get rid of `not` op by folding into `andn`.

But now that i have actually looked:
https://godbolt.org/g/VTUDmU
_some_ backend changes will be needed too.
We clearly loose `bzhi` recognition.

Reviewers: spatel, craig.topper, RKSimon

Reviewed By: spatel

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@334127 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-06 19:38:27 +00:00
Sanjay Patel
9a5dadc5b1 [InstCombine] improve sub with bool folds
There's a patchwork of existing transforms trying to handle
these cases, but as seen in the changed test, we weren't
catching them all.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333845 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-03 16:35:26 +00:00
Sanjay Patel
b155a7cf56 [InstCombine] call simplify before trying vector folds
As noted in the review thread for rL333782, we could have
made a bug harder to hit if we were simplifying instructions
before trying other folds. 

The shuffle transform in question isn't ever a simplification;
it's just a canonicalization. So I've renamed that to make that 
clearer.

This is NFCI at this point, but I've regenerated the test file 
to show the cosmetic value naming difference of using 
instcombine's RAUW vs. the builder.

Possible follow-ups:
1. Move reassociation folds after simplifies too.
2. Refactor common code; we shouldn't have so much repetition.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333820 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-02 16:27:44 +00:00
Sanjay Patel
a855adc9a0 [InstCombine] don't negate constant expression with fsub (PR37605)
X + (-C) would be transformed back into X - C, so infinite loop:
https://bugs.llvm.org/show_bug.cgi?id=37605


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333610 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-30 23:55:12 +00:00
Craig Topper
c058ba5c3a [InstCombine] Negate ABS/NABS patterns by swapping the select operands to remove the negation
Differential Revision: https://reviews.llvm.org/D47236

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333101 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-23 17:29:03 +00:00
Omer Paparo Bivas
55a66360d5 [InstCombine] Moving overflow computation logic from InstCombine to ValueTracking; NFC
Differential Revision: https://reviews.llvm.org/D46704

Change-Id: Ifabcbe431a2169743b3cc310f2a34fd706f13f02

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332026 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-10 19:46:19 +00:00
Adrian Prantl
26b584c691 Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

  for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331272 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-01 15:54:18 +00:00
Roman Lebedev
a9bc2db4f5 [PatternMatch] Stabilize the matching order of commutative matchers
Summary:
Currently, we
1. match `LHS` matcher to the `first` operand of binary operator,
2. and then match `RHS` matcher to the `second` operand of binary operator.
If that does not match, we swap the `LHS` and `RHS` matchers:
1. match `RHS` matcher to the `first` operand of binary operator,
2. and then match `LHS` matcher to the `second` operand of binary operator.

This works ok.
But it complicates writing of commutative matchers, where one would like to match
(`m_Value()`) the value on one side, and use (`m_Specific()`) it on the other side.

This is additionally complicated by the fact that `m_Specific()` stores the `Value *`,
not `Value **`, so it won't work at all out of the box.

The last problem is trivially solved by adding a new `m_c_Specific()` that stores the
`Value **`, not `Value *`. I'm choosing to add a new matcher, not change the existing
one because i guess all the current users are ok with existing behavior,
and this additional pointer indirection may have performance drawbacks.
Also, i'm storing pointer, not reference, because for some mysterious-to-me reason
it did not work with the reference.

The first one appears trivial, too.
Currently, we
1. match `LHS` matcher to the `first` operand of binary operator,
2. and then match `RHS` matcher to the `second` operand of binary operator.
If that does not match, we swap the ~~`LHS` and `RHS` matchers~~ **operands**:
1. match ~~`RHS`~~ **`LHS`** matcher to the ~~`first`~~ **`second`** operand of binary operator,
2. and then match ~~`LHS`~~ **`RHS`** matcher to the ~~`second`~ **`first`** operand of binary operator.

Surprisingly, `$ ninja check-llvm` still passes with this.
But i expect the bots will disagree..

The motivational unittest is included.
I'd like to use this in D45664.

Reviewers: spatel, craig.topper, arsenm, RKSimon

Reviewed By: craig.topper

Subscribers: xbolva00, wdng, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331085 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-27 21:23:20 +00:00
Sanjoy Das
03f69e2059 [InstCombine] Simplify Add with remainder expressions as operands.
Summary:
Simplify integer add expression X % C0 + (( X / C0 ) % C1) * C0 to
X % (C0 * C1).  This is a common pattern seen in code generated by the XLA
GPU backend.

Add test cases for this new optimization.

Patch by Bixia Zheng!

Reviewers: sanjoy

Reviewed By: sanjoy

Subscribers: efriedma, craig.topper, lebedev.ri, llvm-commits, jlebar

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330992 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-26 20:52:28 +00:00
Sanjay Patel
72fc210036 [InstCombine] simplify fneg+fadd folds; NFC
Two cleanups:
1. As noted in D45453, we had tests that don't need FMF that were misplaced in the 'fast-math.ll' test file.
2. This removes the final uses of dyn_castFNegVal, so that can be deleted. We use 'match' now.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330126 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-16 14:13:57 +00:00
Warren Ristow
cfa414cb84 [InstCombine] Enable Add/Sub simplifications with only 'reassoc' FMF
These simplifications were previously enabled only with isFast(), but that
is more restrictive than required. Since r317488, FMF has 'reassoc' to
control these cases at a finer level.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330089 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-14 19:18:28 +00:00
Sanjay Patel
eab1e54c67 [InstCombine] limit X - (cast(-Y) --> X + cast(Y) with hasOneUse()
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329821 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-11 15:57:18 +00:00
Sanjay Patel
d637812084 [InstCombine] limit nsz: -(X - Y) --> Y - X to hasOneUse()
As noted in the post-commit discussion for r329350, we shouldn't
generally assume that fsub is the same cost as fneg.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329429 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-06 17:24:08 +00:00
Sanjay Patel
06426a9f21 [InstCombine] FP: Z - (X - Y) --> Z + (Y - X)
This restores what was lost with rL73243 but without
re-introducing the bug that was present in the old code.

Note that we already have these transforms if the ops are 
marked 'fast' (and I assume that's happening somewhere in
the code added with rL170471), but we clearly don't need 
all of 'fast' for these transforms.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329362 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-05 23:21:15 +00:00
Sanjay Patel
bd62cc1c78 [InstCombine] nsz: -(X - Y) --> Y - X
This restores part of the fold that was removed with rL73243 (PR4374).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329350 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-05 21:37:17 +00:00
Sanjay Patel
4736168ad5 [InstCombine] use pattern matchers for fsub --> fadd folds
This allows folding for vectors with undef elements.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329316 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-05 17:06:45 +00:00
Sanjay Patel
1017678677 [PatternMatch] allow undef elements when matching vector FP +0.0
This continues the FP constant pattern matching improvements from:
https://reviews.llvm.org/rL327627
https://reviews.llvm.org/rL327339
https://reviews.llvm.org/rL327307

Several integer constant matchers also have this ability. I'm
separating matching of integer/pointer null from FP positive zero
and renaming/commenting to make the functionality clearer.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328461 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-25 21:16:33 +00:00
Sanjay Patel
80d9b90c34 [InstCombine] (~X) - (~Y) --> Y - X
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326660 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-03 17:53:25 +00:00
Sanjay Patel
2f11a75319 [InstCombine] move constant check into foldBinOpIntoSelectOrPhi; NFCI
Also, rename 'foldOpWithConstantIntoOperand' because that's annoyingly 
vague. The constant check is redundant in some cases, but it allows 
removing duplication for most of the calls.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326329 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-28 16:36:24 +00:00
Sanjay Patel
69e8988b65 [InstCombine] use FMF-copying functions to reduce code; NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@325923 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-23 17:07:29 +00:00
Sanjay Patel
2b68e112a3 [InstCombine] canonicalize constant-minus-boolean to select-of-constants
This restores the half of:
https://reviews.llvm.org/rL75531
that was reverted at:
https://reviews.llvm.org/rL159230

For the x86 case mentioned there, we now produce:
leal 1(%rdi), %eax
subl %esi, %eax

We have target hooks to invert this in DAGCombiner (and x86 is enabled) with:
https://reviews.llvm.org/rL296977
https://reviews.llvm.org/rL311731

AArch64 and possibly other targets would probably benefit from enabling those hooks too. 
See PR30327:
https://bugs.llvm.org/show_bug.cgi?id=30327#c2

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319964 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-06 21:22:57 +00:00
Sanjay Patel
00e900afdb [IR] redefine 'UnsafeAlgebra' / 'reassoc' fast-math-flags and add 'trans' fast-math-flag
As discussed on llvm-dev:
http://lists.llvm.org/pipermail/llvm-dev/2016-November/107104.html
and again more recently:
http://lists.llvm.org/pipermail/llvm-dev/2017-October/118118.html

...this is a step in cleaning up our fast-math-flags implementation in IR to better match
the capabilities of both clang's user-visible flags and the backend's flags for SDNode.

As proposed in the above threads, we're replacing the 'UnsafeAlgebra' bit (which had the 
'umbrella' meaning that all flags are set) with a new bit that only applies to algebraic 
reassociation - 'AllowReassoc'.

We're also adding a bit to allow approximations for library functions called 'ApproxFunc' 
(this was initially proposed as 'libm' or similar).

...and we're out of bits. 7 bits ought to be enough for anyone, right? :) FWIW, I did 
look at getting this out of SubclassOptionalData via SubclassData (spacious 16-bits), 
but that's apparently already used for other purposes. Also, I don't think we can just 
add a field to FPMathOperator because Operator is not intended to be instantiated. 
We'll defer movement of FMF to another day.

We keep the 'fast' keyword. I thought about removing that, but seeing IR like this:
%f.fast = fadd reassoc nnan ninf nsz arcp contract afn float %op1, %op2
...made me think we want to keep the shortcut synonym.

Finally, this change is binary incompatible with existing IR as seen in the 
compatibility tests. This statement:
"Newer releases can ignore features from older releases, but they cannot miscompile 
them. For example, if nsw is ever replaced with something else, dropping it would be 
a valid way to upgrade the IR." 
( http://llvm.org/docs/DeveloperPolicy.html#ir-backwards-compatibility )
...provides the flexibility we want to make this change without requiring a new IR 
version. Ie, we're not loosening the FP strictness of existing IR. At worst, we will 
fail to optimize some previously 'fast' code because it's no longer recognized as 
'fast'. This should get fixed as we audit/squash all of the uses of 'isFast()'.

Note: an inter-dependent clang commit to use the new API name should closely follow 
commit.

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317488 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-06 16:27:15 +00:00