Skip to content

Commit 4c37dc3

Browse files
committed
add unit test
1 parent 054a3c5 commit 4c37dc3

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,4 +954,36 @@ TEST_F(ScalarEvolutionExpanderTest, ExpandNonIntegralPtrWithNullBase) {
954954
});
955955
}
956956

957+
TEST_F(ScalarEvolutionExpanderTest, GEPFlags) {
958+
LLVMContext C;
959+
SMDiagnostic Err;
960+
StringRef ModStr = R"(
961+
define void @f(ptr %p, i64 %x) {
962+
%gep_inbounds = getelementptr inbounds i8, ptr %p, i64 %x
963+
ret void
964+
})";
965+
std::unique_ptr<Module> M = parseAssemblyString(ModStr, Err, C);
966+
967+
assert(M && "Could not parse module?");
968+
assert(!verifyModule(*M) && "Must have been well formed!");
969+
970+
Function *F = M->getFunction("f");
971+
ASSERT_NE(F, nullptr) << "Could not find function 'f'";
972+
BasicBlock &Entry = F->getEntryBlock();
973+
auto *GEP = cast<GetElementPtrInst>(&Entry.front());
974+
975+
ScalarEvolution SE = buildSE(*F);
976+
const SCEV *Ptr = SE.getSCEV(F->getArg(0));
977+
const SCEV *X = SE.getSCEV(F->getArg(1));
978+
const SCEV *PtrX = SE.getAddExpr(Ptr, X);
979+
980+
SCEVExpander Exp(SE, M->getDataLayout(), "expander");
981+
auto *I = cast<Instruction>(
982+
Exp.expandCodeFor(PtrX, nullptr, Entry.getTerminator()));
983+
// Check that the GEP is reused, but the inbounds flag cleared. We don't
984+
// know that the newly introduced use is inbounds.
985+
EXPECT_EQ(I, GEP);
986+
EXPECT_EQ(GEP->getNoWrapFlags(), GEPNoWrapFlags::none());
987+
}
988+
957989
} // end namespace llvm

0 commit comments

Comments
 (0)