This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Added a utility method that raising the number 2 to the desired power to SCEV
ClosedPublic

Authored by dbakunevich on Feb 20 2023, 4:26 AM.

Details

Summary

The new function has been added to SCEV that allows
to raise the number 2 to the desired power.

Diff Detail

Event Timeline

dbakunevich created this revision.Feb 20 2023, 4:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 20 2023, 4:26 AM
dbakunevich requested review of this revision.Feb 20 2023, 4:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 20 2023, 4:26 AM
mkazantsev requested changes to this revision.Feb 20 2023, 9:55 PM

Please write a more reasonable patch name

llvm/include/llvm/Analysis/ScalarEvolution.h
659
  1. Degree -> Power
  2. Does it really have to be long long? I mean, it's neither signed nor practically that huge.
660

This is incorrect for anything greater than 31. (1 << 32) is just zero, no matter the type.

llvm/unittests/Analysis/ScalarEvolutionTest.cpp
1764

Just check that they are constants you expect to see.

This revision now requires changes to proceed.Feb 20 2023, 9:55 PM
mkazantsev added inline comments.Feb 20 2023, 9:57 PM
llvm/include/llvm/Analysis/ScalarEvolution.h
659

Change return types here to const SCEVConstant *? Can be an NFC follow-up.

mkazantsev added inline comments.Feb 20 2023, 9:59 PM
llvm/include/llvm/Analysis/ScalarEvolution.h
660

Even if you make it 1LL << 32, it is still wrong. You should use APInt to construct the constant,

dbakunevich retitled this revision from [SCEV] Added a util function to SCEV to [SCEV] Added a utility method that raising the number 2 to the desired power to SCEV.Feb 21 2023, 5:22 AM
dbakunevich marked 4 inline comments as done.
mkazantsev requested changes to this revision.Feb 26 2023, 7:04 PM
mkazantsev added inline comments.
llvm/include/llvm/Analysis/ScalarEvolution.h
658

/// Return a SCEV for the constant \p Power of two.

660

You still haven't addressed my previous comment here. Test for Power = 62? You'll see it fails.

This revision now requires changes to proceed.Feb 26 2023, 7:04 PM
dbakunevich marked 3 inline comments as done.
nikic added a subscriber: nikic.Feb 27 2023, 1:46 AM

Where is this method going to be used?

dbakunevich added a comment.EditedFeb 27 2023, 2:51 AM

Where is this method going to be used?

This helper method is planned to be used to improve the SCEV module. In particular, to improve existing optimizations and to write new ones.

llvm/include/llvm/Analysis/ScalarEvolution.h
659

I'll do it in the next NFC patch.

Code is fine with nits now, but I want to see the application before I approve this.

llvm/include/llvm/Analysis/ScalarEvolution.h
660

Assert that Power is less than type width?

llvm/unittests/Analysis/ScalarEvolutionTest.cpp
1750

param not needed

1760

Use Type::getInt64Ty(Ctx)

1761

{ } not needed.

dbakunevich marked 4 inline comments as done.
nikic added inline comments.Feb 27 2023, 5:52 AM
llvm/include/llvm/Analysis/ScalarEvolution.h
661

APInt::getOneBitSet().

dbakunevich marked an inline comment as done.
mkazantsev accepted this revision.Feb 28 2023, 2:04 AM

I talked to Dmitry offline, and the motivating example is in downstream code. However, I think this utility function is still a good thing to have in general, maybe someone else will use it.

@dbakunevich I propose commit message

[SCEV][NFC] Introduce utility function to get power of 2
This revision is now accepted and ready to land.Feb 28 2023, 2:04 AM
nikic added a comment.Feb 28 2023, 2:15 AM

I talked to Dmitry offline, and the motivating example is in downstream code. However, I think this utility function is still a good thing to have in general, maybe someone else will use it.

There are two uses of APInt::getOneBitSet() that could make use of this API -- but they specify the bitwidth as an integer, not as a type.

Though TBH I can't say the value of getPowerOfTwo(BitWidth, TZ) over getConstant(APInt::getOneBitSet(BitWidth, TZ)) is particularly large.

This revision was landed with ongoing or failed builds.Feb 28 2023, 4:06 AM
This revision was automatically updated to reflect the committed changes.