Fix a major pessimization in the instcombiner. If an allocation instruction

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. :)

llvm-svn: 13289
This commit is contained in:
Chris Lattner 2004-04-30 04:37:52 +00:00
parent 63c3b3c8d7
commit 652064e3b8
1 changed files with 1 additions and 1 deletions

View 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);
}
}