diff options
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 29 |
1 files changed, 5 insertions, 24 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 1eba354532f..dddcd0183b3 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -566,30 +566,11 @@ Instruction *InstCombiner::visitTrunc(TruncInst &CI) { // Transform "trunc (and X, cst)" -> "and (trunc X), cst" so long as the dest // type isn't non-native. if (Src->hasOneUse() && isa<IntegerType>(SrcTy) && - ShouldChangeType(SrcTy, DestTy)) { - - // Transform "trunc (and X, cst)" -> "and (trunc X), cst" so long as the dest - // type isn't non-native. - if (match(Src, m_And(m_Value(A), m_ConstantInt(Cst)))) { - Value *NewTrunc = Builder->CreateTrunc(A, DestTy, A->getName() + ".tr"); - return BinaryOperator::CreateAnd(NewTrunc, - ConstantExpr::getTrunc(Cst, DestTy)); - } - - // Transform "trunc (shl X, cst)" -> "shl (trunc X), cst" so long as the dest - // type isn't non-native and cst < size / 2 - if (match(Src, m_Shl(m_Value(A), m_ConstantInt(Cst)))) { - const unsigned Size = A->getType()->getPrimitiveSizeInBits(); - if (Cst->getValue().ult(Size / 2)) { - const unsigned DstSize = DestTy->getPrimitiveSizeInBits(); - Value *NewTrunc = Builder->CreateTrunc(A, DestTy, A->getName() + ".tr"); - - return BinaryOperator::CreateWithCopiedFlags( - Instruction::Shl, NewTrunc, - ConstantInt::get(DestTy, Cst->getValue().trunc(DstSize)), - cast<BinaryOperator>(Src)); - } - } + ShouldChangeType(SrcTy, DestTy) && + match(Src, m_And(m_Value(A), m_ConstantInt(Cst)))) { + Value *NewTrunc = Builder->CreateTrunc(A, DestTy, A->getName() + ".tr"); + return BinaryOperator::CreateAnd(NewTrunc, + ConstantExpr::getTrunc(Cst, DestTy)); } if (Instruction *I = foldVecTruncToExtElt(CI, *this, DL)) |