[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).
llvm-svn: 217544
diff --git a/llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp b/llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp
index a662acc..7ab16f1 100644
--- a/llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp
+++ b/llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp
@@ -179,7 +179,9 @@
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 @@
NewAlignment << "\n");
return NewAlignment;
}
- } else if (NewIncAlignment == NewAlignment && NewIncAlignment) {
+ } else if (NewIncAlignment == NewAlignment) {
DEBUG(dbgs() << "\tnew start/inc alignment: " <<
NewAlignment << "\n");
return NewAlignment;