summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2015-11-18 00:00:04 +0000
committerSanjay Patel <spatel@rotateright.com>2015-11-18 00:00:04 +0000
commit77f448695091fb421bc8ba4977763eab50654252 (patch)
tree8290e24289df62d128a648630a9107a5368c6e89
parent55020566edcc1c3a718e43d29eb4d3f17c800472 (diff)
downloadbcm5719-llvm-77f448695091fb421bc8ba4977763eab50654252.tar.gz
bcm5719-llvm-77f448695091fb421bc8ba4977763eab50654252.zip
[InstCombine] refactor optimizeIntToFloatBitCast() ; NFCI
The logic for handling the pattern without a shift is identical to the logic for handling the pattern with a shift if you set the shift amount to zero for the former. This should make it easier to see that we probably don't even need optimizeIntToFloatBitCast(). If we call something like foldVecTruncToExtElt() from visitTrunc(), we'll solve PR25543: https://llvm.org/bugs/show_bug.cgi?id=25543 llvm-svn: 253403
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp67
1 files changed, 29 insertions, 38 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 3cf8561a1d3..18415efb16f 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1715,62 +1715,53 @@ static Value *optimizeIntegerToVectorInsertions(BitCastInst &CI,
return Result;
}
+static Instruction *foldVecTruncToExtElt(Value *VecInput, Type *DestTy,
+ unsigned ShiftAmt, InstCombiner &IC,
+ const DataLayout &DL) {
+ VectorType *VecTy = cast<VectorType>(VecInput->getType());
+ unsigned DestWidth = DestTy->getPrimitiveSizeInBits();
+ unsigned VecWidth = VecTy->getPrimitiveSizeInBits();
+
+ if ((VecWidth % DestWidth != 0) || (ShiftAmt % DestWidth != 0))
+ return nullptr;
+
+ // If the element type of the vector doesn't match the result type,
+ // bitcast it to be a vector type we can extract from.
+ unsigned NumVecElts = VecWidth / DestWidth;
+ if (VecTy->getElementType() != DestTy) {
+ VecTy = VectorType::get(DestTy, NumVecElts);
+ VecInput = IC.Builder->CreateBitCast(VecInput, VecTy);
+ }
+
+ unsigned Elt = ShiftAmt / DestWidth;
+ if (DL.isBigEndian())
+ Elt = NumVecElts - 1 - Elt;
+
+ return ExtractElementInst::Create(VecInput, IC.Builder->getInt32(Elt));
+}
/// See if we can optimize an integer->float/double bitcast.
/// The various long double bitcasts can't get in here.
static Instruction *optimizeIntToFloatBitCast(BitCastInst &CI, InstCombiner &IC,
const DataLayout &DL) {
Value *Src = CI.getOperand(0);
- Type *DestTy = CI.getType();
+ Type *DstTy = CI.getType();
// If this is a bitcast from int to float, check to see if the int is an
// extraction from a vector.
Value *VecInput = nullptr;
// bitcast(trunc(bitcast(somevector)))
if (match(Src, m_Trunc(m_BitCast(m_Value(VecInput)))) &&
- isa<VectorType>(VecInput->getType())) {
- VectorType *VecTy = cast<VectorType>(VecInput->getType());
- unsigned DestWidth = DestTy->getPrimitiveSizeInBits();
-
- if (VecTy->getPrimitiveSizeInBits() % DestWidth == 0) {
- // If the element type of the vector doesn't match the result type,
- // bitcast it to be a vector type we can extract from.
- if (VecTy->getElementType() != DestTy) {
- VecTy = VectorType::get(DestTy,
- VecTy->getPrimitiveSizeInBits() / DestWidth);
- VecInput = IC.Builder->CreateBitCast(VecInput, VecTy);
- }
-
- unsigned Elt = 0;
- if (DL.isBigEndian())
- Elt = VecTy->getPrimitiveSizeInBits() / DestWidth - 1;
- return ExtractElementInst::Create(VecInput, IC.Builder->getInt32(Elt));
- }
- }
+ isa<VectorType>(VecInput->getType()))
+ return foldVecTruncToExtElt(VecInput, DstTy, 0, IC, DL);
// bitcast(trunc(lshr(bitcast(somevector), cst))
ConstantInt *ShAmt = nullptr;
if (match(Src, m_Trunc(m_LShr(m_BitCast(m_Value(VecInput)),
m_ConstantInt(ShAmt)))) &&
- isa<VectorType>(VecInput->getType())) {
- VectorType *VecTy = cast<VectorType>(VecInput->getType());
- unsigned DestWidth = DestTy->getPrimitiveSizeInBits();
- if (VecTy->getPrimitiveSizeInBits() % DestWidth == 0 &&
- ShAmt->getZExtValue() % DestWidth == 0) {
- // If the element type of the vector doesn't match the result type,
- // bitcast it to be a vector type we can extract from.
- if (VecTy->getElementType() != DestTy) {
- VecTy = VectorType::get(DestTy,
- VecTy->getPrimitiveSizeInBits() / DestWidth);
- VecInput = IC.Builder->CreateBitCast(VecInput, VecTy);
- }
+ isa<VectorType>(VecInput->getType()))
+ return foldVecTruncToExtElt(VecInput, DstTy, ShAmt->getZExtValue(), IC, DL);
- unsigned Elt = ShAmt->getZExtValue() / DestWidth;
- if (DL.isBigEndian())
- Elt = VecTy->getPrimitiveSizeInBits() / DestWidth - 1 - Elt;
- return ExtractElementInst::Create(VecInput, IC.Builder->getInt32(Elt));
- }
- }
return nullptr;
}
OpenPOWER on IntegriCloud