Transform (sub 0, (zext bool to A)) to (sext bool to A) and

(sub 0, (sext bool to A)) to (zext bool to A).

Patch by Muhammad Ahmad
Reviewed by Duncan Sands

llvm-svn: 173093
This commit is contained in:
Paul Redmond
2013-01-21 21:57:20 +00:00
parent 830875bbda
commit 9d86a4a3b6
4 changed files with 22 additions and 4 deletions

View File

@@ -1250,6 +1250,16 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
if (SimplifyDemandedInstructionBits(I))
return &I;
// Fold (sub 0, (zext bool to B)) --> (sext bool to B)
if (C->isZero() && match(Op1, m_ZExt(m_Value(X))))
if (X->getType()->isIntegerTy(1))
return CastInst::CreateSExtOrBitCast(X, Op1->getType());
// Fold (sub 0, (sext bool to B)) --> (zext bool to B)
if (C->isZero() && match(Op1, m_SExt(m_Value(X))))
if (X->getType()->isIntegerTy(1))
return CastInst::CreateZExtOrBitCast(X, Op1->getType());
}