[llvm] 52f2970 - [InstCombine] reduce code duplication; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sat May 29 06:12:03 PDT 2021
Author: Sanjay Patel
Date: 2021-05-29T08:33:25-04:00
New Revision: 52f2970036019b54f280bd531c7c65c09e18567a
URL: https://github.com/llvm/llvm-project/commit/52f2970036019b54f280bd531c7c65c09e18567a
DIFF: https://github.com/llvm/llvm-project/commit/52f2970036019b54f280bd531c7c65c09e18567a.diff
LOG: [InstCombine] reduce code duplication; NFC
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 49c6057d8c932..9e2b673b0a7b2 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1482,6 +1482,8 @@ Instruction *InstCombinerImpl::visitSExt(SExtInst &CI) {
Value *Src = CI.getOperand(0);
Type *SrcTy = Src->getType(), *DestTy = CI.getType();
+ unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
+ unsigned DestBitSize = DestTy->getScalarSizeInBits();
// If we know that the value being extended is positive, we can use a zext
// instead.
@@ -1499,9 +1501,6 @@ Instruction *InstCombinerImpl::visitSExt(SExtInst &CI) {
Value *Res = EvaluateInDifferentType(Src, DestTy, true);
assert(Res->getType() == DestTy);
- uint32_t SrcBitSize = SrcTy->getScalarSizeInBits();
- uint32_t DestBitSize = DestTy->getScalarSizeInBits();
-
// If the high bits are already filled with sign bit, just replace this
// cast with the result.
if (ComputeNumSignBits(Res, 0, &CI) > DestBitSize - SrcBitSize)
@@ -1517,9 +1516,7 @@ Instruction *InstCombinerImpl::visitSExt(SExtInst &CI) {
// into shifts.
Value *X;
if (match(Src, m_OneUse(m_Trunc(m_Value(X)))) && X->getType() == DestTy) {
- // sext(trunc(X)) --> ashr(shl(X, C), C)
- unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
- unsigned DestBitSize = DestTy->getScalarSizeInBits();
+ // sext (trunc X) --> ashr (shl X, C), C
Constant *ShAmt = ConstantInt::get(DestTy, DestBitSize - SrcBitSize);
return BinaryOperator::CreateAShr(Builder.CreateShl(X, ShAmt), ShAmt);
}
More information about the llvm-commits
mailing list