Fix a major pessimization in the instcombiner. If an allocation instruction
authorChris Lattner <sabre@nondot.org>
Fri, 30 Apr 2004 04:37:52 +0000 (04:37 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 30 Apr 2004 04:37:52 +0000 (04:37 +0000)
is only used by a cast, and the casted type is the same size as the original
allocation, it would eliminate the cast by folding it into the allocation.

Unfortunately, it was placing the new allocation instruction right before
the cast, which could pull (for example) alloca instructions into the body
of a function.  This turns statically allocatable allocas into expensive
dynamically allocated allocas, which is bad bad bad.

This fixes the problem by placing the new allocation instruction at the same
place the old one was, duh. :)

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

lib/Transforms/Scalar/InstructionCombining.cpp

index 92b7f1a39bc719a7c367ff8fadc1463d8f10dc2e..18de1269e9d5ab865c56c2fbd27f0b0ad6114530 100644 (file)
@@ -2035,7 +2035,7 @@ Instruction *InstCombiner::visitCastInst(CastInst &CI) {
             New = new MallocInst(CastElTy, Amt, Name);
           else
             New = new AllocaInst(CastElTy, Amt, Name);
-          InsertNewInstBefore(New, CI);
+          InsertNewInstBefore(New, *AI);
           return ReplaceInstUsesWith(CI, New);
         }
       }