From be6ceb6ebcfb48e09ffab297c1537c87383f0ce9 Mon Sep 17 00:00:00 2001 From: Nadav Rotem Date: Sun, 28 Aug 2011 11:51:08 +0000 Subject: Bitcasts are transitive. Bitcast-Bitcast-X becomes Bitcast-X. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138722 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ConstantFolding.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/Analysis/ConstantFolding.cpp') diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index df79849c3c..613804d6d2 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -51,6 +51,12 @@ 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(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(DestTy); if (DestVTy == 0) -- cgit v1.2.3-18-g5258