<feed xmlns='http://www.w3.org/2005/Atom'>
<title>llvm-project.git/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp, branch users/nico/python-2</title>
<subtitle>Unnamed repository; edit this file 'description' to name the repository.
</subtitle>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/'/>
<entry>
<title>[InstCombine] Preserve NSW/NUW flags when folding const BOp with min/max (#143471)</title>
<updated>2025-06-13T18:16:44+00:00</updated>
<author>
<name>Alex MacLean</name>
<email>amaclean@nvidia.com</email>
</author>
<published>2025-06-13T18:16:44+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=59388fb0b92d7efd5737efd6c7b6d5c82f1bc6a8'/>
<id>59388fb0b92d7efd5737efd6c7b6d5c82f1bc6a8</id>
<content type='text'>
When folding `X Pred C2 ? X BOp C1 : C2 BOp C1` to `min/max(X, C2) BOp
C1`, if NUW/NSW flags are present on `X BOp C1` and could be safely
applied to `C2 BOp C1`, then they may be added on the BOp after the fold
is complete. https://alive2.llvm.org/ce/z/n_3aNJ

Preserving these flags can allow subsequent transforms to re-order the
min/max and BOp, which in the case of NVPTX would allow for some
potential future transformations which would improve
instruction-selection.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When folding `X Pred C2 ? X BOp C1 : C2 BOp C1` to `min/max(X, C2) BOp
C1`, if NUW/NSW flags are present on `X BOp C1` and could be safely
applied to `C2 BOp C1`, then they may be added on the BOp after the fold
is complete. https://alive2.llvm.org/ce/z/n_3aNJ

Preserving these flags can allow subsequent transforms to re-order the
min/max and BOp, which in the case of NVPTX would allow for some
potential future transformations which would improve
instruction-selection.</pre>
</div>
</content>
</entry>
<entry>
<title>[llvm][InstCombine] Fold select to cmp for weak and inverted inequalities (#143445)</title>
<updated>2025-06-13T13:53:34+00:00</updated>
<author>
<name>Yash Solanki</name>
<email>67216443+yashnator@users.noreply.github.com</email>
</author>
<published>2025-06-13T13:53:34+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=a361a3dc7a12b776507f48035f245e764c45455d'/>
<id>a361a3dc7a12b776507f48035f245e764c45455d</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>[InstCombine] Fold max/min when incrementing/decrementing by 1 (#142466)</title>
<updated>2025-06-10T14:55:56+00:00</updated>
<author>
<name>Alex MacLean</name>
<email>amaclean@nvidia.com</email>
</author>
<published>2025-06-10T14:55:56+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=09029045a88b48591ce645bae640fc3bc8b58b63'/>
<id>09029045a88b48591ce645bae640fc3bc8b58b63</id>
<content type='text'>
Add the following folds for integer min max folding in InstCombine:
 -  (X &gt; Y) ? X : (Y - 1) ==&gt; MIN(X, Y - 1)
 -  (X &lt; Y) ? X : (Y + 1) ==&gt; 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 &gt;= width)
    return width - 1;
  return idx;
}

https://cuda.godbolt.org/z/nhPzWrc3W</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Add the following folds for integer min max folding in InstCombine:
 -  (X &gt; Y) ? X : (Y - 1) ==&gt; MIN(X, Y - 1)
 -  (X &lt; Y) ? X : (Y + 1) ==&gt; 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 &gt;= width)
    return width - 1;
  return idx;
}

https://cuda.godbolt.org/z/nhPzWrc3W</pre>
</div>
</content>
</entry>
<entry>
<title>[InstCombine] Allow min/max in constant BOp min/max folding (#142878)</title>
<updated>2025-06-06T19:44:04+00:00</updated>
<author>
<name>Alex MacLean</name>
<email>amaclean@nvidia.com</email>
</author>
<published>2025-06-06T19:44:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=107601ed063f9e92aba61ea4f2a36c372127a82a'/>
<id>107601ed063f9e92aba61ea4f2a36c372127a82a</id>
<content type='text'>
Extend folding for `X Pred C2 ? X BOp C1 : C2 BOp C1` to `min/max(X, C2)
BOp C1` to allow min and max as `BOp`. This ensures a constant clamping
pattern is folded into a pair of min/max instructions. Here is a
simplified example of a case where this folding is not occurring
currently.

int clampToU8(int v) {
    if (v &lt; 0) return 0;
    if (v &gt; 255) return 255;
    return v;
}

https://godbolt.org/z/78jhKPWbv

Generic proof: https://alive2.llvm.org/ce/z/cdpLYy</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Extend folding for `X Pred C2 ? X BOp C1 : C2 BOp C1` to `min/max(X, C2)
BOp C1` to allow min and max as `BOp`. This ensures a constant clamping
pattern is folded into a pair of min/max instructions. Here is a
simplified example of a case where this folding is not occurring
currently.

int clampToU8(int v) {
    if (v &lt; 0) return 0;
    if (v &gt; 255) return 255;
    return v;
}

https://godbolt.org/z/78jhKPWbv

Generic proof: https://alive2.llvm.org/ce/z/cdpLYy</pre>
</div>
</content>
</entry>
<entry>
<title>[InstCombine] Avoid infinite loop in `foldSelectValueEquivalence` (#142754)</title>
<updated>2025-06-04T11:42:56+00:00</updated>
<author>
<name>Yingwei Zheng</name>
<email>dtcxzyw2333@gmail.com</email>
</author>
<published>2025-06-04T11:42:56+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=5e2dcfe42cd4af14d6e6155314aa5d4167710b65'/>
<id>5e2dcfe42cd4af14d6e6155314aa5d4167710b65</id>
<content type='text'>
Before this patch, InstCombine hung because it replaced a value with a
more complex one:
```
%sel = select i1 %cmp, i32 %smax, i32 0 -&gt;
%sel = select i1 %cmp, i32 %masked, i32 0 -&gt;
%sel = select i1 %cmp, i32 %smax, i32 0 -&gt;
...
```
This patch makes this replacement more conservative. It only performs
the replacement iff the new value is one of the operands of the original
value.

Closes https://github.com/llvm/llvm-project/issues/142405.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Before this patch, InstCombine hung because it replaced a value with a
more complex one:
```
%sel = select i1 %cmp, i32 %smax, i32 0 -&gt;
%sel = select i1 %cmp, i32 %masked, i32 0 -&gt;
%sel = select i1 %cmp, i32 %smax, i32 0 -&gt;
...
```
This patch makes this replacement more conservative. It only performs
the replacement iff the new value is one of the operands of the original
value.

Closes https://github.com/llvm/llvm-project/issues/142405.</pre>
</div>
</content>
</entry>
<entry>
<title>[ValueTracking] Make Depth last default arg (NFC) (#142384)</title>
<updated>2025-06-03T16:12:24+00:00</updated>
<author>
<name>Ramkumar Ramachandra</name>
<email>ramkumar.ramachandra@codasip.com</email>
</author>
<published>2025-06-03T16:12:24+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=b40e4ceaa61c5f14ca261e2952e7f85a066403e2'/>
<id>b40e4ceaa61c5f14ca261e2952e7f85a066403e2</id>
<content type='text'>
Having a finite Depth (or recursion limit) for computeKnownBits is very
limiting, but is currently a load-bearing necessity, as all KnownBits
are recomputed on each call and there is no caching. As a prerequisite
for an effort to remove the recursion limit altogether, either using a
clever caching technique, or writing a easily-invalidable KnownBits
analysis, make the Depth argument in APIs in ValueTracking uniformly the
last argument with a default value. This would aid in removing the
argument when the time comes, as many callers that currently pass 0
explicitly are now updated to omit the argument altogether.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Having a finite Depth (or recursion limit) for computeKnownBits is very
limiting, but is currently a load-bearing necessity, as all KnownBits
are recomputed on each call and there is no caching. As a prerequisite
for an effort to remove the recursion limit altogether, either using a
clever caching technique, or writing a easily-invalidable KnownBits
analysis, make the Depth argument in APIs in ValueTracking uniformly the
last argument with a default value. This would aid in removing the
argument when the time comes, as many callers that currently pass 0
explicitly are now updated to omit the argument altogether.</pre>
</div>
</content>
</entry>
<entry>
<title>[InstCombine] Propagate FMF from select instead of fcmp (#141010)</title>
<updated>2025-05-31T08:25:10+00:00</updated>
<author>
<name>Yingwei Zheng</name>
<email>dtcxzyw2333@gmail.com</email>
</author>
<published>2025-05-31T08:25:10+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=3ec0c5c7fef03985b43432c6b914c289d8a5435e'/>
<id>3ec0c5c7fef03985b43432c6b914c289d8a5435e</id>
<content type='text'>
Previously,
https://github.com/llvm/llvm-project/commit/3d6b53980ce4ee855484fc8ae6ac3f99c85e48c3
propagates FMF from fcmp to avoid performance regressions. With the help
of https://github.com/llvm/llvm-project/pull/139861,
https://github.com/llvm/llvm-project/pull/141015, and
https://github.com/llvm/llvm-project/pull/141914, we can still convert
SPF into fabs/minnum/maxnum intrinsics even if some flags are missing.
This patch propagates FMF from select to address the long-standing
issue.

Closes https://github.com/llvm/llvm-project/issues/140994.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Previously,
https://github.com/llvm/llvm-project/commit/3d6b53980ce4ee855484fc8ae6ac3f99c85e48c3
propagates FMF from fcmp to avoid performance regressions. With the help
of https://github.com/llvm/llvm-project/pull/139861,
https://github.com/llvm/llvm-project/pull/141015, and
https://github.com/llvm/llvm-project/pull/141914, we can still convert
SPF into fabs/minnum/maxnum intrinsics even if some flags are missing.
This patch propagates FMF from select to address the long-standing
issue.

Closes https://github.com/llvm/llvm-project/issues/140994.</pre>
</div>
</content>
</entry>
<entry>
<title>[InstCombine] Use `canIgnoreSignBitOfZero` in `spf-&gt;minmax` fold (#141914)</title>
<updated>2025-05-30T06:18:05+00:00</updated>
<author>
<name>Yingwei Zheng</name>
<email>dtcxzyw2333@gmail.com</email>
</author>
<published>2025-05-30T06:18:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=87fd352d910889a9ada9085de9d141d8820a0f61'/>
<id>87fd352d910889a9ada9085de9d141d8820a0f61</id>
<content type='text'>
Alive2: https://alive2.llvm.org/ce/z/dCZBB_
Fix remaining regressions caused by https://github.com/llvm/llvm-project/pull/141010.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Alive2: https://alive2.llvm.org/ce/z/dCZBB_
Fix remaining regressions caused by https://github.com/llvm/llvm-project/pull/141010.</pre>
</div>
</content>
</entry>
<entry>
<title>[ValueTracking][InstCombine] Generalize ignoreSignBitOfZero/NaN to handle more cases (#141015)</title>
<updated>2025-05-28T11:17:51+00:00</updated>
<author>
<name>Yingwei Zheng</name>
<email>dtcxzyw2333@gmail.com</email>
</author>
<published>2025-05-28T11:17:51+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=6c86b7d7d8bc0f77242e938e68c0325acc7f04c3'/>
<id>6c86b7d7d8bc0f77242e938e68c0325acc7f04c3</id>
<content type='text'>
This patch was originally part of
https://github.com/llvm/llvm-project/pull/139861. It generalizes
`ignoreSignBitOfZero/NaN` to handle more instructions/intrinsics.

BTW, I find it mitigates performance regressions caused by
https://github.com/llvm/llvm-project/pull/141010 (IR diff
https://github.com/dtcxzyw/llvm-opt-benchmark/pull/2365/files). We don't
need to propagate FMF from fcmp into select, since we can infer demanded
properties from the user of select.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This patch was originally part of
https://github.com/llvm/llvm-project/pull/139861. It generalizes
`ignoreSignBitOfZero/NaN` to handle more instructions/intrinsics.

BTW, I find it mitigates performance regressions caused by
https://github.com/llvm/llvm-project/pull/141010 (IR diff
https://github.com/dtcxzyw/llvm-opt-benchmark/pull/2365/files). We don't
need to propagate FMF from fcmp into select, since we can infer demanded
properties from the user of select.</pre>
</div>
</content>
</entry>
<entry>
<title>[InstCombine] Enable more fabs fold when the user ignores sign bit of zero/NaN (#139861)</title>
<updated>2025-05-21T15:50:00+00:00</updated>
<author>
<name>Yingwei Zheng</name>
<email>dtcxzyw2333@gmail.com</email>
</author>
<published>2025-05-21T15:50:00+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=d13947bd6caf442151a4b3f51e3e8b226c490535'/>
<id>d13947bd6caf442151a4b3f51e3e8b226c490535</id>
<content type='text'>
When the only user of select is a fcmp or a fp operation with nnan/nsz,
the sign bit of zero/NaN can be ignored.
Alive2: https://alive2.llvm.org/ce/z/ZcxeIv

Compile-time impact:
https://llvm-compile-time-tracker.com/compare.php?from=7add1bcd02b1f72d580bb2e64a1fe4a8bdc085d9&amp;to=cb419c7cbddce778673f3d4b414ed9b8064b8d6e&amp;stat=instructions:u

Closes https://github.com/llvm/llvm-project/issues/133367.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When the only user of select is a fcmp or a fp operation with nnan/nsz,
the sign bit of zero/NaN can be ignored.
Alive2: https://alive2.llvm.org/ce/z/ZcxeIv

Compile-time impact:
https://llvm-compile-time-tracker.com/compare.php?from=7add1bcd02b1f72d580bb2e64a1fe4a8bdc085d9&amp;to=cb419c7cbddce778673f3d4b414ed9b8064b8d6e&amp;stat=instructions:u

Closes https://github.com/llvm/llvm-project/issues/133367.</pre>
</div>
</content>
</entry>
</feed>
