diff options
author | Sebastian Pop <spop@codeaurora.org> | 2014-05-27 22:42:00 +0000 |
---|---|---|
committer | Sebastian Pop <spop@codeaurora.org> | 2014-05-27 22:42:00 +0000 |
commit | f93ef123300cf943980fef09cee723cf49c96017 (patch) | |
tree | 8f657de4423a0d4d435d831147a7054002e06061 /llvm/lib | |
parent | e30bd351cc8ac1981b1c6e4190a74d6f5ab77097 (diff) | |
download | bcm5719-llvm-f93ef123300cf943980fef09cee723cf49c96017.tar.gz bcm5719-llvm-f93ef123300cf943980fef09cee723cf49c96017.zip |
avoid type mismatch when building SCEVs
This is a corner case I have stumbled upon when dealing with ARM64 type
conversions. I was not able to extract a testcase for the community codebase to
fail on. The patch conservatively discards a division that would have ended up
in an ICE due to a type mismatch when building a multiply expression. I have
also added code to a place that builds add expressions and in which we should be
careful not to pass in operands of different types.
llvm-svn: 209694
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 4d85948489d..42a7aa23896 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -7131,9 +7131,19 @@ public: void visitAddExpr(const SCEVAddExpr *Numerator) { SmallVector<const SCEV *, 2> Qs, Rs; + Type *Ty = Denominator->getType(); + for (const SCEV *Op : Numerator->operands()) { const SCEV *Q, *R; divide(SE, Op, Denominator, &Q, &R); + + // Bail out if types do not match. + if (Ty != Q->getType() || Ty != R->getType()) { + Quotient = Zero; + Remainder = Numerator; + return; + } + Qs.push_back(Q); Rs.push_back(R); } @@ -7150,9 +7160,17 @@ public: void visitMulExpr(const SCEVMulExpr *Numerator) { SmallVector<const SCEV *, 2> Qs; + Type *Ty = Denominator->getType(); bool FoundDenominatorTerm = false; for (const SCEV *Op : Numerator->operands()) { + // Bail out if types do not match. + if (Ty != Op->getType()) { + Quotient = Zero; + Remainder = Numerator; + return; + } + if (FoundDenominatorTerm) { Qs.push_back(Op); continue; @@ -7165,6 +7183,14 @@ public: Qs.push_back(Op); continue; } + + // Bail out if types do not match. + if (Ty != Q->getType()) { + Quotient = Zero; + Remainder = Numerator; + return; + } + FoundDenominatorTerm = true; Qs.push_back(Q); } |