for (BasicBlock::iterator BBI = BB.end(); BBI != BB.begin(); ){
--BBI;
- if (deadPointers.empty())
- break;
-
// If we find a store whose pointer is dead...
if (StoreInst* S = dyn_cast<StoreInst>(BBI)) {
if (!S->isVolatile()) {
// See through pointer-to-pointer bitcasts
TranslatePointerBitCasts(pointerOperand);
- if (isa<AllocaInst>(pointerOperand) &&
- deadPointers.count(cast<AllocaInst>(pointerOperand))) {
+ // Alloca'd pointers or byval arguments (which are functionally like
+ // alloca's) are valid candidates for removal.
+ if ( (isa<AllocaInst>(pointerOperand) &&
+ deadPointers.count(cast<AllocaInst>(pointerOperand))) ||
+ (isa<Argument>(pointerOperand) &&
+ cast<Argument>(pointerOperand)->hasByValAttr())) {
// Remove it!
MD.removeInstruction(S);
--- /dev/null
+; RUN: llvm-as < %s | opt -dse | llvm-dis | not grep store
+
+%struct.x = type { i32, i32, i32, i32 }
+
+define i32 @foo(%struct.x* byval %a) nounwind {
+entry:
+ %tmp2 = getelementptr %struct.x* %a, i32 0, i32 0
+ store i32 1, i32* %tmp2, align 4
+ ret i32 1
+}