LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 46915 - analysis for min/max/abs intrinsics
Summary: analysis for min/max/abs intrinsics
Status: NEW
Alias: None
Product: libraries
Classification: Unclassified
Component: Scalar Optimizations (show other bugs)
Version: trunk
Hardware: PC All
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on: 48900
Blocks: 45972
  Show dependency tree
 
Reported: 2020-07-30 10:05 PDT by Sanjay Patel
Modified: 2021-06-17 18:17 PDT (History)
8 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sanjay Patel 2020-07-30 10:05:26 PDT
We recently added IR intrinsics for min/max/abs, and there are several areas that need to be updated to support and optimize these. Please comment here if you are or are planning to work on any part of this, so we do not duplicate effort.

Partial list:
 * ConstantFolding
 * ValueTracking
 * InstSimplify
 * InstCombine
 * PatternMatch
 * DemandedBits
 * Vectorization 
 * Cost Modeling
 * LVI, CVP, SCCP
 * SCEV
 * IndVars
Comment 1 Sanjay Patel 2020-07-30 10:06:48 PDT
I'm working on ConstantFolding and InstSimplify currently.
Comment 2 Craig Topper 2020-07-30 10:39:46 PDT
I'm working on computeKnownBits for abs
Comment 3 Simon Pilgrim 2020-07-30 11:39:26 PDT
Default + X86 costs have been committed.
Comment 4 Simon Pilgrim 2020-08-07 03:51:46 PDT
SLP - basic abs/min/max vectorization works fine

I'm going to look at adding min/max intrinsic reduction support
Comment 5 Sanjay Patel 2020-08-11 13:02:24 PDT
This was the last InstSimplify that was on my list to adapt:
https://reviews.llvm.org/rG1470ce4a76fc

Constant folding should be complete too.
Comment 6 Sanjay Patel 2020-09-03 13:22:02 PDT
I think we have most of it covered now. I'm not as familiar with the last 3 on the list (LVI/CVP/SCCP, SCEV, IndVars).

What needs to be done before we start producing intrinsics in place of cmp+select in instcombine transforms?
Comment 7 Nikita Popov 2020-09-03 13:34:52 PDT
The main thing that still needs to be done is recognizing min/max intrinsics in SCEV.
Comment 8 Sanjay Patel 2020-09-18 09:32:44 PDT
First try to get abs() canonicalized:
https://reviews.llvm.org/D87188

As I mentioned there, I don't think we have our *size* cost models updated (but let me know if I'm misreading the code).

We updated the throughput models here:
https://github.com/llvm/llvm-project/commit/c5ef1f1edd4d539df530b07daf7a0c8b94d0efc8
https://github.com/llvm/llvm-project/commit/0a0f28254ab7ae5cc9e1868a0ef1ba03d945434d

That's what is used by the vectorizers, but that's probably not what is used by unrolling, inlining, and simplifycfg.
Comment 9 Sanjay Patel 2020-12-10 09:21:18 PST
The basic cost model handling is in place as of:
https://reviews.llvm.org/D90554 / https://reviews.llvm.org/rGe32bd3512043

Still trying to get abs canonicalization in with:
https://reviews.llvm.org/D87188
Comment 10 Roman Lebedev 2020-12-18 10:25:30 PST
(In reply to Sanjay Patel from comment #9)
> The basic cost model handling is in place as of:
> https://reviews.llvm.org/D90554 / https://reviews.llvm.org/rGe32bd3512043

> Still trying to get abs canonicalization in with:
> https://reviews.llvm.org/D87188
Done.
Comment 11 Nikita Popov 2020-12-18 12:10:33 PST
Awesome! Only part left now is to canonicalize min/max...

I took a quick look at that, here's how the InstCombine test diff looks like: https://gist.github.com/nikic/f69061736ea8e6b6c159b28b09991599

We're still missing quite a few folds, e.g. pushing nots across min/max and forming unsigned saturating math.
Comment 12 Sanjay Patel 2021-01-22 11:16:59 PST
Over in bug 48816, we discovered that we need narrowing combines for abs to avoid regressions. 

I'll work on the related folds for min/max.
Comment 13 Sanjay Patel 2021-03-01 06:35:42 PST
(In reply to Sanjay Patel from comment #12)
> I'll work on the related folds for min/max.

Those were:
https://reviews.llvm.org/rG09a136bcc694
https://reviews.llvm.org/rG0ce2920f1707
Comment 14 Sanjay Patel 2021-04-02 05:19:44 PDT
This is likely the best view of current state:
https://reviews.llvm.org/D98152

There are still missing parts of analysis/instcombines as noted.

I think SLP is done (and the sooner we can switch to intrinsics, the better because supporting cmp+select is still at risk for hard-to-spot bugs as shown in https://reviews.llvm.org/D99753 ).

AFAIK, LoopVectorizer is partially done. I'll add some PhaseOrdering tests to increase visibility.
Comment 15 Roman Lebedev 2021-04-10 14:52:26 PDT
Added CVP handling for abs/min/max
Comment 16 David Zarzycki 2021-06-17 18:17:06 PDT
What about saturating intrinsics? The same pattern matching discrepancy seems to apply, no?