Eliminate cast of same type instructions.
authorChris Lattner <sabre@nondot.org>
Mon, 15 Apr 2002 19:45:29 +0000 (19:45 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 15 Apr 2002 19:45:29 +0000 (19:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2251 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index fcf3707bac1a1041b3f6ec28b4caa29ab245cf92..0bcd6f1534a36d0575b62735a3c20c28c2b97827 100644 (file)
@@ -18,6 +18,7 @@
 #include "llvm/ConstantHandling.h"
 #include "llvm/Function.h"
 #include "llvm/iMemory.h"
+#include "llvm/iOther.h"
 #include "llvm/InstrTypes.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/InstIterator.h"
@@ -138,6 +139,13 @@ static bool CombineInstruction(Instruction *I) {
     Result = CombineBinOp(BOP);
   else if (MemAccessInst *MAI = dyn_cast<MemAccessInst>(I))
     Result = CombineIndicies(MAI);
+  else if (CastInst *CI = dyn_cast<CastInst>(I)) {
+    if (CI->getType() == CI->getOperand(0)->getType() && !CI->use_empty()) {
+      CI->replaceAllUsesWith(CI->getOperand(0));
+      return true;
+    }
+      
+  }
 
   if (!Result) return false;
   if (Result == I) return true;