[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
lattner at cs.uiuc.edu
Fri Mar 19 00:09:01 PST 2004
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.172 -> 1.173
---
Log message:
Teach the optimizer to delete zero sized alloca's (but not mallocs!)
---
Diffs of the changes: (+12 -4)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.172 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.173
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.172 Sat Mar 13 17:54:27 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri Mar 19 00:08:10 2004
@@ -2367,11 +2367,13 @@
// Create and insert the replacement instruction...
if (isa<MallocInst>(AI))
- New = new MallocInst(NewTy, 0, AI.getName(), &AI);
+ New = new MallocInst(NewTy, 0, AI.getName());
else {
assert(isa<AllocaInst>(AI) && "Unknown type of allocation inst!");
- New = new AllocaInst(NewTy, 0, AI.getName(), &AI);
+ New = new AllocaInst(NewTy, 0, AI.getName());
}
+
+ InsertNewInstBefore(New, AI);
// Scan to the end of the allocation instructions, to skip over a block of
// allocas if possible...
@@ -2387,9 +2389,15 @@
// Now make everything use the getelementptr instead of the original
// allocation.
- ReplaceInstUsesWith(AI, V);
- return &AI;
+ return ReplaceInstUsesWith(AI, V);
}
+
+ // If alloca'ing a zero byte object, replace the alloca with a null pointer.
+ // Note that we only do this for alloca's, because malloc should allocate and
+ // return a unique pointer, even for a zero byte allocation.
+ if (isa<AllocaInst>(AI) && TD->getTypeSize(AI.getAllocatedType()) == 0)
+ return ReplaceInstUsesWith(AI, Constant::getNullValue(AI.getType()));
+
return 0;
}
More information about the llvm-commits
mailing list