[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Apr 29 23:38:01 PDT 2004

Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.194 -> 1.195

Log message:

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

Diffs of the changes:  (+1 -1)

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.194 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.195
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.194	Tue Apr 27 10:12:23 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Thu Apr 29 23:37:52 2004
@@ -2035,7 +2035,7 @@
             New = new MallocInst(CastElTy, Amt, Name);
             New = new AllocaInst(CastElTy, Amt, Name);
-          InsertNewInstBefore(New, CI);
+          InsertNewInstBefore(New, *AI);
           return ReplaceInstUsesWith(CI, New);

More information about the llvm-commits mailing list