From 555518c70f271236c0c8d84d6c640bfb5fbe25a3 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 23 Sep 2002 23:39:43 +0000 Subject: [PATCH] Optimize away cases like: %cast109 = cast uint %cast212 to short ; [#uses=1] %cast214 = cast short %cast109 to uint ; [#uses=1] %cast215 = cast uint %cast214 to short ; [#uses=1] llvm-svn: 3897 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 082dc020b009..b60d1fa9720f 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -536,6 +536,12 @@ static inline bool isEliminableCastOfCast(const CastInst &CI, if (SrcSize >= MidSize && MidSize >= DstSize) return true; + // Cases where the source and destination type are the same, but the middle + // type is bigger are noops. + // + if (SrcSize == DstSize && MidSize > SrcSize) + return true; + // If we are monotonically growing, things are more complex. // if (SrcSize <= MidSize && MidSize <= DstSize) {