diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-02-13 20:41:22 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-02-13 20:41:22 +0000 |
commit | cb8ac00f733fbf290179b011739770a8f17e1b03 (patch) | |
tree | 3796b6ce462043bd9baae8d87d661fb84fa16ce9 /llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | |
parent | fd520962590350c8072394771ced45b15ee93002 (diff) | |
download | bcm5719-llvm-cb8ac00f733fbf290179b011739770a8f17e1b03.tar.gz bcm5719-llvm-cb8ac00f733fbf290179b011739770a8f17e1b03.zip |
[InstCombine] (bool X) * Y --> X ? Y : 0
This is both a functional improvement for vectors and an
efficiency improvement for scalars. The existing code below
the new folds does the same thing for scalars, but in an
indirect and expensive way.
llvm-svn: 325048
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index 7654c34cc4c..27f2a6dbc4e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -340,6 +340,15 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { } } + Value *X; + // (bool X) * Y --> X ? Y : 0 + if (match(Op0, m_ZExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)) + return SelectInst::Create(X, Op1, ConstantInt::get(I.getType(), 0)); + + // Y * (bool X) --> X ? Y : 0 + if (match(Op1, m_ZExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)) + return SelectInst::Create(X, Op0, ConstantInt::get(I.getType(), 0)); + // If one of the operands of the multiply is a cast from a boolean value, then // we know the bool is either zero or one, so this is a 'masking' multiply. // X * Y (where Y is 0 or 1) -> X & (0-Y) |