diff options
author | Brendon Cahoon <bcahoon@codeaurora.org> | 2015-04-22 15:06:40 +0000 |
---|---|---|
committer | Brendon Cahoon <bcahoon@codeaurora.org> | 2015-04-22 15:06:40 +0000 |
commit | f9751ad1b09ab1eecbf62a43a8ff8fc62a0963dd (patch) | |
tree | 990353ce46fd560e8d7e73af35013754054ba4d0 | |
parent | 60785973701f5558f167ab2f584b19bf5203ae25 (diff) | |
download | bcm5719-llvm-f9751ad1b09ab1eecbf62a43a8ff8fc62a0963dd.tar.gz bcm5719-llvm-f9751ad1b09ab1eecbf62a43a8ff8fc62a0963dd.zip |
Fix a type mismatch assert in SCEV division
An assert was triggered when attempting to create a new SCEV
with operands of different types in the visitAddRecExpr. In this
test case, the operand types of the numerator and denominator
are different. The SCEV division code should generate a
conservative answer when this happens.
Differential Revision: http://reviews.llvm.org/D9021
llvm-svn: 235511
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 8 | ||||
-rw-r--r-- | llvm/test/Analysis/Delinearization/type_mismatch.ll | 29 |
2 files changed, 37 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index d88b0268651..9d99b8f77c9 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -795,6 +795,14 @@ public: assert(Numerator->isAffine() && "Numerator should be affine"); divide(SE, Numerator->getStart(), Denominator, &StartQ, &StartR); divide(SE, Numerator->getStepRecurrence(SE), Denominator, &StepQ, &StepR); + // Bail out if the types do not match. + Type *Ty = Denominator->getType(); + if (Ty != StartQ->getType() || Ty != StartR->getType() || + Ty != StepQ->getType() || Ty != StepR->getType()) { + Quotient = Zero; + Remainder = Numerator; + return; + } Quotient = SE.getAddRecExpr(StartQ, StepQ, Numerator->getLoop(), Numerator->getNoWrapFlags()); Remainder = SE.getAddRecExpr(StartR, StepR, Numerator->getLoop(), diff --git a/llvm/test/Analysis/Delinearization/type_mismatch.ll b/llvm/test/Analysis/Delinearization/type_mismatch.ll new file mode 100644 index 00000000000..0aa9a96cb1f --- /dev/null +++ b/llvm/test/Analysis/Delinearization/type_mismatch.ll @@ -0,0 +1,29 @@ +; RUN: opt < %s -analyze -delinearize +; REQUIRES: asserts + +; Test that SCEV divide code doesn't crash when attempting to create a SCEV +; with operands of different types. In this case, the visitAddRecExpr +; function tries to create an AddRec where the start and step are different +; types. + +target datalayout = "e-m:e-p:32:32-i64:64-a:0-v32:32-n16:32" + +define fastcc void @test() { +entry: + %0 = load i16, i16* undef, align 2 + %conv21 = zext i16 %0 to i32 + br label %for.cond7.preheader + +for.cond7.preheader: + %p1.022 = phi i8* [ undef, %entry ], [ %add.ptr, %for.end ] + br label %for.body11 + +for.body11: + %arrayidx.phi = phi i8* [ %p1.022, %for.cond7.preheader ], [ undef, %for.body11 ] + store i8 undef, i8* %arrayidx.phi, align 1 + br i1 undef, label %for.body11, label %for.end + +for.end: + %add.ptr = getelementptr inbounds i8, i8* %p1.022, i32 %conv21 + br label %for.cond7.preheader +} |