summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNadav Rotem <nadav.rotem@intel.com>2011-08-29 19:58:36 +0000
committerNadav Rotem <nadav.rotem@intel.com>2011-08-29 19:58:36 +0000
commit89879ec76b5d81b0cc82e9f402dfe7c4cc63b0d6 (patch)
tree63b76e1c8cfe9857bd47b0b7aa99da40baace8dd /lib
parent0da10cf44d0f22111dae728bb535ade2283d976b (diff)
downloadllvm-89879ec76b5d81b0cc82e9f402dfe7c4cc63b0d6.tar.gz
llvm-89879ec76b5d81b0cc82e9f402dfe7c4cc63b0d6.tar.bz2
llvm-89879ec76b5d81b0cc82e9f402dfe7c4cc63b0d6.tar.xz
Fixes following the CR by Chris and Duncan:
Optimize chained bitcasts of the form A->B->A. Undo r138722 and change isEliminableCastPair to allow this case. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138756 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Analysis/ConstantFolding.cpp6
-rw-r--r--lib/Transforms/InstCombine/InstCombineCasts.cpp5
-rw-r--r--lib/VMCore/Instructions.cpp19
3 files changed, 11 insertions, 19 deletions
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp
index 613804d6d2..df79849c3c 100644
--- a/lib/Analysis/ConstantFolding.cpp
+++ b/lib/Analysis/ConstantFolding.cpp
@@ -51,12 +51,6 @@ static Constant *FoldBitCast(Constant *C, Type *DestTy,
if (C->isAllOnesValue() && !DestTy->isX86_MMXTy())
return Constant::getAllOnesValue(DestTy);
- // Bitcast of Bitcast can be done using a single cast.
- ConstantExpr *CE = dyn_cast<ConstantExpr>(C);
- if (CE && CE->getOpcode() == Instruction::BitCast) {
- return ConstantExpr::getBitCast(CE->getOperand(0), DestTy);
- }
-
// The code below only handles casts to vectors currently.
VectorType *DestVTy = dyn_cast<VectorType>(DestTy);
if (DestVTy == 0)
diff --git a/lib/Transforms/InstCombine/InstCombineCasts.cpp b/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 6c42c0c660..ba90bf6b5c 100644
--- a/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1659,11 +1659,6 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
if (DestTy == Src->getType())
return ReplaceInstUsesWith(CI, Src);
- // Bitcasts are transitive.
- if (BitCastInst* BSrc = dyn_cast<BitCastInst>(Src)) {
- return CastInst::Create(Instruction::BitCast, BSrc->getOperand(0), DestTy);
- }
-
if (PointerType *DstPTy = dyn_cast<PointerType>(DestTy)) {
PointerType *SrcPTy = cast<PointerType>(SrcTy);
Type *DstElTy = DstPTy->getElementType();
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index 2f6c069a2d..908e19e2ab 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -2059,8 +2059,7 @@ bool CastInst::isNoopCast(Type *IntPtrTy) const {
/// If no such cast is permited, the function returns 0.
unsigned CastInst::isEliminableCastPair(
Instruction::CastOps firstOp, Instruction::CastOps secondOp,
- Type *SrcTy, Type *MidTy, Type *DstTy, Type *IntPtrTy)
-{
+ Type *SrcTy, Type *MidTy, Type *DstTy, Type *IntPtrTy) {
// Define the 144 possibilities for these two cast instructions. The values
// in this matrix determine what to do in a given situation and select the
// case in the switch below. The rows correspond to firstOp, the columns
@@ -2113,12 +2112,16 @@ unsigned CastInst::isEliminableCastPair(
};
// If either of the casts are a bitcast from scalar to vector, disallow the
- // merging.
- if ((firstOp == Instruction::BitCast &&
- isa<VectorType>(SrcTy) != isa<VectorType>(MidTy)) ||
- (secondOp == Instruction::BitCast &&
- isa<VectorType>(MidTy) != isa<VectorType>(DstTy)))
- return 0; // Disallowed
+ // merging. However, bitcast of A->B->A are allowed.
+ bool isFirstBitcast = (firstOp == Instruction::BitCast);
+ bool isSecondBitcast = (secondOp == Instruction::BitCast);
+ bool chainedBitcast = (SrcTy == DstTy && isFirstBitcast && isSecondBitcast);
+
+ // Check if any of the bitcasts convert scalars<->vectors.
+ if ((isFirstBitcast && isa<VectorType>(SrcTy) != isa<VectorType>(MidTy)) ||
+ (isSecondBitcast && isa<VectorType>(MidTy) != isa<VectorType>(DstTy)))
+ // Unless we are bitcasing to the original type, disallow optimizations.
+ if (!chainedBitcast) return 0;
int ElimCase = CastResults[firstOp-Instruction::CastOpsBegin]
[secondOp-Instruction::CastOpsBegin];