Commit Graph

565 Commits

Author SHA1 Message Date
Sanjay Patel
347248d483 [InstSimplify] simplify power-of-2 (single bit set) sequences
As discussed in PR42314:
https://bugs.llvm.org/show_bug.cgi?id=42314

Improving the canonicalization for these patterns:
rL363956
...means we should adjust/enhance the related simplification.

https://rise4fun.com/Alive/w1cp

  Name: isPow2 or zero
  %x = and i32 %xx, 2048
  %a = add i32 %x, -1
  %r = and i32 %a, %x
  =>
  %r = i32 0

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363997 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-20 22:55:28 +00:00
Sanjay Patel
a0711e68bd [InstSimplify] add tests for known-not-a-power-of-2; NFC
I added a canonicalization to create this general pattern in:
rL363956

But as noted in PR42314:
https://bugs.llvm.org/show_bug.cgi?id=42314#c11

...we have a (potentially expensive) simplification for the version
of the code that we just canonicalized away from, so we should
add/adjust that code to match.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363981 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-20 21:04:14 +00:00
Sanjay Patel
f9309e39c3 [InstSimplify] add a phi test with 1 incoming value; NFC
D63489 proposes to change this behavior, but there's no
direct -instsimplify test to verify that the transform exists.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363842 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-19 17:23:29 +00:00
Jay Foad
c54dc66218 [ConstantFolding] Fix assertion failure on non-power-of-two vector load.
Summary:
The test case does an (out of bounds) load from a global constant with
type <3 x float>. InstSimplify tried to turn this into an integer load
of the whole alloc size of the vector, which is 128 bits due to
alignment padding, and then bitcast this to <3 x vector> which failed
an assertion due to the type size mismatch.

The fix is to do an integer load of the normal size of the vector, with
no alignment padding.

Reviewers: tpr, arsenm, majnemer, dstuttard

Reviewed By: arsenm

Subscribers: hfinkel, wdng, llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363784 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-19 10:28:48 +00:00
Roman Lebedev
d09f140cd1 [InstSimplify] Fix addo/subo undef folds (PR42209)
Fix folds of addo and subo with an undef operand to be:

`@llvm.{u,s}{add,sub}.with.overflow` all fold to `{ undef, false }`,
 as per LLVM undef rules.
Same for commuted variants.

Based on the original version of the patch by @nikic.

Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=42209 | PR42209 ]]

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363522 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-16 20:39:45 +00:00
Sanjay Patel
8a87b868f5 [InstSimplify] enhance fcmp fold with never-nan operand
This is another step towards correcting our usage of fast-math-flags when applied on an fcmp.
In this case, we are checking for 'nnan' on the fcmp itself rather than the operand of
the fcmp. But I'm leaving that clause in until we're more confident that we can stop
relying on fcmp's FMF.

By using the more general "isKnownNeverNaN()", we gain a simplification shown on the
tests with 'uitofp' regardless of the FMF on the fcmp (uitofp never produces a NaN).
On the tests with 'fabs', we are now relying on the FMF for the call fabs instruction
in addition to the FMF on the fcmp.

This is a continuation of D62979 / rL362879.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362903 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-09 13:48:59 +00:00
Sanjay Patel
4cca04faf2 [InstSimplify] add tests for fcmp with known-never-nan operands; NFC
Opposite predicate for rL362742 / rL362879 / D62979

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362902 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-09 13:30:14 +00:00
Sanjay Patel
51431e756c [InstSimplify] enhance fcmp fold with never-nan operand
This is 1 step towards correcting our usage of fast-math-flags when applied on an fcmp.
In this case, we are checking for 'nnan' on the fcmp itself rather than the operand of
the fcmp. But I'm leaving that clause in until we're more confident that we can stop
relying on fcmp's FMF.

By using the more general "isKnownNeverNaN()", we gain a simplification shown on the
tests with 'uitofp' regardless of the FMF on the fcmp (uitofp never produces a NaN).
On the tests with 'fabs', we are now relying on the FMF for the call fabs instruction
in addition to the FMF on the fcmp.

I'll update the 'ult' case below here as a follow-up assuming no problems here.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362879 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-08 15:12:33 +00:00
Sanjay Patel
0460af3331 [InstSimplify] add tests for fcmp with known-never-nan operands; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362742 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-06 20:14:06 +00:00
Sanjay Patel
4888407568 [InstSimplify] fold insertelement-of-extractelement
This was partly handled in InstCombine (only the constant
index case), so delete that and zap it more generally in
InstSimplify.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361576 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-24 00:13:58 +00:00
Sanjay Patel
d095a2fe17 [InstSimplify] add tests for insert-of-extract; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361575 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-24 00:11:23 +00:00
Sanjay Patel
8dc3a075f3 [InstSimplify] insertelement V, undef, ? --> V
This was part of InstCombine, but it's better placed in
InstSimplify. InstCombine also had an unreachable but weaker
fold for insertelement with undef index, so that is deleted.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361559 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-23 21:49:47 +00:00
Cameron McInally
dc94462906 [InstSimplify] Teach fsub -0.0, (fneg X) ==> X about unary fneg
Differential Revision: https://reviews.llvm.org/D62077

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361151 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-20 13:13:35 +00:00
Sanjay Patel
8dbc761309 [InstSimplify] fold fcmp (maxnum, X, C1), C2
This is the sibling transform for rL360899 (D61691):

  maxnum(X, GreaterC) == C --> false
  maxnum(X, GreaterC) <= C --> false
  maxnum(X, GreaterC) <  C --> false
  maxnum(X, GreaterC) >= C --> true
  maxnum(X, GreaterC) >  C --> true
  maxnum(X, GreaterC) != C --> true

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361118 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-19 14:26:39 +00:00
Cameron McInally
e36567e474 [NFC][InstSimplify] Add more unary fneg tests to floating-point-arithmetic.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361076 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-17 21:10:11 +00:00
Cameron McInally
4edb268ba5 [NFC][InstSimplify] Precommit new unary fneg test
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361060 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-17 18:34:35 +00:00
Cameron McInally
b6fe331584 [NFC][InstSImplify] Fix flip-flopped comments and test names
In test/Transforms/InstSimplify/floating-point-arithmetic.ll

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361057 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-17 17:59:17 +00:00
Cameron McInally
9b20dc3577 [InstSimplify] Add unary fneg to fsub 0.0, (fneg X) ==> X transform
Differential Revision: https://reviews.llvm.org/D62013

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361047 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-17 16:47:00 +00:00
Cameron McInally
ef6ec86b0c [NFC][InstSimplify] Update fast-math.ll tests I botched in r360808.
These were new tests I added in r360808. I made a mistake while converting the exisiting binary FNeg test into the new unary FNeg tests. Correct that.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360928 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-16 19:00:57 +00:00
Sanjay Patel
ba81ceb9be [InstSimplify] add tests for fcmp of maxnum with constants; NFC
Sibling tests for rL360899 (D61691).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360905 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-16 15:00:11 +00:00
Sanjay Patel
90a7bd7e82 [InstSimplify] fold fcmp (minnum, X, C1), C2
minnum(X, LesserC) == C --> false
   minnum(X, LesserC) >= C --> false
   minnum(X, LesserC) >  C --> false
   minnum(X, LesserC) != C --> true
   minnum(X, LesserC) <= C --> true
   minnum(X, LesserC) <  C --> true

maxnum siblings will follow if there are no problems here.

We should be able to perform some other combines when the constants
are equal or greater-than too, but that would go in instcombine.

We might also generalize this by creating an FP ConstantRange
(similar to what we do for integers).

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360899 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-16 14:03:10 +00:00
Cameron McInally
ab863397eb Revert llvm-svn: 360807
Somehow submitted this patch twice.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360812 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-15 20:48:50 +00:00
Cameron McInally
832b299ea5 Pre-commit unary fneg tests to InstSimplify
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360808 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-15 20:27:37 +00:00
Cameron McInally
da36bb93c8 Add unary fneg to InstSimplify/fp-nan.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360807 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-15 20:27:35 +00:00
Cameron McInally
fbfc565fb1 Add unary fneg to InstSimplify/fp-nan.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360797 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-15 19:37:03 +00:00
Cameron McInally
917249a6e6 Teach InstSimplify -X + X --> 0.0 about unary FNeg
Differential Revision: https://reviews.llvm.org/D61916

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360777 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-15 14:31:33 +00:00
Sanjay Patel
2b5b5c473b [InstSimplify] add tests for fcmp+minnum; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360275 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-08 17:53:18 +00:00
Nikita Popov
87650a2cac Revert "[ValueTracking] Improve isKnowNonZero for Ints"
This reverts commit 3b137a495686bd6018d115ea82fb8bb7718349fd.

As reported in https://reviews.llvm.org/D60846, this is causing
miscompiles.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360260 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-08 14:50:01 +00:00
Dan Robertson
b3f2f90c20 [ValueTracking] Improve isKnowNonZero for Ints
Improve isKnownNonZero for integers in order to improve cttz
optimizations.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360222 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-08 02:25:08 +00:00
Sanjay Patel
79040e11a5 [ValueTracking] add logic for known-never-nan with minnum/maxnum
From the LangRef: "Returns NaN only if both operands are NaN."

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360206 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-07 22:58:31 +00:00
Sanjay Patel
0a1de10dea [InstSimplify] add tests for minnum/maxnum and NaN; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360197 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-07 21:50:09 +00:00
Cameron McInally
a0a00583bd Add FNeg support to InstructionSimplify
Differential Revision: https://reviews.llvm.org/D61573

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360053 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-06 16:05:10 +00:00
Dan Robertson
15ec533129 [NFC] Add baseline tests for int isKnownNonZero
Add baseline tests for improvements of isKnownNonZero for integer types.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359267 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-26 02:55:54 +00:00
Eric Christopher
598198edbc Revert "Temporarily Revert "Add basic loop fusion pass.""
The reversion apparently deleted the test/Transforms directory.

Will be re-reverting again.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358552 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-17 04:52:47 +00:00
Eric Christopher
02cc44c1b9 Temporarily Revert "Add basic loop fusion pass."
As it's causing some bot failures (and per request from kbarton).

This reverts commit r358543/ab70da07286e618016e78247e4a24fcb84077fda.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358546 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-17 02:12:23 +00:00
Fangrui Song
a333049e17 [ConstantFold] Don't evaluate FP or FP vector casts or truncations when simplifying icmp
Fix PR41476

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358262 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-12 07:34:30 +00:00
Nikita Popov
cdee3b7f23 Reapply [ValueTracking] Support min/max selects in computeConstantRange()
Add support for min/max flavor selects in computeConstantRange(),
which allows us to fold comparisons of a min/max against a constant
in InstSimplify. This fixes an infinite InstCombine loop, with the
test case taken from D59378.

Relative to the previous iteration, this contains some adjustments for
AMDGPU med3 tests: The AMDGPU target runs InstSimplify prior to codegen,
which ends up constant folding some existing med3 tests after this
change. To preserve these tests a hidden -amdgpu-scalar-ir-passes option
is added, which allows disabling scalar IR passes (that use InstSimplify)
for testing purposes.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357870 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-07 17:22:16 +00:00
Matt Arsenault
45c5050e90 InstSimplify: Fold round intrinsics from sitofp/uitofp
https://godbolt.org/z/gEMRZb

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357549 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-03 00:25:06 +00:00
Matt Arsenault
a5dc7cad20 InstSimplify: Add missing case from r357386
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357443 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-02 00:46:19 +00:00
Matt Arsenault
b52beb7497 InstSimplify: Add baseline test for upcoming change
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357386 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-01 14:03:44 +00:00
Nikita Popov
49e23dc657 [InstSimplify] Add tests for signed icmp of and/or; NFC
Even if a signed predicate is used, the ranges computed for and/or
are unsigned, resulting in missed simplifications.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356720 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-21 21:13:08 +00:00
Nikita Popov
2aa13e1fa8 [ValueTracking] Compute range for abs without nsw
This is a small followup to D59511. The code that was moved into
computeConstantRange() there is a bit overly conversative: If the
abs is not nsw, it does not compute any range. However, abs without
nsw still has a well-defined contiguous unsigned range from 0 to
SIGNED_MIN. This is a lot less useful than the usual 0 to SIGNED_MAX
range, but if we're already here we might as well specify it...

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356586 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-20 18:16:02 +00:00
Nikita Popov
df1fd0765b [InstSimplify] Add additional cmp of abs without nsw tests; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356520 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-19 21:12:21 +00:00
Nikita Popov
867969e80f Revert "[ValueTracking][InstSimplify] Support min/max selects in computeConstantRange()"
This reverts commit 106f0cdefb02afc3064268dc7a71419b409ed2f3.

This change impacts the AMDGPU smed3.ll and umed3.ll codegen tests.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356424 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-18 22:26:27 +00:00
Nikita Popov
348957eb04 [ValueTracking][InstSimplify] Support min/max selects in computeConstantRange()
Add support for min/max flavor selects in computeConstantRange(),
which allows us to fold comparisons of a min/max against a constant
in InstSimplify. This was suggested by spatel as an alternative
approach to D59378. I've also added the infinite looping test from
that revision here.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356415 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-18 21:35:19 +00:00
Nikita Popov
89d0f2ff48 [InstSimplify] Add additional icmp of min/max tests; NFC
These are baseline tests for D59506.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356408 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-18 21:19:56 +00:00
Sanjay Patel
d04ee38acd [InstSimplify] remove zero-shift-guard fold for general funnel shift
As discussed on llvm-dev:
http://lists.llvm.org/pipermail/llvm-dev/2019-February/130491.html

We can't remove the compare+select in the general case because
we are treating funnel shift like a standard instruction (as
opposed to a special instruction like select/phi).

That means that if one of the operands of the funnel shift is
poison, the result is poison regardless of whether we know that
the operand is actually unused based on the instruction's
particular semantics.

The motivating case for this transform is the more specific
rotate op (rather than funnel shift), and we are preserving the
fold for that case because there is no chance of introducing
extra poison when there is no anonymous extra operand to the
funnel shift.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354905 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-26 18:26:56 +00:00
Sanjay Patel
0d20d79a02 [InstSimplify] add tests for rotate; NFC
Rotate is a special-case of funnel shift that has different
poison constraints than the general case. That's not visible
yet in the existing tests, but it needs to be corrected.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354894 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-26 16:44:08 +00:00
Sanjay Patel
df5eac31e9 [InstSimplify] use any-zero matcher for fcmp folds
The m_APFloat matcher does not work with anything but strict
splat vector constants, so we could miss these folds and then
trigger an assertion in instcombine:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=13201

The previous attempt at this in rL354406 had a logic bug that
actually triggered a regression test failure, but I failed to
notice it the first time.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354467 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-20 14:34:00 +00:00
Sanjay Patel
81e598fa8a Revert "[InstSimplify] use any-zero matcher for fcmp folds"
This reverts commit 058bb8351351d56d2a4e8a772570231f9e5305e5.
Forgot to update another test affected by this change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354408 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-20 00:20:38 +00:00