[PATCH] D156881: [InstSimplify] Check the NonZero for power of two value
Allen zhong via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 3 15:59:22 PDT 2023
Allen marked an inline comment as done.
Allen added inline comments.
================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:2022
+ if (Q.CxtI &&
+ (match(V, m_VScale()) || match(V, m_Shl(m_VScale(), m_Value())))) {
const Function *F = Q.CxtI->getFunction();
----------------
goldstein.w.n wrote:
> Allen wrote:
> > goldstein.w.n wrote:
> > > What is this change for? Is this part of the bugfix?
> > Yes. This is similar to the following logic in line 2045.
> > ```
> > // A shift left or a logical shift right of a power of two is a power of two
> > // or zero.
> > if (OrZero && (match(V, m_Shl(m_Value(X), m_Value())) ||
> > match(V, m_LShr(m_Value(X), m_Value()))))
> > return isKnownToBeAPowerOfTwo(X, /*OrZero*/ true, Depth, Q);
> > ```
> >
> > This is try to match following code, because we can assume the vscale always bigger than 1, and it is a power of 2 if it has the attribute of vscale_range
> > ```
> > %vscale = call i64 @llvm.vscale.i64()
> > %shift = shl nuw nsw i64 %vscale, 11
> > ```
> >
> >
> >
> But is it related to making the existing codes correct or just improving the coverage? I don't see how its related to the bug. If its not related to the bug, imo it should be split to a seperate patch.
Thanks very much again. I'll seperate this patch before landing.
This change is necessary to match the following code.
otherwise the case **and_add_shl_vscale_not_power2_negative** will don't have a chance to fold the return value because we only check the **shl ** recursively when the **OrZero** is true now.
```
%vscale = call i64 @llvm.vscale.i64()
%shift = shl nuw nsw i64 %vscale, 11
```
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156881/new/
https://reviews.llvm.org/D156881
More information about the llvm-commits
mailing list