[AlignmentFromAssumptions] Don't divide by zero for unknown starting alignment

The routine that determines an alignment given some SCEV returns zero if the
answer is unknown. In a case where we could determine the increment of an
AddRec but not the starting alignment, we would compute the integer modulus by
zero (which is illegal and traps). Prevent this by returning early if either
the start or increment alignment is unknown (zero).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217544 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Hal Finkel
2014-09-10 21:05:52 +00:00
parent ec407162c1
commit fb42ed2925
2 changed files with 158 additions and 2 deletions

View File

@ -179,7 +179,9 @@ static unsigned getNewAlignment(const SCEV *AASCEV, const SCEV *AlignSCEV,
DEBUG(dbgs() << "\tnew start alignment: " << NewAlignment << "\n");
DEBUG(dbgs() << "\tnew inc alignment: " << NewIncAlignment << "\n");
if (NewAlignment > NewIncAlignment) {
if (!NewAlignment || !NewIncAlignment) {
return 0;
} else if (NewAlignment > NewIncAlignment) {
if (NewAlignment % NewIncAlignment == 0) {
DEBUG(dbgs() << "\tnew start/inc alignment: " <<
NewIncAlignment << "\n");
@ -191,7 +193,7 @@ static unsigned getNewAlignment(const SCEV *AASCEV, const SCEV *AlignSCEV,
NewAlignment << "\n");
return NewAlignment;
}
} else if (NewIncAlignment == NewAlignment && NewIncAlignment) {
} else if (NewIncAlignment == NewAlignment) {
DEBUG(dbgs() << "\tnew start/inc alignment: " <<
NewAlignment << "\n");
return NewAlignment;