diff options
author | Amjad Aboud <amjad.aboud@intel.com> | 2017-08-16 22:42:38 +0000 |
---|---|---|
committer | Amjad Aboud <amjad.aboud@intel.com> | 2017-08-16 22:42:38 +0000 |
commit | 86111c6696e3411363cd12697e837ca46ca5a2e2 (patch) | |
tree | 789b09e59ee7470535377b86f6e4ac31433ae35a /llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | |
parent | cbcffb173c25a294fb21ba0c77ff5e68a004601e (diff) | |
download | bcm5719-llvm-86111c6696e3411363cd12697e837ca46ca5a2e2.tar.gz bcm5719-llvm-86111c6696e3411363cd12697e837ca46ca5a2e2.zip |
[InstCombine] Teach canEvaluateTruncated to handle arithmetic shift (including those with vector splat shift amount)
Differential Revision: https://reviews.llvm.org/D36784
llvm-svn: 311050
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 298120e1f69..05728c25db7 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -373,6 +373,23 @@ static bool canEvaluateTruncated(Value *V, Type *Ty, InstCombiner &IC, } break; } + case Instruction::AShr: { + // If this is a truncate of an arithmetic shr, we can truncate it to a + // smaller ashr iff we know that all the bits from the sign bit of the + // original type and the sign bit of the truncate type are similar. + // TODO: It is enough to check that the bits we would be shifting in are + // similar to sign bit of the truncate type. + const APInt *Amt; + if (match(I->getOperand(1), m_APInt(Amt))) { + uint32_t OrigBitWidth = OrigTy->getScalarSizeInBits(); + uint32_t BitWidth = Ty->getScalarSizeInBits(); + if (Amt->getLimitedValue(BitWidth) < BitWidth && + OrigBitWidth - BitWidth < + IC.ComputeNumSignBits(I->getOperand(0), 0, CxtI)) + return canEvaluateTruncated(I->getOperand(0), Ty, IC, CxtI); + } + break; + } case Instruction::Trunc: // trunc(trunc(x)) -> trunc(x) return true; |