summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2016-06-17 04:43:22 +0000
committerMatt Arsenault <Matthew.Arsenault@amd.com>2016-06-17 04:43:22 +0000
commit028fd5064298868dbc238fe768091a3c8360959d (patch)
treea2cc011b651c18cc0d5b4a50c09413216f53e3a1 /llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
parent211ba785d9b12ab4014d76fdae7b0d5b3df132d4 (diff)
downloadbcm5719-llvm-028fd5064298868dbc238fe768091a3c8360959d.tar.gz
bcm5719-llvm-028fd5064298868dbc238fe768091a3c8360959d.zip
InstCombine: Reduce trunc (shl x, K) width.
llvm-svn: 272987
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp29
1 files changed, 24 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index dddcd0183b3..1eba354532f 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -566,11 +566,30 @@ 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 < 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));
+ }
+ }
}
if (Instruction *I = foldVecTruncToExtElt(CI, *this, DL))
OpenPOWER on IntegriCloud