[llvm] bf7f87e - [InstCombine] reduce code duplication in foldBitcastExtElt(); NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 24 07:16:47 PST 2022
Author: Sanjay Patel
Date: 2022-11-24T10:16:37-05:00
New Revision: bf7f87e62c3c8016886dc722eeae9062624a73ca
URL: https://github.com/llvm/llvm-project/commit/bf7f87e62c3c8016886dc722eeae9062624a73ca
DIFF: https://github.com/llvm/llvm-project/commit/bf7f87e62c3c8016886dc722eeae9062624a73ca.diff
LOG: [InstCombine] reduce code duplication in foldBitcastExtElt(); NFC
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index 782af54d9dbf5..ed9661c0a4449 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -187,6 +187,7 @@ Instruction *InstCombinerImpl::foldBitcastExtElt(ExtractElementInst &Ext) {
ElementCount NumElts =
cast<VectorType>(Ext.getVectorOperandType())->getElementCount();
Type *DestTy = Ext.getType();
+ unsigned DestWidth = DestTy->getPrimitiveSizeInBits();
bool IsBigEndian = DL.isBigEndian();
// If we are casting an integer to vector and extracting a portion, that is
@@ -201,12 +202,11 @@ Instruction *InstCombinerImpl::foldBitcastExtElt(ExtractElementInst &Ext) {
// BigEndian: extelt (bitcast i32 X to v4i8), 0 -> trunc i32 (X >> 24) to i8
if (IsBigEndian)
ExtIndexC = NumElts.getKnownMinValue() - 1 - ExtIndexC;
- unsigned ShiftAmountC = ExtIndexC * DestTy->getPrimitiveSizeInBits();
+ unsigned ShiftAmountC = ExtIndexC * DestWidth;
if (!ShiftAmountC || Ext.getVectorOperand()->hasOneUse()) {
Value *Lshr = Builder.CreateLShr(X, ShiftAmountC, "extelt.offset");
if (DestTy->isFloatingPointTy()) {
- Type *DstIntTy = IntegerType::getIntNTy(
- Lshr->getContext(), DestTy->getPrimitiveSizeInBits());
+ Type *DstIntTy = IntegerType::getIntNTy(Lshr->getContext(), DestWidth);
Value *Trunc = Builder.CreateTrunc(Lshr, DstIntTy);
return new BitCastInst(Trunc, DestTy);
}
@@ -283,7 +283,6 @@ Instruction *InstCombinerImpl::foldBitcastExtElt(ExtractElementInst &Ext) {
return nullptr;
unsigned SrcWidth = SrcTy->getScalarSizeInBits();
- unsigned DestWidth = DestTy->getPrimitiveSizeInBits();
unsigned ShAmt = Chunk * DestWidth;
// TODO: This limitation is more strict than necessary. We could sum the
More information about the llvm-commits
mailing list