diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2016-06-17 20:33:53 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2016-06-17 20:33:53 +0000 |
commit | d76efc14b9eebfc6c176a2b8a16bf661e2ab803c (patch) | |
tree | c400b197dee548c511ade9539e599cc98f4855ca /llvm/lib | |
parent | e97deffb6a20832cd79fb12cdc9b51b1694bb97a (diff) | |
download | bcm5719-llvm-d76efc14b9eebfc6c176a2b8a16bf661e2ab803c.tar.gz bcm5719-llvm-d76efc14b9eebfc6c176a2b8a16bf661e2ab803c.zip |
Revert "Revert "InstCombine: Reduce trunc (shl x, K) width.""
Reapply r272987. Condition should be in terms of the destination type,
and the flags should not be copied.
llvm-svn: 273045
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index dddcd0183b3..75562eca390 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -566,11 +566,28 @@ 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) && - 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)); + 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 < dest size. + if (match(Src, m_Shl(m_Value(A), m_ConstantInt(Cst)))) { + const unsigned DestSize = DestTy->getPrimitiveSizeInBits(); + if (Cst->getValue().ult(DestSize)) { + Value *NewTrunc = Builder->CreateTrunc(A, DestTy, A->getName() + ".tr"); + + return BinaryOperator::Create( + Instruction::Shl, NewTrunc, + ConstantInt::get(DestTy, Cst->getValue().trunc(DestSize))); + } + } } if (Instruction *I = foldVecTruncToExtElt(CI, *this, DL)) |