<feed xmlns='http://www.w3.org/2005/Atom'>
<title>llvm-project.git/llvm/test/Transforms/InstSimplify/div.ll, 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>[LLVM][IR] Use splat syntax when printing Constant[Data]Vector. (#112548)</title>
<updated>2024-11-06T11:53:33+00:00</updated>
<author>
<name>Paul Walker</name>
<email>paul.walker@arm.com</email>
</author>
<published>2024-11-06T11:53:33+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=38fffa630ee80163dc65e759392ad29798905679'/>
<id>38fffa630ee80163dc65e759392ad29798905679</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>[InstSimplify][InstCombine][ConstantFold] Move vector div/rem by zero fold to InstCombine (#114280)</title>
<updated>2024-11-01T14:56:22+00:00</updated>
<author>
<name>Yingwei Zheng</name>
<email>dtcxzyw2333@gmail.com</email>
</author>
<published>2024-11-01T14:56:22+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=a77dedcacb4c5eb221395b69877981dd6ad98989'/>
<id>a77dedcacb4c5eb221395b69877981dd6ad98989</id>
<content type='text'>
Previously we fold `div/rem X, C` into `poison` if any element of the
constant divisor `C` is zero or undef. However, it is incorrect when
threading udiv over an vector select:
https://alive2.llvm.org/ce/z/3Ninx5
```
define &lt;2 x i32&gt; @vec_select_udiv_poison(&lt;2 x i1&gt; %x) {
  %sel = select &lt;2 x i1&gt; %x, &lt;2 x i32&gt; &lt;i32 -1, i32 -1&gt;, &lt;2 x i32&gt; &lt;i32 0, i32 1&gt;
  %div = udiv &lt;2 x i32&gt; &lt;i32 42, i32 -7&gt;, %sel
  ret &lt;2 x i32&gt; %div
}
```
In this case, `threadBinOpOverSelect` folds `udiv &lt;i32 42, i32 -7&gt;, &lt;i32
-1, i32 -1&gt;` and `udiv &lt;i32 42, i32 -7&gt;, &lt;i32 0, i32 1&gt;` into
`zeroinitializer` and `poison`, respectively. One solution is to
introduce a new flag indicating that we are threading over a vector
select. But it requires to modify both `InstSimplify` and
`ConstantFold`.

However, this optimization doesn't provide benefits to real-world
programs:

https://dtcxzyw.github.io/llvm-opt-benchmark/coverage/data/zyw/opt-ci/actions-runner/_work/llvm-opt-benchmark/llvm-opt-benchmark/llvm/llvm-project/llvm/lib/IR/ConstantFold.cpp.html#L908

https://dtcxzyw.github.io/llvm-opt-benchmark/coverage/data/zyw/opt-ci/actions-runner/_work/llvm-opt-benchmark/llvm-opt-benchmark/llvm/llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp.html#L1107

This patch moves the fold into InstCombine to avoid breaking numerous
existing tests.

Fixes #114191 and #113866 (only poison-safety issue).</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Previously we fold `div/rem X, C` into `poison` if any element of the
constant divisor `C` is zero or undef. However, it is incorrect when
threading udiv over an vector select:
https://alive2.llvm.org/ce/z/3Ninx5
```
define &lt;2 x i32&gt; @vec_select_udiv_poison(&lt;2 x i1&gt; %x) {
  %sel = select &lt;2 x i1&gt; %x, &lt;2 x i32&gt; &lt;i32 -1, i32 -1&gt;, &lt;2 x i32&gt; &lt;i32 0, i32 1&gt;
  %div = udiv &lt;2 x i32&gt; &lt;i32 42, i32 -7&gt;, %sel
  ret &lt;2 x i32&gt; %div
}
```
In this case, `threadBinOpOverSelect` folds `udiv &lt;i32 42, i32 -7&gt;, &lt;i32
-1, i32 -1&gt;` and `udiv &lt;i32 42, i32 -7&gt;, &lt;i32 0, i32 1&gt;` into
`zeroinitializer` and `poison`, respectively. One solution is to
introduce a new flag indicating that we are threading over a vector
select. But it requires to modify both `InstSimplify` and
`ConstantFold`.

However, this optimization doesn't provide benefits to real-world
programs:

https://dtcxzyw.github.io/llvm-opt-benchmark/coverage/data/zyw/opt-ci/actions-runner/_work/llvm-opt-benchmark/llvm-opt-benchmark/llvm/llvm-project/llvm/lib/IR/ConstantFold.cpp.html#L908

https://dtcxzyw.github.io/llvm-opt-benchmark/coverage/data/zyw/opt-ci/actions-runner/_work/llvm-opt-benchmark/llvm-opt-benchmark/llvm/llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp.html#L1107

This patch moves the fold into InstCombine to avoid breaking numerous
existing tests.

Fixes #114191 and #113866 (only poison-safety issue).</pre>
</div>
</content>
</entry>
<entry>
<title>[PatternMatch] Do not accept undef elements in m_AllOnes() and friends (#88217)</title>
<updated>2024-04-17T09:22:05+00:00</updated>
<author>
<name>Nikita Popov</name>
<email>npopov@redhat.com</email>
</author>
<published>2024-04-17T09:22:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=d9a5aa8e2d755643cf4e7fa86aa831ed226fe54d'/>
<id>d9a5aa8e2d755643cf4e7fa86aa831ed226fe54d</id>
<content type='text'>
Change all the cstval_pred_ty based PatternMatch helpers (things like
m_AllOnes and m_Zero) to only allow poison elements inside vector
splats, not undef elements.

Historically, we used to represent non-demanded elements in vectors
using undef. Nowadays, we use poison instead. As such, I believe that
support for undef in vector splats is no longer useful.

At the same time, while poison splat elements are pretty much always
safe to ignore, this is not generally the case for undef elements. We
have existing miscompiles in our tests due to this (see the
masked-merge-*.ll tests changed here) and it's easy to miss such cases
in the future, now that we write tests using poison instead of undef
elements.

I think overall, keeping support for undef elements no longer makes
sense, and we should drop it. Once this is done consistently, I think we
may also consider allowing poison in m_APInt by default, as doing that
change is much less risky than doing the same with undef.

This change involves a substantial amount of test changes. For most
tests, I've just replaced undef with poison, as I don't think there is
value in retaining both. For some tests (where the distinction between
undef and poison is important), I've duplicated tests.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Change all the cstval_pred_ty based PatternMatch helpers (things like
m_AllOnes and m_Zero) to only allow poison elements inside vector
splats, not undef elements.

Historically, we used to represent non-demanded elements in vectors
using undef. Nowadays, we use poison instead. As such, I believe that
support for undef in vector splats is no longer useful.

At the same time, while poison splat elements are pretty much always
safe to ignore, this is not generally the case for undef elements. We
have existing miscompiles in our tests due to this (see the
masked-merge-*.ll tests changed here) and it's easy to miss such cases
in the future, now that we write tests using poison instead of undef
elements.

I think overall, keeping support for undef elements no longer makes
sense, and we should drop it. Once this is done consistently, I think we
may also consider allowing poison in m_APInt by default, as doing that
change is much less risky than doing the same with undef.

This change involves a substantial amount of test changes. For most
tests, I've just replaced undef with poison, as I don't think there is
value in retaining both. For some tests (where the distinction between
undef and poison is important), I've duplicated tests.</pre>
</div>
</content>
</entry>
<entry>
<title>[InstSimplify] Fold `u/sdiv exact (mul nsw/nuw X, C), C --&gt; X` when C is not a power of 2 (#76445)</title>
<updated>2023-12-28T09:36:25+00:00</updated>
<author>
<name>Yingwei Zheng</name>
<email>dtcxzyw2333@gmail.com</email>
</author>
<published>2023-12-28T09:36:25+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=8a4266a626914765c0c69839e8a51be383013c1a'/>
<id>8a4266a626914765c0c69839e8a51be383013c1a</id>
<content type='text'>
Alive2: https://alive2.llvm.org/ce/z/3D9R7d</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Alive2: https://alive2.llvm.org/ce/z/3D9R7d</pre>
</div>
</content>
</entry>
<entry>
<title>[InstSimplify] sdiv a (1 srem b) --&gt; a</title>
<updated>2023-04-24T12:37:07+00:00</updated>
<author>
<name>Siyuan Zhu</name>
<email>timeorange7071@outlook.com</email>
</author>
<published>2023-04-24T12:29:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=946b32680311f43a349d0199f9e286f385cd9847'/>
<id>946b32680311f43a349d0199f9e286f385cd9847</id>
<content type='text'>
Extend the existing fold for division by zero or one to use known
bits, so it catches additional patterns like division by
(1 srem b).

Fixes https://github.com/llvm/llvm-project/issues/62163.

Differential Revision: https://reviews.llvm.org/D149001
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Extend the existing fold for division by zero or one to use known
bits, so it catches additional patterns like division by
(1 srem b).

Fixes https://github.com/llvm/llvm-project/issues/62163.

Differential Revision: https://reviews.llvm.org/D149001
</pre>
</div>
</content>
</entry>
<entry>
<title>[InstSimplify] Test case for D149001 (NFC)</title>
<updated>2023-04-24T12:28:41+00:00</updated>
<author>
<name>Siyuan Zhu</name>
<email>timeorange7071@outlook.com</email>
</author>
<published>2023-04-24T12:28:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=2eb72fa9172f99658ef8968ca66129463f360b14'/>
<id>2eb72fa9172f99658ef8968ca66129463f360b14</id>
<content type='text'>
Differential Revision: https://reviews.llvm.org/D149012
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Differential Revision: https://reviews.llvm.org/D149012
</pre>
</div>
</content>
</entry>
<entry>
<title>[InstSimplify] fold exact divide to poison if it is known to not divide evenly</title>
<updated>2022-12-29T15:26:50+00:00</updated>
<author>
<name>Sanjay Patel</name>
<email>spatel@rotateright.com</email>
</author>
<published>2022-12-29T14:55:59+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=f0faea571403eb75a1d2d0dceca1dd52a7824d33'/>
<id>f0faea571403eb75a1d2d0dceca1dd52a7824d33</id>
<content type='text'>
This is related to the discussion in D140665. I was looking over the demanded
bits implementation in IR and noticed that we just bail out of a potential
fold if a udiv is exact:
https://github.com/llvm/llvm-project/blob/82be8a1d2b00f6e89096b86f670a8be894c7b9e6/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp#L799

Also, see tests added with 7f0c11509e8f.

Then, I saw that we could lose a fold to poison if we zap the exact with that
transform, so this patch tries to catch that as a preliminary step.

Alive2 proofs:
https://alive2.llvm.org/ce/z/zCjKM7
https://alive2.llvm.org/ce/z/-tz_RK (trailing zeros must be "less-than")
https://alive2.llvm.org/ce/z/c9CMsJ (general proof and specific example)

Differential Revision: https://reviews.llvm.org/D140733
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This is related to the discussion in D140665. I was looking over the demanded
bits implementation in IR and noticed that we just bail out of a potential
fold if a udiv is exact:
https://github.com/llvm/llvm-project/blob/82be8a1d2b00f6e89096b86f670a8be894c7b9e6/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp#L799

Also, see tests added with 7f0c11509e8f.

Then, I saw that we could lose a fold to poison if we zap the exact with that
transform, so this patch tries to catch that as a preliminary step.

Alive2 proofs:
https://alive2.llvm.org/ce/z/zCjKM7
https://alive2.llvm.org/ce/z/-tz_RK (trailing zeros must be "less-than")
https://alive2.llvm.org/ce/z/c9CMsJ (general proof and specific example)

Differential Revision: https://reviews.llvm.org/D140733
</pre>
</div>
</content>
</entry>
<entry>
<title>[InstSimplify] add tests for div exact; NFC</title>
<updated>2022-12-28T19:08:47+00:00</updated>
<author>
<name>Sanjay Patel</name>
<email>spatel@rotateright.com</email>
</author>
<published>2022-12-28T17:06:57+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=935a6525e4fada4a969f53f0760d129699c6210c'/>
<id>935a6525e4fada4a969f53f0760d129699c6210c</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>[ConstFold] Salvage some div/rem folding test (NFC)</title>
<updated>2022-07-06T08:03:03+00:00</updated>
<author>
<name>Nikita Popov</name>
<email>npopov@redhat.com</email>
</author>
<published>2022-07-06T08:01:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=02b38ba8aa6ea32be5198849fff93929a117afe6'/>
<id>02b38ba8aa6ea32be5198849fff93929a117afe6</id>
<content type='text'>
The div/rem constant expressions are going away in D129148. Convert
some tests to use InstSimplify instead, to show that the constant
folding still happens.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The div/rem constant expressions are going away in D129148. Convert
some tests to use InstSimplify instead, to show that the constant
folding still happens.
</pre>
</div>
</content>
</entry>
<entry>
<title>[test] Use -passes=instsimplify instead of -instsimplify in a number of tests. NFC</title>
<updated>2022-02-07T13:26:58+00:00</updated>
<author>
<name>Bjorn Pettersson</name>
<email>bjorn.a.pettersson@ericsson.com</email>
</author>
<published>2022-02-04T10:45:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=b280ee1dd7e9b36ae7aaa3953556e4b7a7f31a29'/>
<id>b280ee1dd7e9b36ae7aaa3953556e4b7a7f31a29</id>
<content type='text'>
Another step moving away from the deprecated syntax of specifying
pass pipeline in opt.

Differential Revision: https://reviews.llvm.org/D119080
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Another step moving away from the deprecated syntax of specifying
pass pipeline in opt.

Differential Revision: https://reviews.llvm.org/D119080
</pre>
</div>
</content>
</entry>
</feed>
