[PATCH] D144381: [SCEV] Added a utility method that raising the number 2 to the desired power to SCEV
Dmitry Bakunevich via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 27 05:03:01 PST 2023
dbakunevich updated this revision to Diff 500739.
dbakunevich marked 4 inline comments as done.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D144381/new/
https://reviews.llvm.org/D144381
Files:
llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/unittests/Analysis/ScalarEvolutionTest.cpp
Index: llvm/unittests/Analysis/ScalarEvolutionTest.cpp
===================================================================
--- llvm/unittests/Analysis/ScalarEvolutionTest.cpp
+++ llvm/unittests/Analysis/ScalarEvolutionTest.cpp
@@ -1744,4 +1744,20 @@
});
}
+TEST_F(ScalarEvolutionsTest, CheckGetPowerOfTwo) {
+ Module M("CheckGetPowerOfTwo", Context);
+ FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), {}, false);
+ Function *F = Function::Create(FTy, Function::ExternalLinkage, "foo", M);
+ BasicBlock *Entry = BasicBlock::Create(Context, "entry", F);
+ IRBuilder<> Builder(Entry);
+ Builder.CreateRetVoid();
+ ScalarEvolution SE = buildSE(*F);
+
+ Type *T_int64 = Type::getInt64Ty(Context);
+ for (unsigned short i = 0; i < 64; ++i)
+ EXPECT_TRUE(dyn_cast<SCEVConstant>(SE.getPowerOfTwo(T_int64, i))
+ ->getValue()
+ ->equalsInt(1ULL << i));
+}
+
} // end namespace llvm
Index: llvm/include/llvm/Analysis/ScalarEvolution.h
===================================================================
--- llvm/include/llvm/Analysis/ScalarEvolution.h
+++ llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -655,6 +655,14 @@
/// Return a SCEV for the constant 1 of a specific type.
const SCEV *getOne(Type *Ty) { return getConstant(Ty, 1); }
+ /// Return a SCEV for the constant \p Power of two.
+ const SCEV *getPowerOfTwo(Type *Ty, unsigned Power) {
+ assert(Power < getTypeSizeInBits(Ty) && "Power out of range");
+ auto Val = APInt::getZero(getTypeSizeInBits(Ty));
+ Val.setBit(Power);
+ return getConstant(Val);
+ }
+
/// Return a SCEV for the constant -1 of a specific type.
const SCEV *getMinusOne(Type *Ty) {
return getConstant(Ty, -1, /*isSigned=*/true);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144381.500739.patch
Type: text/x-patch
Size: 1760 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230227/729672d3/attachment.bin>
More information about the llvm-commits
mailing list