diff options
author | Sanjay Patel <spatel@rotateright.com> | 2017-01-13 18:52:10 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2017-01-13 18:52:10 +0000 |
commit | acd24c7b6a2ce097a7850b402f219a64d61da18d (patch) | |
tree | d99762f0768e4be5215101a93dd6e01f21350707 /llvm/lib/Transforms/InstCombine | |
parent | d109f46573595e78044b1276a083fd0f988d37c8 (diff) | |
download | bcm5719-llvm-acd24c7b6a2ce097a7850b402f219a64d61da18d.tar.gz bcm5719-llvm-acd24c7b6a2ce097a7850b402f219a64d61da18d.zip |
[InstCombine] use 'match' and other clean-up; NFCI
llvm-svn: 291937
Diffstat (limited to 'llvm/lib/Transforms/InstCombine')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp index a79a630e5ec..5209dad31b5 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp @@ -727,23 +727,14 @@ Instruction *InstCombiner::visitShl(BinaryOperator &I) { if (match(Op1, m_APInt(ShAmtAPInt))) { unsigned ShAmt = ShAmtAPInt->getZExtValue(); - // Turn: - // %zext = zext i32 %V to i64 - // %res = shl i64 %V, 8 - // - // Into: - // %shl = shl i32 %V, 8 - // %res = zext i32 %shl to i64 - // - // This is only valid if %V would have zeros shifted out. - if (auto *ZI = dyn_cast<ZExtInst>(Op0)) { - unsigned SrcBitWidth = ZI->getSrcTy()->getScalarSizeInBits(); - if (ShAmt < SrcBitWidth && - MaskedValueIsZero(ZI->getOperand(0), - APInt::getHighBitsSet(SrcBitWidth, ShAmt), 0, &I)) { - auto *Shl = Builder->CreateShl(ZI->getOperand(0), ShAmt); - return new ZExtInst(Shl, I.getType()); - } + // shl (zext X), ShAmt --> zext (shl X, ShAmt) + // This is only valid if X would have zeros shifted out. + Value *X; + if (match(Op0, m_ZExt(m_Value(X)))) { + unsigned SrcWidth = X->getType()->getScalarSizeInBits(); + if (ShAmt < SrcWidth && + MaskedValueIsZero(X, APInt::getHighBitsSet(SrcWidth, ShAmt), 0, &I)) + return new ZExtInst(Builder->CreateShl(X, ShAmt), I.getType()); } // If the shifted-out value is known-zero, then this is a NUW shift. |