diff options
author | Sanjay Patel <spatel@rotateright.com> | 2016-06-27 18:38:40 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2016-06-27 18:38:40 +0000 |
commit | bedd1f9d3d45bc4e62a8b8806598fc5ae327bf92 (patch) | |
tree | ab7ad070eed2253ce9f7fcf7a5ea64072c99cb35 | |
parent | cbfeb9f7cdaf6ebbb509d3412bb90aa976551c30 (diff) | |
download | bcm5719-llvm-bedd1f9d3d45bc4e62a8b8806598fc5ae327bf92.tar.gz bcm5719-llvm-bedd1f9d3d45bc4e62a8b8806598fc5ae327bf92.zip |
[InstCombine] refactor sdiv by APInt transforms (NFC)
There's at least one more fold to do here:
https://llvm.org/bugs/show_bug.cgi?id=28153
llvm-svn: 273904
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index d7bd80261ab..4e5bf7859db 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -1139,16 +1139,17 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) { if (Instruction *Common = commonIDivTransforms(I)) return Common; - // sdiv X, -1 == -X - if (match(Op1, m_AllOnes())) - return BinaryOperator::CreateNeg(Op0); - - // sdiv exact X, C --> ashr exact X, log2(C) const APInt *Op1C; - if (match(Op1, m_APInt(Op1C)) && I.isExact() && Op1C->isNonNegative() && - Op1C->isPowerOf2()) { - Value *ShAmt = ConstantInt::get(Op1->getType(), Op1C->exactLogBase2()); - return BinaryOperator::CreateExactAShr(Op0, ShAmt, I.getName()); + 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()); + return BinaryOperator::CreateExactAShr(Op0, ShAmt, I.getName()); + } } if (Constant *RHS = dyn_cast<Constant>(Op1)) { |