<feed xmlns='http://www.w3.org/2005/Atom'>
<title>llvm-project.git/llvm/lib/Analysis/InstructionSimplify.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>[InstSimplify] Extend icmp-of-add simplification to sle/sgt/sge (#168900)</title>
<updated>2025-11-20T21:35:14+00:00</updated>
<author>
<name>Pedro Lobo</name>
<email>pedro.lobo@tecnico.ulisboa.pt</email>
</author>
<published>2025-11-20T21:35:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=76d614b7c1222f459d42c6cfdf619da19ac3f739'/>
<id>76d614b7c1222f459d42c6cfdf619da19ac3f739</id>
<content type='text'>
When comparing additions with the same base where one has `nsw`, the
following simplification can be performed:

```llvm
icmp slt/sgt/sle/sge (x + C1), (x +nsw C2)
=&gt;
icmp slt/sgt/sle/sge C1, C2
```

Previously this was only done for `slt`. This patch extends it to the
`sgt`, `sle`, and `sge` predicates when either of the conditions hold:
- `C1 &lt;= C2 &amp;&amp; C1 &gt;= 0`, or
- `C2 &lt;= C1 &amp;&amp; C1 &lt;= 0`

This patch also handles the `C1 == C2` case, which was previously
excluded.

Proof: https://alive2.llvm.org/ce/z/LtmY4f</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When comparing additions with the same base where one has `nsw`, the
following simplification can be performed:

```llvm
icmp slt/sgt/sle/sge (x + C1), (x +nsw C2)
=&gt;
icmp slt/sgt/sle/sge C1, C2
```

Previously this was only done for `slt`. This patch extends it to the
`sgt`, `sle`, and `sge` predicates when either of the conditions hold:
- `C1 &lt;= C2 &amp;&amp; C1 &gt;= 0`, or
- `C2 &lt;= C1 &amp;&amp; C1 &lt;= 0`

This patch also handles the `C1 == C2` case, which was previously
excluded.

Proof: https://alive2.llvm.org/ce/z/LtmY4f</pre>
</div>
</content>
</entry>
<entry>
<title>[LLVM][InstSimplify] Add folds for SVE integer reduction intrinsics. (#167519)</title>
<updated>2025-11-18T14:33:43+00:00</updated>
<author>
<name>Paul Walker</name>
<email>paul.walker@arm.com</email>
</author>
<published>2025-11-18T14:33:43+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=f2b5d04f2968727270a9d9368c6a4222bbebf12c'/>
<id>f2b5d04f2968727270a9d9368c6a4222bbebf12c</id>
<content type='text'>
[andv, eorv, orv, s/uaddv, s/umaxv, s/uminv]
sve_reduce_##(none, ?) -&gt; op's neutral value
sve_reduce_##(any, neutral) -&gt; op's neutral value
    
[andv, orv, s/umaxv, s/uminv]
sve_reduce_##(all, splat(X)) -&gt; X
    
[eorv]
sve_reduce_##(all, splat(X)) -&gt; 0</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[andv, eorv, orv, s/uaddv, s/umaxv, s/uminv]
sve_reduce_##(none, ?) -&gt; op's neutral value
sve_reduce_##(any, neutral) -&gt; op's neutral value
    
[andv, orv, s/umaxv, s/uminv]
sve_reduce_##(all, splat(X)) -&gt; X
    
[eorv]
sve_reduce_##(all, splat(X)) -&gt; 0</pre>
</div>
</content>
</entry>
<entry>
<title>[InstSimplify] Fix crash when optimizing minmax with bitcast constant vectors (#168055)</title>
<updated>2025-11-14T19:05:30+00:00</updated>
<author>
<name>Igor Gorban</name>
<email>igor.gorban@intel.com</email>
</author>
<published>2025-11-14T19:05:30+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=dd7a000a3114543d58786bbfb84870446034e767'/>
<id>dd7a000a3114543d58786bbfb84870446034e767</id>
<content type='text'>
When simplifying min/max intrinsics with fixed-size vector constants,
InstructionSimplify attempts to optimize element-wise. However,
getAggregateElement() can return null for certain constant expressions
like bitcasts, leading to a null pointer dereference.

This patch adds a check to bail out of the optimization when
getAggregateElement() returns null, preventing the crash while
maintaining correct behavior for normal constant vectors.

Fixes crash with patterns like:
  call &lt;2 x half&gt; @llvm.minnum.v2f16(&lt;2 x half&gt; %x,
&lt;2 x half&gt; bitcast (&lt;1 x i32&gt; &lt;i32 N&gt; to &lt;2 x half&gt;))</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When simplifying min/max intrinsics with fixed-size vector constants,
InstructionSimplify attempts to optimize element-wise. However,
getAggregateElement() can return null for certain constant expressions
like bitcasts, leading to a null pointer dereference.

This patch adds a check to bail out of the optimization when
getAggregateElement() returns null, preventing the crash while
maintaining correct behavior for normal constant vectors.

Fixes crash with patterns like:
  call &lt;2 x half&gt; @llvm.minnum.v2f16(&lt;2 x half&gt; %x,
&lt;2 x half&gt; bitcast (&lt;1 x i32&gt; &lt;i32 N&gt; to &lt;2 x half&gt;))</pre>
</div>
</content>
</entry>
<entry>
<title>Reland "[InstructionSimplify] Enhance simplifySelectInst() (#163453)" (#164694)</title>
<updated>2025-10-26T04:39:49+00:00</updated>
<author>
<name>Congzhe</name>
<email>congzhe.cao@huawei.com</email>
</author>
<published>2025-10-26T04:39:49+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=e246fffb253c3ed9a2c0b4a71ef33d97c7b5629c'/>
<id>e246fffb253c3ed9a2c0b4a71ef33d97c7b5629c</id>
<content type='text'>
This reverts commit f1c1063.

PR #163453 was merged and reverted since it exposed a crash. 
After investigation the crash was unrelated and is then fixed in #164628.

This is an attempt to reland #163453.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This reverts commit f1c1063.

PR #163453 was merged and reverted since it exposed a crash. 
After investigation the crash was unrelated and is then fixed in #164628.

This is an attempt to reland #163453.</pre>
</div>
</content>
</entry>
<entry>
<title>Revert "[InstCombinePHI] Enhance PHI CSE to remove redundant phis" (#164520)</title>
<updated>2025-10-22T08:51:10+00:00</updated>
<author>
<name>Arthur Eubanks</name>
<email>aeubanks@google.com</email>
</author>
<published>2025-10-22T08:51:10+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=f1c1063acb12c7ce7724a88bf93351dd76b561c4'/>
<id>f1c1063acb12c7ce7724a88bf93351dd76b561c4</id>
<content type='text'>
Reverts llvm/llvm-project#163453

Causes crashes, see
https://github.com/llvm/llvm-project/pull/163453#issuecomment-3429922732</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Reverts llvm/llvm-project#163453

Causes crashes, see
https://github.com/llvm/llvm-project/pull/163453#issuecomment-3429922732</pre>
</div>
</content>
</entry>
<entry>
<title>[InstructionSimplify] Enhance simplifySelectInst() (#163453)</title>
<updated>2025-10-21T20:12:26+00:00</updated>
<author>
<name>Congzhe</name>
<email>congzhe.cao@huawei.com</email>
</author>
<published>2025-10-21T20:12:26+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=9a9fbbba5c81efed72c08a70bbe58427190d69db'/>
<id>9a9fbbba5c81efed72c08a70bbe58427190d69db</id>
<content type='text'>
Fold select instructions with true and false values that act as the same 
phi, which cleans up the IR and open up opportunities for other passes 
such as loop vectorization.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Fold select instructions with true and false values that act as the same 
phi, which cleans up the IR and open up opportunities for other passes 
such as loop vectorization.</pre>
</div>
</content>
</entry>
<entry>
<title>[InstSimplify] Support ptrtoaddr in simplifyGEPInst() (#164262)</title>
<updated>2025-10-21T07:27:07+00:00</updated>
<author>
<name>Nikita Popov</name>
<email>npopov@redhat.com</email>
</author>
<published>2025-10-21T07:27:07+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=ec26f219acce77fb9b3d52abd31b0e639e788514'/>
<id>ec26f219acce77fb9b3d52abd31b0e639e788514</id>
<content type='text'>
This adds support for ptrtoaddr in the `ptradd p, ptrtoaddr(p2) -
ptrtoaddr(p) -&gt; p2` fold.

This fold requires that p and p2 have the same underlying object
(otherwise the provenance may not be the same).

The argument I would like to make here is that because the underlying
objects are the same (and the pointers in the same address space), the
non-address bits of the pointer must be the same. Looking at some
specific cases of underlying object relationship:

 * phi/select: Trivially true.
* getelementptr: Only modifies address bits, non-address bits must
remain the same.
* addrspacecast round-trip cast: Must preserve all bits because we
optimize such round-trip casts away.
* non-interposable global alias: I'm a bit unsure about this one, but I
guess the alias and the aliasee must have the same non-address bits?
* various intrinsics like launder.invariant.group, ptrmask. I think
these all either preserve all pointer bits (like the invariant.group
ones) or at least the non-address bits (like ptrmask). There are some
interesting cases like amdgcn.make.buffer.rsrc, but those are cross
address-space.

-----

There is a second `gep (gep p, C), (sub 0, ptrtoint(p)) -&gt; C` transform
in this function, which I am not extending to handle ptrtoaddr, adding
negative tests instead. This transform is overall dubious for provenance
reasons, but especially dubious with ptrtoaddr, as then we don't have
the guarantee that provenance of `p` has been exposed.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This adds support for ptrtoaddr in the `ptradd p, ptrtoaddr(p2) -
ptrtoaddr(p) -&gt; p2` fold.

This fold requires that p and p2 have the same underlying object
(otherwise the provenance may not be the same).

The argument I would like to make here is that because the underlying
objects are the same (and the pointers in the same address space), the
non-address bits of the pointer must be the same. Looking at some
specific cases of underlying object relationship:

 * phi/select: Trivially true.
* getelementptr: Only modifies address bits, non-address bits must
remain the same.
* addrspacecast round-trip cast: Must preserve all bits because we
optimize such round-trip casts away.
* non-interposable global alias: I'm a bit unsure about this one, but I
guess the alias and the aliasee must have the same non-address bits?
* various intrinsics like launder.invariant.group, ptrmask. I think
these all either preserve all pointer bits (like the invariant.group
ones) or at least the non-address bits (like ptrmask). There are some
interesting cases like amdgcn.make.buffer.rsrc, but those are cross
address-space.

-----

There is a second `gep (gep p, C), (sub 0, ptrtoint(p)) -&gt; C` transform
in this function, which I am not extending to handle ptrtoaddr, adding
negative tests instead. This transform is overall dubious for provenance
reasons, but especially dubious with ptrtoaddr, as then we don't have
the guarantee that provenance of `p` has been exposed.</pre>
</div>
</content>
</entry>
<entry>
<title>[InstSimplify] Support ptrtoaddr in simplifyCastInst()</title>
<updated>2025-10-20T12:18:34+00:00</updated>
<author>
<name>Nikita Popov</name>
<email>npopov@redhat.com</email>
</author>
<published>2025-10-10T12:57:07+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=ee50839700af4800a2d72702a5583b72e1ffb81e'/>
<id>ee50839700af4800a2d72702a5583b72e1ffb81e</id>
<content type='text'>
Handle ptrtoaddr the same way as ptrtoint. The fold already only
operates on the index/address bits.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Handle ptrtoaddr the same way as ptrtoint. The fold already only
operates on the index/address bits.
</pre>
</div>
</content>
</entry>
<entry>
<title>[IR] Replace alignment argument with attribute on masked intrinsics (#163802)</title>
<updated>2025-10-20T08:50:09+00:00</updated>
<author>
<name>Nikita Popov</name>
<email>npopov@redhat.com</email>
</author>
<published>2025-10-20T08:50:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=573ca36753e9141f25b941ea9a84d0599e3baae7'/>
<id>573ca36753e9141f25b941ea9a84d0599e3baae7</id>
<content type='text'>
The `masked.load`, `masked.store`, `masked.gather` and `masked.scatter`
intrinsics currently accept a separate alignment immarg. Replace this
with an `align` attribute on the pointer / vector of pointers argument.

This is the standard representation for alignment information on
intrinsics, and is already used by all other memory intrinsics. This
means the signatures now match llvm.expandload, llvm.vp.load, etc.
(Things like llvm.memcpy used to have a separate alignment argument as
well, but were already migrated a long time ago.)

It's worth noting that the masked.gather and masked.scatter intrinsics
previously accepted a zero alignment to indicate the ABI type alignment
of the element type. This special case is gone now: If the align
attribute is omitted, the implied alignment is 1, as usual. If ABI
alignment is desired, it needs to be explicitly emitted (which the
IRBuilder API already requires anyway).</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The `masked.load`, `masked.store`, `masked.gather` and `masked.scatter`
intrinsics currently accept a separate alignment immarg. Replace this
with an `align` attribute on the pointer / vector of pointers argument.

This is the standard representation for alignment information on
intrinsics, and is already used by all other memory intrinsics. This
means the signatures now match llvm.expandload, llvm.vp.load, etc.
(Things like llvm.memcpy used to have a separate alignment argument as
well, but were already migrated a long time ago.)

It's worth noting that the masked.gather and masked.scatter intrinsics
previously accepted a zero alignment to indicate the ABI type alignment
of the element type. This special case is gone now: If the align
attribute is omitted, the implied alignment is 1, as usual. If ABI
alignment is desired, it needs to be explicitly emitted (which the
IRBuilder API already requires anyway).</pre>
</div>
</content>
</entry>
<entry>
<title>[InstSimplify] Support ptrtoaddr in ptrmask fold</title>
<updated>2025-10-14T11:55:04+00:00</updated>
<author>
<name>Nikita Popov</name>
<email>npopov@redhat.com</email>
</author>
<published>2025-10-14T11:53:07+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=cf3765752b3669eb6efba00379b95c79b86b272d'/>
<id>cf3765752b3669eb6efba00379b95c79b86b272d</id>
<content type='text'>
Treat it the same way as ptrtoint. ptrmask only operates on the
address bits of the pointer.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Treat it the same way as ptrtoint. ptrmask only operates on the
address bits of the pointer.
</pre>
</div>
</content>
</entry>
</feed>
