<feed xmlns='http://www.w3.org/2005/Atom'>
<title>llvm-project.git/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp, branch main</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] Generalize trunc-shift-icmp fold from (1 &lt;&lt; Y) to (Pow2 &lt;&lt; Y) (#169163)</title>
<updated>2025-11-22T15:44:06+00:00</updated>
<author>
<name>Pedro Lobo</name>
<email>pedro.lobo@tecnico.ulisboa.pt</email>
</author>
<published>2025-11-22T15:44:06+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=e8af134bb7f891caa49178c8a04a8ca944c611df'/>
<id>e8af134bb7f891caa49178c8a04a8ca944c611df</id>
<content type='text'>
Extends the `icmp(trunc(shl))` fold to handle any power of 2 constant as
the shift base, not just 1. This generalizes the following patterns by
adjusting the comparison offsets by `log2(Pow2)`.

```llvm
(trunc (1 &lt;&lt; Y) to iN) == 0    --&gt; Y u&gt;= N
(trunc (1 &lt;&lt; Y) to iN) != 0    --&gt; Y u&lt;  N
(trunc (1 &lt;&lt; Y) to iN) == 2**C --&gt; Y ==  C
(trunc (1 &lt;&lt; Y) to iN) != 2**C --&gt; Y !=  C

; to

(trunc (Pow2 &lt;&lt; Y) to iN) == 0    --&gt; Y u&gt;= N - log2(Pow2)
(trunc (Pow2 &lt;&lt; Y) to iN) != 0    --&gt; Y u&lt;  N - log2(Pow2)
(trunc (Pow2 &lt;&lt; Y) to iN) == 2**C --&gt; Y ==  C - log2(Pow2)
(trunc (Pow2 &lt;&lt; Y) to iN) != 2**C --&gt; Y !=  C - log2(Pow2)
```

Proof: https://alive2.llvm.org/ce/z/2zwTkp</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Extends the `icmp(trunc(shl))` fold to handle any power of 2 constant as
the shift base, not just 1. This generalizes the following patterns by
adjusting the comparison offsets by `log2(Pow2)`.

```llvm
(trunc (1 &lt;&lt; Y) to iN) == 0    --&gt; Y u&gt;= N
(trunc (1 &lt;&lt; Y) to iN) != 0    --&gt; Y u&lt;  N
(trunc (1 &lt;&lt; Y) to iN) == 2**C --&gt; Y ==  C
(trunc (1 &lt;&lt; Y) to iN) != 2**C --&gt; Y !=  C

; to

(trunc (Pow2 &lt;&lt; Y) to iN) == 0    --&gt; Y u&gt;= N - log2(Pow2)
(trunc (Pow2 &lt;&lt; Y) to iN) != 0    --&gt; Y u&lt;  N - log2(Pow2)
(trunc (Pow2 &lt;&lt; Y) to iN) == 2**C --&gt; Y ==  C - log2(Pow2)
(trunc (Pow2 &lt;&lt; Y) to iN) != 2**C --&gt; Y !=  C - log2(Pow2)
```

Proof: https://alive2.llvm.org/ce/z/2zwTkp</pre>
</div>
</content>
</entry>
<entry>
<title>InstCombine: Stop transforming EQ/NE of SHR to 0 to ULT/UGT if &gt;1 use</title>
<updated>2025-11-18T03:39:20+00:00</updated>
<author>
<name>Peter Collingbourne</name>
<email>pcc@google.com</email>
</author>
<published>2025-11-18T03:39:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=b3c54914ef2066347370949ea30dd3fcbc4493f1'/>
<id>b3c54914ef2066347370949ea30dd3fcbc4493f1</id>
<content type='text'>
This is a small code size optimization that lets us avoid both shifting
and comparing to a constant if we need the shifted value anyway. On most
architectures the zero comparison is cheaper than a constant comparison
(or free if the shift sets flags).

Although this change appears to remove the optimization entirely, we
continue to do this transform if there is one use because of the code
below the removed code that transforms the shift into an and, followed
by the PR10267 case in InstCombinerImpl::foldICmpAndConstConst that
transforms the and into a ult/ugt. Added a test case to verify this
explicitly.

Per [1] reduces clang .text size by 0.09% and dynamic instruction count
by 0.01%.

[1] https://llvm-compile-time-tracker.com/compare.php?from=1f38d49ebe96417e368a567efa4d650b8a9ac30f&amp;to=0873787a12b8f2eab019d8211ace4bccc1807343&amp;stat=size-text

Reviewers: nikic, dtcxzyw

Reviewed By: dtcxzyw

Pull Request: https://github.com/llvm/llvm-project/pull/168007
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This is a small code size optimization that lets us avoid both shifting
and comparing to a constant if we need the shifted value anyway. On most
architectures the zero comparison is cheaper than a constant comparison
(or free if the shift sets flags).

Although this change appears to remove the optimization entirely, we
continue to do this transform if there is one use because of the code
below the removed code that transforms the shift into an and, followed
by the PR10267 case in InstCombinerImpl::foldICmpAndConstConst that
transforms the and into a ult/ugt. Added a test case to verify this
explicitly.

Per [1] reduces clang .text size by 0.09% and dynamic instruction count
by 0.01%.

[1] https://llvm-compile-time-tracker.com/compare.php?from=1f38d49ebe96417e368a567efa4d650b8a9ac30f&amp;to=0873787a12b8f2eab019d8211ace4bccc1807343&amp;stat=size-text

Reviewers: nikic, dtcxzyw

Reviewed By: dtcxzyw

Pull Request: https://github.com/llvm/llvm-project/pull/168007
</pre>
</div>
</content>
</entry>
<entry>
<title>[InstCombine]: Canonicalize to a mask when trunc nuw (#163628)</title>
<updated>2025-10-17T16:13:29+00:00</updated>
<author>
<name>kper</name>
<email>kevin.per@protonmail.com</email>
</author>
<published>2025-10-17T16:13:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=fcb5293ad0a13b665cbaee26edf33cbfaab6404d'/>
<id>fcb5293ad0a13b665cbaee26edf33cbfaab6404d</id>
<content type='text'>
The canonicalize is also triggered when the `trunc` is `nuw`.

Proof: https://alive2.llvm.org/ce/z/eWvWe3
Fixes: https://github.com/llvm/llvm-project/issues/162451
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The canonicalize is also triggered when the `trunc` is `nuw`.

Proof: https://alive2.llvm.org/ce/z/eWvWe3
Fixes: https://github.com/llvm/llvm-project/issues/162451
</pre>
</div>
</content>
</entry>
<entry>
<title>[InstCombine] Fold icmp with clamp into unsigned bound check (#161303)</title>
<updated>2025-10-02T19:51:39+00:00</updated>
<author>
<name>Brandon</name>
<email>61314499+brandonxin@users.noreply.github.com</email>
</author>
<published>2025-10-02T19:51:39+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=11faf88d8fea4d221e826e4e9827864f38d246fb'/>
<id>11faf88d8fea4d221e826e4e9827864f38d246fb</id>
<content type='text'>
Fix #157315 

alive2: https://alive2.llvm.org/ce/z/TEnuFV

The equality comparison of `min(max(X, Lo), Hi)` and `X` is actually a
range check on `X`. This PR folds this into an unsigned bound check `(X
- Lo) u&lt; (Hi - Lo + 1)`.

---------

Co-authored-by: Yingwei Zheng &lt;dtcxzyw@qq.com&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Fix #157315 

alive2: https://alive2.llvm.org/ce/z/TEnuFV

The equality comparison of `min(max(X, Lo), Hi)` and `X` is actually a
range check on `X`. This PR folds this into an unsigned bound check `(X
- Lo) u&lt; (Hi - Lo + 1)`.

---------

Co-authored-by: Yingwei Zheng &lt;dtcxzyw@qq.com&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>[InstCombine] Fix FMF propagation in `foldFCmpFSubIntoFCmp` (#161539)</title>
<updated>2025-10-02T17:44:03+00:00</updated>
<author>
<name>Yingwei Zheng</name>
<email>dtcxzyw2333@gmail.com</email>
</author>
<published>2025-10-02T17:44:03+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=0b7129afccc8e79fb88bb686466211f3bcad142e'/>
<id>0b7129afccc8e79fb88bb686466211f3bcad142e</id>
<content type='text'>
Proof: https://alive2.llvm.org/ce/z/orSP-S
Closes https://github.com/llvm/llvm-project/issues/161525.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Proof: https://alive2.llvm.org/ce/z/orSP-S
Closes https://github.com/llvm/llvm-project/issues/161525.</pre>
</div>
</content>
</entry>
<entry>
<title>[PatternMatch] Introduce match functor (NFC) (#159386)</title>
<updated>2025-09-17T20:04:33+00:00</updated>
<author>
<name>Ramkumar Ramachandra</name>
<email>ramkumar.ramachandra@codasip.com</email>
</author>
<published>2025-09-17T20:04:33+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=7fb3a91418df61a81b1386eba3c29bc0df9e0787'/>
<id>7fb3a91418df61a81b1386eba3c29bc0df9e0787</id>
<content type='text'>
A common idiom is the usage of the PatternMatch match function within a
functional algorithm like all_of. Introduce a match functor to shorten
this idiom.

Co-authored-by: Luke Lau &lt;luke@igalia.com&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
A common idiom is the usage of the PatternMatch match function within a
functional algorithm like all_of. Introduce a match functor to shorten
this idiom.

Co-authored-by: Luke Lau &lt;luke@igalia.com&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>[InstCombine] Support GEP chains in foldCmpLoadFromIndexedGlobal() (#157447)</title>
<updated>2025-09-09T14:50:45+00:00</updated>
<author>
<name>Nikita Popov</name>
<email>npopov@redhat.com</email>
</author>
<published>2025-09-09T14:50:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=1cbb35e044e2902b049499116c93f98f9a30955e'/>
<id>1cbb35e044e2902b049499116c93f98f9a30955e</id>
<content type='text'>
Currently this fold only supports a single GEP. However, in ptradd
representation, it may be split across multiple GEPs. In particular, PR
#151333 will split off constant offset GEPs.

To support this, add a new helper decomposeLinearExpression(), which
decomposes a pointer into a linear expression of the form BasePtr +
Index * Scale + Offset.

I plan to also extend this helper to look through mul/shl on the index
and use it in more places that currently use collectOffset() to extract
a single index * scale. This will make sure such optimizations are not
affected by the ptradd migration.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Currently this fold only supports a single GEP. However, in ptradd
representation, it may be split across multiple GEPs. In particular, PR
#151333 will split off constant offset GEPs.

To support this, add a new helper decomposeLinearExpression(), which
decomposes a pointer into a linear expression of the form BasePtr +
Index * Scale + Offset.

I plan to also extend this helper to look through mul/shl on the index
and use it in more places that currently use collectOffset() to extract
a single index * scale. This will make sure such optimizations are not
affected by the ptradd migration.</pre>
</div>
</content>
</entry>
<entry>
<title>[InstCombine][VectorCombine][NFC] Unify uses of lossless inverse cast (#156597)</title>
<updated>2025-09-08T13:30:06+00:00</updated>
<author>
<name>Hongyu Chen</name>
<email>xxs_chy@outlook.com</email>
</author>
<published>2025-09-08T13:30:06+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=75b0c89e626f21e9ba9c920c878cc9e81471f4cf'/>
<id>75b0c89e626f21e9ba9c920c878cc9e81471f4cf</id>
<content type='text'>
This patch addresses
https://github.com/llvm/llvm-project/pull/155216#discussion_r2297724663.
This patch adds a helper function to put the inverse cast on constants,
with cast flags preserved(optional).
Follow-up patches will add trunc/ext handling on VectorCombine and flags
preservation on InstCombine.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This patch addresses
https://github.com/llvm/llvm-project/pull/155216#discussion_r2297724663.
This patch adds a helper function to put the inverse cast on constants,
with cast flags preserved(optional).
Follow-up patches will add trunc/ext handling on VectorCombine and flags
preservation on InstCombine.</pre>
</div>
</content>
</entry>
<entry>
<title>[InstCombine] Make foldCmpLoadFromIndexedGlobal() GEP-type independent (#157089)</title>
<updated>2025-09-08T10:54:24+00:00</updated>
<author>
<name>Nikita Popov</name>
<email>npopov@redhat.com</email>
</author>
<published>2025-09-08T10:54:24+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=305cf0e912529bfd847429f33ae09756aeb1813a'/>
<id>305cf0e912529bfd847429f33ae09756aeb1813a</id>
<content type='text'>
foldCmpLoadFromIndexedGlobal() currently checks that the global type,
the GEP type and the load type match in certain ways. Replace this with
generic logic based on offsets.

This is a reboot of https://github.com/llvm/llvm-project/pull/67093.
This PR is less ambitious by requiring that the constant offset is
smaller than the stride, which avoids the additional complexity of that
PR.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
foldCmpLoadFromIndexedGlobal() currently checks that the global type,
the GEP type and the load type match in certain ways. Replace this with
generic logic based on offsets.

This is a reboot of https://github.com/llvm/llvm-project/pull/67093.
This PR is less ambitious by requiring that the constant offset is
smaller than the stride, which avoids the additional complexity of that
PR.</pre>
</div>
</content>
</entry>
<entry>
<title>[InstCombine] Slightly optimize visitFcmp (NFC) (#156097)</title>
<updated>2025-08-31T15:48:56+00:00</updated>
<author>
<name>Seraphimt</name>
<email>svet58585@mail.ru</email>
</author>
<published>2025-08-31T15:48:56+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=9f620b8f62c4a0bdbf066c6f86ff9f38a6acd932'/>
<id>9f620b8f62c4a0bdbf066c6f86ff9f38a6acd932</id>
<content type='text'>
Studying the code related to float found a slightly optimal sequence of
actions.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Studying the code related to float found a slightly optimal sequence of
actions.</pre>
</div>
</content>
</entry>
</feed>
