This is an archive of the discontinued LLVM Phabricator instance.

Reland [ValueTracking] Improve the coverage of isKnownToBeAPowerOfTwo for vscale
AbandonedPublic

Authored by Allen on Aug 7 2023, 8:39 AM.

Details

Summary

The previous commit 9c837b7d0e2e don't check the type width,
so the logic is incorrect because a shift left of vscale can be zero
if all bits get shifted out.

This PR add condition to check above issue.

Diff Detail

Event Timeline

Allen created this revision.Aug 7 2023, 8:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 7 2023, 8:39 AM
Allen requested review of this revision.Aug 7 2023, 8:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 7 2023, 8:39 AM
nikic added a comment.EditedAug 7 2023, 8:57 AM

Given the lack of test changes, do we need this? Presumably https://github.com/llvm/llvm-project/commit/5de89b4d99c913e3c7c2735886f2519a2ed39d8a already covered the motivating cases.

Edit: To clarify, we do need to remove the incorrect code, the question is more about whether we need the new code this introduces.

Allen updated this revision to Diff 547811.Aug 7 2023, 8:59 AM
Allen retitled this revision from [ValueTracking] Fix the correct of isKnownToBeAPowerOfTwo to Reland [ValueTracking] Improve the coverage of isKnownToBeAPowerOfTwo for vscale.
Allen edited the summary of this revision. (Show Details)

rebase after revert of f6c726472df1

Allen added a comment.Aug 7 2023, 9:08 AM

In my local test, there is some failure tests after the revert of f6c726472df1, and this PR can fix them

LLVM :: Transforms/InstCombine/rem-mul-shl.ll
LLVM :: Transforms/LoopVectorize/AArch64/sve-interleaved-accesses.ll
LLVM :: Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
nikic added a comment.Aug 7 2023, 9:19 AM

I don't get any failures for check-llvm on current main, which includes the revert.

I don't get any failures for check-llvm on current main, which includes the revert.

Likewise.

goldstein.w.n added inline comments.Aug 7 2023, 9:45 AM
llvm/lib/Analysis/ValueTracking.cpp
2028

More robust would be to match shift as a value and use ComputeKnownBits to get max shift cnt.

2031

If we have OrZero don't need the extra logic.

2035

Keep these as APInt to avoid overflow / handle abnormal types like i128

Allen added a comment.Aug 7 2023, 6:04 PM

oh, I find the commit 5de89b4d99c9 already fixed, thanks @goldstein.w.n and @nikic, so this is not necessary

Allen abandoned this revision.Aug 7 2023, 6:05 PM