diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-06-26 12:41:15 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-06-26 12:41:15 +0000 |
commit | 7c45debaea9147693e61f310ab57a7cba8a71bce (patch) | |
tree | c142380b00d33e0c649f4b80843a28472c8893fa /llvm/lib/Transforms/InstCombine | |
parent | f2f9f2f505bb06421c323ffc50e9a5ebcac0894e (diff) | |
download | bcm5719-llvm-7c45debaea9147693e61f310ab57a7cba8a71bce.tar.gz bcm5719-llvm-7c45debaea9147693e61f310ab57a7cba8a71bce.zip |
[InstCombine] fold udiv with sext bool divisor
Note: I didn't add a hasOneUse() check because the existing,
related fold doesn't have that check. I suspect that the
improved analysis and codegen make these some of the rare
canonicalization cases where we allow an increase in
instructions.
llvm-svn: 335597
Diffstat (limited to 'llvm/lib/Transforms/InstCombine')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index bb714d00d69..7a8f2c27adc 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -954,9 +954,15 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) { // Op0 / C where C is large (negative) --> zext (Op0 >= C) // TODO: Could use isKnownNegative() to handle non-constant values. + Type *Ty = I.getType(); if (match(Op1, m_Negative())) { Value *Cmp = Builder.CreateICmpUGE(Op0, Op1); - return CastInst::CreateZExtOrBitCast(Cmp, I.getType()); + return CastInst::CreateZExtOrBitCast(Cmp, Ty); + } + // Op0 / (sext i1 X) --> zext (Op0 == -1) (if X is 0, the div is undefined) + if (match(Op1, m_SExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)) { + Value *Cmp = Builder.CreateICmpEQ(Op0, ConstantInt::getAllOnesValue(Ty)); + return CastInst::CreateZExtOrBitCast(Cmp, Ty); } if (Instruction *NarrowDiv = narrowUDivURem(I, Builder)) |