summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorDavid Stenberg <david.stenberg@ericsson.com>2018-12-11 10:33:38 +0000
committerDavid Stenberg <david.stenberg@ericsson.com>2018-12-11 10:33:38 +0000
commit2474ce586227b5c11bc50994841281dbaff129d8 (patch)
tree438b4b26e179f50185163d576a9bee5d98269639 /llvm/lib/Transforms
parent4862ff8d17dd8e2bd47394f6c368c2e2c9609c39 (diff)
downloadbcm5719-llvm-2474ce586227b5c11bc50994841281dbaff129d8.tar.gz
bcm5719-llvm-2474ce586227b5c11bc50994841281dbaff129d8.zip
[DeadArgElim] Fixes for dbg.values using dead arg/return values
Summary: When eliminating a dead argument or return value in a function with local linkage, all uses, including in dbg.value intrinsics, would be replaced with null constants. This would mean that, for example for an integer argument, the debug info would incorrectly express that the value is 0. Instead, replace all uses with undef to indicate that the argument/return value is optimized out. Also, make sure that metadata uses of return values are rewritten even if there are no non-metadata uses of the value. As a bit of historical curiosity, the code that emitted null constants was introduced in the initial check-in of the pass in 2003, before 'undef' values even existed in LLVM. This fixes PR23260. Reviewers: dblaikie, aprantl, vsk, djtodoro Reviewed By: aprantl Subscribers: llvm-commits Tags: #debug-info Differential Revision: https://reviews.llvm.org/D55513 llvm-svn: 348837
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
index 0cf238b5d60..cffb3325f1c 100644
--- a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
+++ b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
@@ -24,7 +24,6 @@
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CallSite.h"
-#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
@@ -954,16 +953,16 @@ bool DeadArgumentEliminationPass::RemoveDeadStuffFromFunction(Function *F) {
ArgAttrVec.clear();
Instruction *New = NewCS.getInstruction();
- if (!Call->use_empty()) {
+ if (!Call->use_empty() || Call->isUsedByMetadata()) {
if (New->getType() == Call->getType()) {
// Return type not changed? Just replace users then.
Call->replaceAllUsesWith(New);
New->takeName(Call);
} else if (New->getType()->isVoidTy()) {
- // Our return value has uses, but they will get removed later on.
- // Replace by null for now.
+ // If the return value is dead, replace any uses of it with undef
+ // (any non-debug value uses will get removed later on).
if (!Call->getType()->isX86_MMXTy())
- Call->replaceAllUsesWith(Constant::getNullValue(Call->getType()));
+ Call->replaceAllUsesWith(UndefValue::get(Call->getType()));
} else {
assert((RetTy->isStructTy() || RetTy->isArrayTy()) &&
"Return type changed, but not into a void. The old return type"
@@ -1023,10 +1022,10 @@ bool DeadArgumentEliminationPass::RemoveDeadStuffFromFunction(Function *F) {
I2->takeName(&*I);
++I2;
} else {
- // If this argument is dead, replace any uses of it with null constants
- // (these are guaranteed to become unused later on).
+ // If this argument is dead, replace any uses of it with undef
+ // (any non-debug value uses will get removed later on).
if (!I->getType()->isX86_MMXTy())
- I->replaceAllUsesWith(Constant::getNullValue(I->getType()));
+ I->replaceAllUsesWith(UndefValue::get(I->getType()));
}
// If we change the return value of the function we must rewrite any return
OpenPOWER on IntegriCloud