/// 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");
+ return getConstant(APInt::getOneBitSet(getTypeSizeInBits(Ty), Power));
+ }
+
/// Return a SCEV for the constant -1 of a specific type.
const SCEV *getMinusOne(Type *Ty) {
return getConstant(Ty, -1, /*isSigned=*/true);
});
}
+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);
+
+ for (unsigned short i = 0; i < 64; ++i)
+ EXPECT_TRUE(
+ dyn_cast<SCEVConstant>(SE.getPowerOfTwo(Type::getInt64Ty(Context), i))
+ ->getValue()
+ ->equalsInt(1ULL << i));
+}
+
} // end namespace llvm