Don't emit a redundant BitCastInst if the value to be defined in the
authorDan Gohman <gohman@apple.com>
Wed, 24 Jun 2009 00:28:59 +0000 (00:28 +0000)
committerDan Gohman <gohman@apple.com>
Wed, 24 Jun 2009 00:28:59 +0000 (00:28 +0000)
preheader is already an instruction.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74031 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopStrengthReduce.cpp

index ba600584865de85ffd7a19b76663c65b0d387c8f..312b957948ba28a26150088d35209730505f786f 100644 (file)
@@ -1642,7 +1642,8 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEV* const &Stride,
       // the preheader, instead of being forward substituted into the uses.  We
       // do this by forcing a BitCast (noop cast) to be inserted into the
       // preheader in this case.
-      if (!fitsInAddressMode(Base, getAccessType(Inst), TLI, false)) {
+      if (!fitsInAddressMode(Base, getAccessType(Inst), TLI, false) &&
+          !isa<Instruction>(BaseV)) {
         // We want this constant emitted into the preheader! This is just
         // using cast as a copy so BitCast (no-op cast) is appropriate
         BaseV = new BitCastInst(BaseV, BaseV->getType(), "preheaderinsert",