From a694e2a6910a33596ca706e2c6fc713f02b64c50 Mon Sep 17 00:00:00 2001 From: Nadav Rotem Date: Tue, 28 Aug 2012 12:23:22 +0000 Subject: [PATCH] Make sure that we don't call getZExtValue on values > 64 bits. Thanks Benjamin for noticing this. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@162749 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 16 ++++++++-------- test/Transforms/InstCombine/2012-08-28-udiv_ashl.ll | 7 +++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index e104a0a9798..5eba463ec05 100644 --- a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -462,11 +462,11 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) { } } - // Udiv ((Lshl x, c1) , c2) -> x / (C1 * 1<(Op1)) { + // Udiv ((Lshl x, C1) , C2) -> x / (C2 * 1<(Op1)) { Value *X = 0, *C1 = 0; - if (match(Op0, m_LShr(m_Value(X), m_Value(C1)))) { - uint64_t NC = cast(C)->getZExtValue() * + if (match(Op0, m_LShr(m_Value(X), m_Value(C1))) && C2->getBitWidth() < 65) { + uint64_t NC = cast(C2)->getZExtValue() * (1<< cast(C1)->getZExtValue()); return BinaryOperator::CreateUDiv(X, ConstantInt::get(I.getType(), NC)); } @@ -543,11 +543,11 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) { ConstantExpr::getNeg(RHS)); } - // Sdiv ((Ashl x, c1) , c2) -> x / (C1 * 1<(Op1)) { + // Sdiv ((Ashl x, C1) , C2) -> x / (C2 * 1<(Op1)) { Value *X = 0, *C1 = 0; - if (match(Op0, m_AShr(m_Value(X), m_Value(C1)))) { - uint64_t NC = cast(C)->getZExtValue() * + if (match(Op0, m_AShr(m_Value(X), m_Value(C1))) && C2->getBitWidth() < 65) { + uint64_t NC = cast(C2)->getZExtValue() * (1<< cast(C1)->getZExtValue()); return BinaryOperator::CreateSDiv(X, ConstantInt::get(I.getType(), NC)); } diff --git a/test/Transforms/InstCombine/2012-08-28-udiv_ashl.ll b/test/Transforms/InstCombine/2012-08-28-udiv_ashl.ll index 9f52119248e..1bede348931 100644 --- a/test/Transforms/InstCombine/2012-08-28-udiv_ashl.ll +++ b/test/Transforms/InstCombine/2012-08-28-udiv_ashl.ll @@ -48,3 +48,10 @@ entry: %div1 = sdiv i32 %div, 100 ret i32 %div1 } + +define i80 @no_crash_i80(i80 %x) { +entry: + %div = lshr i80 %x, 2 + %div1 = udiv i80 %div, 100 + ret i80 %div1 +} -- 2.11.0