diff options
author | Alex MacLean <amaclean@nvidia.com> | 2025-06-10 07:55:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-10 07:55:56 -0700 |
commit | 09029045a88b48591ce645bae640fc3bc8b58b63 (patch) | |
tree | ff1e52a4dac9489f7ab522cf5f6baef9fa551bd3 /llvm/unittests/ProfileData/MemProfTest.cpp | |
parent | e74d834cb155a894fa0f9dbd1483b7fef53a79ae (diff) | |
download | llvm-09029045a88b48591ce645bae640fc3bc8b58b63.zip llvm-09029045a88b48591ce645bae640fc3bc8b58b63.tar.gz llvm-09029045a88b48591ce645bae640fc3bc8b58b63.tar.bz2 |
[InstCombine] Fold max/min when incrementing/decrementing by 1 (#142466)
Add the following folds for integer min max folding in InstCombine:
- (X > Y) ? X : (Y - 1) ==> MIN(X, Y - 1)
- (X < Y) ? X : (Y + 1) ==> MAX(X, Y + 1)
These are safe when overflow corresponding to the sign of the comparison
is poison. (proof https://alive2.llvm.org/ce/z/oj5iiI).
The most common of these patterns is likely the minimum case which
occurs in some internal library code when clamping an integer index to a
range (The maximum cases are included for completeness). Here is a
simplified example:
int clampToWidth(int idx, int width) {
if (idx >= width)
return width - 1;
return idx;
}
https://cuda.godbolt.org/z/nhPzWrc3W
Diffstat (limited to 'llvm/unittests/ProfileData/MemProfTest.cpp')
0 files changed, 0 insertions, 0 deletions