@@ -954,4 +954,36 @@ TEST_F(ScalarEvolutionExpanderTest, ExpandNonIntegralPtrWithNullBase) {
954
954
});
955
955
}
956
956
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
+
957
989
} // end namespace llvm
0 commit comments