Commit Graph

533 Commits

Author SHA1 Message Date
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
Sanjay Patel 4408ff5e00 [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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354406 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-20 00:09:50 +00:00
Sanjay Patel 7db184f31e [InstSimplify] add vector tests for fcmp+fabs; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354404 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-19 23:58:02 +00:00
Dmitry Venikov 505cfd572a [InstSimplify] Missed optimization in math expression: log10(pow(10.0,x)) == x, log2(pow(2.0,x)) == x
Summary: This patch enables folding following instructions under -ffast-math flag: log10(pow(10.0,x)) -> x, log2(pow(2.0,x)) -> x

Reviewers: hfinkel, spatel, efriedma, craig.topper, zvi, majnemer, lebedev.ri

Reviewed By: spatel, lebedev.ri

Subscribers: lebedev.ri, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352981 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-03 03:48:30 +00:00
Dmitry Venikov 066452779d Commit tests for changes in revision D41940
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352734 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-31 07:38:19 +00:00
Nikita Popov f52646ddc7 [ConstantFolding] Consolidate and extend bitcount intrinsic tests; NFC
Move constant folding tests into ConstantFolding/bitcount.ll and drop
various tests in other places. Add coverage for undefs.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349806 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-20 19:46:52 +00:00
Nikita Popov e84034484b [InstSimplify] Simplify saturating add/sub + icmp
If a saturating add/sub has one constant operand, then we can
determine the possible range of outputs it can produce, and simplify
an icmp comparison based on that.

The implementation is based on a similar existing mechanism for
simplifying binary operator + icmps.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349369 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-17 17:45:18 +00:00
Nikita Popov dbb2df9229 [InstCombine] Add additional saturating add/sub + icmp tests; NFC
These test comparisons with saturating add/sub in non-canonical
form.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349309 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-16 17:45:25 +00:00
Nikita Popov 7c45236930 [InstSimplify] Add tests for saturating add/sub + icmp; NFC
If a saturating add/sub with a constant operand is compared to
another constant, we should be able to determine that the condition
is always true/false in some cases (but currently don't).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349261 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-15 10:37:01 +00:00
Sanjay Patel 7c4834215a [InstCombine] remove dead code from visitExtractElement
Extracting from a splat constant is always handled by InstSimplify.
Move the test for this from InstCombine to InstSimplify to make
sure that stays true.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348423 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-05 23:09:33 +00:00
Sanjay Patel 83bcdb16b4 [InstSimplify] add tests for undef + partial undef constant folding; NFC
These tests should probably go under a separate test file because they
should fold with just -constprop, but they're similar to the scalar
tests already in here.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348045 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-30 22:51:34 +00:00
Sanjay Patel 3c0efb7a96 [InstSimplify] fold select with implied condition
This is an almost direct move of the functionality from InstCombine to 
InstSimplify. There's no reason not to do this in InstSimplify because 
we never create a new value with this transform.

(There's a question of whether any dominance-based transform belongs in
either of these passes, but that's a separate issue.)

I've changed 1 of the conditions for the fold (1 of the blocks for the 
branch must be the block we started with) into an assert because I'm not 
sure how that could ever be false.

We need 1 extra check to make sure that the instruction itself is in a
basic block because passes other than InstCombine may be using InstSimplify
as an analysis on values that are not wired up yet.

The 3-way compare changes show that InstCombine has some kind of 
phase-ordering hole. Otherwise, we would have already gotten the intended
final result that we now show here.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347896 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-29 18:44:39 +00:00
Sanjay Patel eaf81518af [InstSimplify] fold funnel shifts with undef operands
Splitting these off from the D54666.

Patch by: nikic (Nikita Popov)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347332 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-20 17:34:59 +00:00
Sanjay Patel acc323be20 [InstSimplify] add tests for funnel shift with undef operands; NFC
These are part of D54666, so adding them here before the patch to
show the baseline (currently unoptimized) results.

Patch by: @nikic (Nikita Popov)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347331 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-20 17:30:09 +00:00
Sanjay Patel ad4da63ac2 [InstructionSimplify] Add support for saturating add/sub
Add support for saturating add/sub in InstructionSimplify. In particular, the following simplifications are supported:

    sat(X + 0) -> X
    sat(X + undef) -> -1
    sat(X uadd MAX) -> MAX
    (and commutative variants)

    sat(X - 0) -> X
    sat(X - X) -> 0
    sat(X - undef) -> 0
    sat(undef - X) -> 0
    sat(0 usub X) -> 0
    sat(X usub MAX) -> 0

Patch by: @nikic (Nikita Popov)

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347330 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-20 17:20:26 +00:00
Sanjay Patel 40bfd6fe1e [PatternMatch] Handle undef vectors consistently
This patch fixes the issue noticed in D54532. 
The problem is that cst_pred_ty-based matchers like m_Zero() currently do not match 
scalar undefs (as expected), but *do* match vector undefs. This may lead to optimization 
inconsistencies in rare cases.

There is only one existing test for which output changes, reverting the change from D53205. 
The reason here is that vector fsub undef, %x is no longer matched as an m_FNeg(). While I 
think that the new output is technically worse than the previous one, it is consistent with 
scalar, and I don't think it's really important either way (generally that undef should have 
been folded away prior to reassociation.)

I've also added another test case for this issue based on InstructionSimplify. It took some 
effort to find that one, as in most cases undef folds are either checked first -- and in the 
cases where they aren't it usually happens to not make a difference in the end. This is the 
only case I was able to come up with. Prior to this patch the test case simplified to undef 
in the scalar case, but zeroinitializer in the vector case.

Patch by: @nikic (Nikita Popov)

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347318 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-20 16:08:19 +00:00
Sanjay Patel 7c5ab08064 [InstSimplify] add tests for saturating add/sub; NFC
These are baseline tests for D54532.
Patch based on the original tests by:
@nikic (Nikita Popov)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347060 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-16 16:32:34 +00:00
Sanjay Patel 9d51722c9d [InstSimplify] add test to demonstrate undef matching differences; NFC
This is a baseline test for D54631.
Patch by:
@nikic (Nikita Popov)



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347055 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-16 15:35:58 +00:00
Sanjay Patel fc0780a8a9 [InstSimplify] delete shift-of-zero guard ops around funnel shifts
This is a problem seen in common rotate idioms as noted in:
https://bugs.llvm.org/show_bug.cgi?id=34924

Note that we are not canonicalizing standard IR (shifts and logic) to the intrinsics yet. 
(Although I've written this before...) I think this is the last step before we enable 
that transform. Ie, we could regress code by doing that transform without this 
simplification in place.

In PR34924, I questioned whether this is a valid transform for target-independent IR, 
but I convinced myself this is ok. If we're speculating a funnel shift by turning cmp+br 
into select, then SimplifyCFG has already determined that the transform is justified. 
It's possible that SimplifyCFG is not taking into account profile or other metadata, 
but if that's true, then it's a bug independent of funnel shifts.

Also, we do have CGP code to restore a guard like this around an intrinsic if it can't 
be lowered cheaply. But that isn't necessary for funnel shift because the default 
expansion in SelectionDAGBuilder includes this same cmp+select.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346960 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-15 14:53:37 +00:00
Sanjay Patel 530c44f27c [InstSimplify] add more tests for funnel shift with select; NFC
The cases are just different enough that we should have 
complete tests to avoid bugs from typos in the code.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346902 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-14 22:34:25 +00:00
Sanjay Patel c79bd8af97 [InstSimplify] add tests for funnel shift with select; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346881 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-14 19:12:54 +00:00
Sanjay Patel e357c8b879 [InstSimplify] fold select (fcmp X, Y), X, Y
This is NFCI for InstCombine because it calls InstSimplify, 
so I left the tests for this transform there. As noted in
the code comment, we can allow this fold more often by using
FMF and/or value tracking.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346169 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-05 21:51:39 +00:00
Sanjay Patel 80ce0ad512 [InstSimplify] add tests for select+fcmp; NFC
These are translated from InstCombine's test file with the same name.
We should move the transform from InstCombine to InstSimplify.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346168 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-05 21:42:01 +00:00
Sanjay Patel 148536769a [InstSimplify] fold icmp based on range of abs/nabs (2nd try)
This is retrying the fold from rL345717 
(reverted at rL347780)
...with a fix for the miscompile
demonstrated by PR39510:
https://bugs.llvm.org/show_bug.cgi?id=39510

Original commit message:

This is a fix for PR39475:
https://bugs.llvm.org/show_bug.cgi?id=39475

We managed to get some of these patterns using computeKnownBits in https://reviews.llvm.org/D47041, but that
can't be used for nabs(). Instead, put in some range-based logic, so we can fold
both abs/nabs with icmp with a constant value.

Alive proofs:
https://rise4fun.com/Alive/21r

Name: abs_nsw_is_positive

  %cmp = icmp slt i32 %x, 0
  %negx = sub nsw i32 0, %x
  %abs = select i1 %cmp, i32 %negx, i32 %x
  %r = icmp sgt i32 %abs, -1
    =>
  %r = i1 true


Name: abs_nsw_is_not_negative

  %cmp = icmp slt i32 %x, 0
  %negx = sub nsw i32 0, %x
  %abs = select i1 %cmp, i32 %negx, i32 %x
  %r = icmp slt i32 %abs, 0
    =>
  %r = i1 false


Name: nabs_is_negative_or_0

  %cmp = icmp slt i32 %x, 0
  %negx = sub i32 0, %x
  %nabs = select i1 %cmp, i32 %x, i32 %negx
  %r = icmp slt i32 %nabs, 1
    =>
  %r = i1 true

Name: nabs_is_not_over_0

  %cmp = icmp slt i32 %x, 0
  %negx = sub i32 0, %x
  %nabs = select i1 %cmp, i32 %x, i32 %negx
  %r = icmp sgt i32 %nabs, 0
    =>
  %r = i1 false

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345832 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-01 14:07:39 +00:00
Sanjay Patel 258eac5bd6 [InstSimplify] add tests for icmp fold bug (PR39510); NFC
Verify that set intersection/subset are not confused.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345831 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-01 14:03:22 +00:00
Sanjay Patel 9268a4a0f0 revert rL345717 : [InstSimplify] fold icmp based on range of abs/nabs
This can miscompile as shown in PR39510:
https://bugs.llvm.org/show_bug.cgi?id=39510


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345780 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-31 21:37:40 +00:00
Sanjay Patel 5406c80642 [InstSimplify] fold 'fcmp nnan ult X, 0.0' when X is not negative
This is the inverted case for the transform added with D53874 / rL345725.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345728 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-31 15:35:46 +00:00
Sanjay Patel 1ef057dce8 [InstSimplify] fold 'fcmp nnan oge X, 0.0' when X is not negative
This re-raises some of the open questions about how to apply and use fast-math-flags in IR from PR38086:
https://bugs.llvm.org/show_bug.cgi?id=38086
...but given the current implementation (no FMF on casts), this is likely the only way to predicate the 
transform.

This is part of solving PR39475:
https://bugs.llvm.org/show_bug.cgi?id=39475

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345725 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-31 14:57:23 +00:00
Sanjay Patel ea1119a1f5 [InstSimplify] add tests for fcmp and known positive; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345722 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-31 14:29:21 +00:00
Sanjay Patel 893f08bea2 [InstSimplify] fold icmp based on range of abs/nabs
This is a fix for PR39475:
https://bugs.llvm.org/show_bug.cgi?id=39475

We managed to get some of these patterns using computeKnownBits in D47041, but that 
can't be used for nabs(). Instead, put in some range-based logic, so we can fold 
both abs/nabs with icmp with a constant value.

Alive proofs:
https://rise4fun.com/Alive/21r

Name: abs_nsw_is_positive
  %cmp = icmp slt i32 %x, 0
  %negx = sub nsw i32 0, %x
  %abs = select i1 %cmp, i32 %negx, i32 %x
  %r = icmp sgt i32 %abs, -1
    =>
  %r = i1 true
 
Name: abs_nsw_is_not_negative
  %cmp = icmp slt i32 %x, 0
  %negx = sub nsw i32 0, %x
  %abs = select i1 %cmp, i32 %negx, i32 %x
  %r = icmp slt i32 %abs, 0
    =>
  %r = i1 false
 
Name: nabs_is_negative_or_0
  %cmp = icmp slt i32 %x, 0
  %negx = sub i32 0, %x
  %nabs = select i1 %cmp, i32 %x, i32 %negx
  %r = icmp slt i32 %nabs, 1
    =>
  %r = i1 true

Name: nabs_is_not_over_0
  %cmp = icmp slt i32 %x, 0
  %negx = sub i32 0, %x
  %nabs = select i1 %cmp, i32 %x, i32 %negx
  %r = icmp sgt i32 %nabs, 0
    =>
  %r = i1 false

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345717 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-31 13:25:10 +00:00
Sanjay Patel 9abf4aed73 [InstSimplify] add tests for fcmp folds; NFC
This is part of a problem noted in PR39475:
https://bugs.llvm.org/show_bug.cgi?id=39475



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345615 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-30 16:58:43 +00:00
Sanjay Patel d06dc588fe [InstSimplify] add tests for abs/nabs+icmp folding; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345541 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-29 21:05:41 +00:00
Thomas Lively 9e79a4ff27 [InstCombine] InstCombine and InstSimplify for minimum and maximum
Summary: Depends on D52765

Reviewers: aheejin, dschuff

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344799 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-19 19:01:26 +00:00