<feed xmlns='http://www.w3.org/2005/Atom'>
<title>llvm-project.git/llvm/lib/Transforms/InstCombine, 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] Canonicalize signed saturated additions (#153053)</title>
<updated>2025-11-18T17:15:26+00:00</updated>
<author>
<name>AZero13</name>
<email>gfunni234@gmail.com</email>
</author>
<published>2025-11-18T17:15:26+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=58cffea94a31e52d6492ce7103e04c6b073dee16'/>
<id>58cffea94a31e52d6492ce7103e04c6b073dee16</id>
<content type='text'>
https://alive2.llvm.org/ce/z/YGT5SN
https://alive2.llvm.org/ce/z/PVDxCw
https://alive2.llvm.org/ce/z/8buR2N

This is tricky because with positive numbers, we only go up, so we can
in fact always hit the signed_max boundary. This is important because
the intrinsic we use has the behavior of going the OTHER way, aka clamp
to INT_MIN if it goes in that direction.

And the range checking we do only works for positive numbers.

Because of this issue, we can only do this for constants as well.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://alive2.llvm.org/ce/z/YGT5SN
https://alive2.llvm.org/ce/z/PVDxCw
https://alive2.llvm.org/ce/z/8buR2N

This is tricky because with positive numbers, we only go up, so we can
in fact always hit the signed_max boundary. This is important because
the intrinsic we use has the behavior of going the OTHER way, aka clamp
to INT_MIN if it goes in that direction.

And the range checking we do only works for positive numbers.

Because of this issue, we can only do this for constants as well.</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>[LLVM][InstCombine] not (bitcast (cmp A, B) --&gt; bitcast (!cmp A, B) (#167693)</title>
<updated>2025-11-13T11:47:12+00:00</updated>
<author>
<name>Paul Walker</name>
<email>paul.walker@arm.com</email>
</author>
<published>2025-11-13T11:47:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=f84ad4504dfba9df049296d451ec8da668e847a4'/>
<id>f84ad4504dfba9df049296d451ec8da668e847a4</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>[IR] "modular-format" attribute for functions using format strings (#147429)</title>
<updated>2025-11-11T19:52:56+00:00</updated>
<author>
<name>Daniel Thornburgh</name>
<email>dthorn@google.com</email>
</author>
<published>2025-11-11T19:52:56+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=c9ff2df8c3233dcb1d3e45039569dd1b9235ad52'/>
<id>c9ff2df8c3233dcb1d3e45039569dd1b9235ad52</id>
<content type='text'>
A new InstCombine transform uses this attribute to rewrite calls to a
modular version of the implementation along with llvm.reloc.none
relocations against aspects of the implementation needed by the call.

This change only adds support for the 'float' aspect, but it also builds
the structure needed for others.

See issue #146159</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
A new InstCombine transform uses this attribute to rewrite calls to a
modular version of the implementation along with llvm.reloc.none
relocations against aspects of the implementation needed by the call.

This change only adds support for the 'float' aspect, but it also builds
the structure needed for others.

See issue #146159</pre>
</div>
</content>
</entry>
<entry>
<title>[InstCombine] Don't sink if it would require dropping deref assumptions. (#166945)</title>
<updated>2025-11-09T21:08:46+00:00</updated>
<author>
<name>Florian Hahn</name>
<email>flo@fhahn.com</email>
</author>
<published>2025-11-09T21:08:46+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=700b77b5e5ca51fa18b954f062cb14edfc724b5d'/>
<id>700b77b5e5ca51fa18b954f062cb14edfc724b5d</id>
<content type='text'>
Currently sinking assumes in instcombine drops assumes if they would
prevent sinking. Removing dereferenceable assumptions earlier on can
inhibit vectorization of early-exit loops in practice.

Special-case deferenceable assumptions so that they block sinking. This
can be combined with a separate change to drop dereferencebale
assumptions after vectorization: https://clang.godbolt.org/z/jGqcx3sbs

PR: https://github.com/llvm/llvm-project/pull/166945

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Currently sinking assumes in instcombine drops assumes if they would
prevent sinking. Removing dereferenceable assumptions earlier on can
inhibit vectorization of early-exit loops in practice.

Special-case deferenceable assumptions so that they block sinking. This
can be combined with a separate change to drop dereferencebale
assumptions after vectorization: https://clang.godbolt.org/z/jGqcx3sbs

PR: https://github.com/llvm/llvm-project/pull/166945

</pre>
</div>
</content>
</entry>
<entry>
<title>[InstCombine] Fold operation into select, when one operand is zext of select's condition (#166816)</title>
<updated>2025-11-08T14:22:32+00:00</updated>
<author>
<name>Andreas Jonson</name>
<email>andjo403@hotmail.com</email>
</author>
<published>2025-11-08T14:22:32+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=b9ea93cd5c37fb6d606502fd01208dd48330549d'/>
<id>b9ea93cd5c37fb6d606502fd01208dd48330549d</id>
<content type='text'>
Proof https://alive2.llvm.org/ce/z/oCQyTG
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Proof https://alive2.llvm.org/ce/z/oCQyTG
</pre>
</div>
</content>
</entry>
<entry>
<title>[ProfCheck][NFC] Make Function argument from branch weight setter optional (#166032)</title>
<updated>2025-11-05T15:40:37+00:00</updated>
<author>
<name>Mircea Trofin</name>
<email>mtrofin@google.com</email>
</author>
<published>2025-11-05T15:40:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=52cb6e9d49f836b624bd0536734afd7aa4194ca0'/>
<id>52cb6e9d49f836b624bd0536734afd7aa4194ca0</id>
<content type='text'>
This picks up from #166028, making the `Function` argument optional:
most cases don't need to provide it, but in e.g. InstCombine's case,
where the instruction (select, branch) is not attached to a function
yet, the function needs to be passed explicitly.

Co-authored-by: Florian Hahn &lt;flo@fhahn.com&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This picks up from #166028, making the `Function` argument optional:
most cases don't need to provide it, but in e.g. InstCombine's case,
where the instruction (select, branch) is not attached to a function
yet, the function needs to be passed explicitly.

Co-authored-by: Florian Hahn &lt;flo@fhahn.com&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>[InstCombine] Enable FoldOpIntoSelect and foldOpIntoPhi when the Op's other parameter is non-const (#166102)</title>
<updated>2025-11-05T09:04:32+00:00</updated>
<author>
<name>Gábor Spaits</name>
<email>gaborspaits1@gmail.com</email>
</author>
<published>2025-11-05T09:04:32+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=628d53aba53204b8b7eac69b200b04bc4433deac'/>
<id>628d53aba53204b8b7eac69b200b04bc4433deac</id>
<content type='text'>
This patch enables `FoldOpIntoSelect` and `foldOpIntoPhi` for the cases
when Op's second parameter is a non-constant.
It doesn't seem to bring significant improvements, but the compile
time impact is neglegable.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This patch enables `FoldOpIntoSelect` and `foldOpIntoPhi` for the cases
when Op's second parameter is a non-constant.
It doesn't seem to bring significant improvements, but the compile
time impact is neglegable.</pre>
</div>
</content>
</entry>
<entry>
<title>[profcheck][InstCombine] Preserve branch weights in logical identities (#165810)</title>
<updated>2025-11-03T17:32:42+00:00</updated>
<author>
<name>Alan Zhao</name>
<email>ayzhao@google.com</email>
</author>
<published>2025-11-03T17:32:42+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=c4763e2b9038fbd1154f0276a8b9542b8c115111'/>
<id>c4763e2b9038fbd1154f0276a8b9542b8c115111</id>
<content type='text'>
For the simplification
```
(C &amp;&amp; A) || (!C &amp;&amp; B) --&gt; sel C, A, B
```
(and related), if `C` (or (`!C`)) is the condition in the select
instruction representing the logical and, we can preserve that logical
and's branch weights when emitting the new instruction. Otherwise, the
profile data is unknown.

If `C` is the condition of both logical ands, then we just take the
branch weights of the first logical and (though in practice they should
be equal.)

Furthermore, `select-safe-transforms.ii` now passes under the profcheck
configuration, so we remove it from the failing tests.

Tracking issue: #147390</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
For the simplification
```
(C &amp;&amp; A) || (!C &amp;&amp; B) --&gt; sel C, A, B
```
(and related), if `C` (or (`!C`)) is the condition in the select
instruction representing the logical and, we can preserve that logical
and's branch weights when emitting the new instruction. Otherwise, the
profile data is unknown.

If `C` is the condition of both logical ands, then we just take the
branch weights of the first logical and (though in practice they should
be equal.)

Furthermore, `select-safe-transforms.ii` now passes under the profcheck
configuration, so we remove it from the failing tests.

Tracking issue: #147390</pre>
</div>
</content>
</entry>
</feed>
