diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-06-25 21:39:41 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-06-25 21:39:41 +0000 |
commit | 6a96d90acd4ea15b18ab526966dcd4f1fe86754a (patch) | |
tree | 203cbd58f3471d6ef99645d5f21c0fcefb5e27e7 /llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | |
parent | 46f9b8c333d641f5d386e21d0ca3cc34b8b90e34 (diff) | |
download | bcm5719-llvm-6a96d90acd4ea15b18ab526966dcd4f1fe86754a.tar.gz bcm5719-llvm-6a96d90acd4ea15b18ab526966dcd4f1fe86754a.zip |
[InstCombine] fold sdiv with sext bool divisor
llvm-svn: 335527
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index c2293f08309..326f499ed9f 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -1019,12 +1019,15 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) { return Common; Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); + Value *X; + // sdiv Op0, -1 --> -Op0 + // sdiv Op0, (sext i1 X) --> -Op0 (because if X is 0, the op is undefined) + if (match(Op1, m_AllOnes()) || + (match(Op1, m_SExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1))) + return BinaryOperator::CreateNeg(Op0); + const APInt *Op1C; if (match(Op1, m_APInt(Op1C))) { - // sdiv X, -1 == -X - if (Op1C->isAllOnesValue()) - return BinaryOperator::CreateNeg(Op0); - // sdiv exact X, C --> ashr exact X, log2(C) if (I.isExact() && Op1C->isNonNegative() && Op1C->isPowerOf2()) { Value *ShAmt = ConstantInt::get(Op1->getType(), Op1C->exactLogBase2()); |