diff options
author | David Majnemer <david.majnemer@gmail.com> | 2015-09-06 06:49:59 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2015-09-06 06:49:59 +0000 |
commit | 135ca40a7db96c91840d55d075930e5bb81c1e8b (patch) | |
tree | e3b3380b3ed0f6b5a54ba48cb8f6036bce43f9c2 /llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | |
parent | 10aac5fd0e5c2649571862aeb1e78228dcba3098 (diff) | |
download | llvm-135ca40a7db96c91840d55d075930e5bb81c1e8b.zip llvm-135ca40a7db96c91840d55d075930e5bb81c1e8b.tar.gz llvm-135ca40a7db96c91840d55d075930e5bb81c1e8b.tar.bz2 |
[InstCombine] Don't divide by zero when evaluating a potential transform
Trivial multiplication by zero may survive the worklist. We tried to
reassociate the multiplication with a division instruction, causing us
to divide by zero; bail out instead.
This fixes PR24726.
llvm-svn: 246939
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index a554e9f..bb3d928 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -95,6 +95,14 @@ static bool IsMultiple(const APInt &C1, const APInt &C2, APInt &Quotient, assert(C1.getBitWidth() == C2.getBitWidth() && "Inconsistent width of constants!"); + // Bail if we will divide by zero. + if (C2.isMinValue()) + return false; + + // Bail if we would divide INT_MIN by -1. + if (IsSigned && C1.isMinSignedValue() && C2.isAllOnesValue()) + return false; + APInt Remainder(C1.getBitWidth(), /*Val=*/0ULL, IsSigned); if (IsSigned) APInt::sdivrem(C1, C2, Quotient, Remainder); |