aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/GlobalStatus.cpp
diff options
context:
space:
mode:
authorShimin Cui <scui@ca.ibm.com>2021-07-31 18:42:02 -0400
committerShimin Cui <scui@ca.ibm.com>2021-07-31 18:42:02 -0400
commit732b05555c71cfdbf135a100a06472c5efc4eefb (patch)
tree5ae1307296a23e9e5ab43ed0749cc5e11ff393b0 /llvm/lib/Transforms/Utils/GlobalStatus.cpp
parent6ef6616e07f5be69557e744fc28459d6051cfa9c (diff)
downloadllvm-732b05555c71cfdbf135a100a06472c5efc4eefb.zip
llvm-732b05555c71cfdbf135a100a06472c5efc4eefb.tar.gz
llvm-732b05555c71cfdbf135a100a06472c5efc4eefb.tar.bz2
[GlobalOpt] support ConstantExpr use of global address for OptimizeGlobalAddressOfMalloc
I'm working on extending the OptimizeGlobalAddressOfMalloc to handle some more general cases. This is to add support of the ConstantExpr use of the global variables. The function allUsesOfLoadedValueWillTrapIfNull is now iterative with the added CE use of GV. Also, the recursive function valueIsOnlyUsedLocallyOrStoredToOneGlobal is changed to iterative using a worklist with the GEP case added. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D106589
Diffstat (limited to 'llvm/lib/Transforms/Utils/GlobalStatus.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/GlobalStatus.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/GlobalStatus.cpp b/llvm/lib/Transforms/Utils/GlobalStatus.cpp
index f782396..4c3e164 100644
--- a/llvm/lib/Transforms/Utils/GlobalStatus.cpp
+++ b/llvm/lib/Transforms/Utils/GlobalStatus.cpp
@@ -105,8 +105,10 @@ static bool analyzeGlobalAux(const Value *V, GlobalStatus &GS,
// value, not an aggregate), keep more specific information about
// stores.
if (GS.StoredType != GlobalStatus::Stored) {
- if (const GlobalVariable *GV =
- dyn_cast<GlobalVariable>(SI->getOperand(1))) {
+ const Value *Ptr = SI->getPointerOperand();
+ if (isa<ConstantExpr>(Ptr))
+ Ptr = Ptr->stripPointerCasts();
+ if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Ptr)) {
Value *StoredVal = SI->getOperand(0);
if (Constant *C = dyn_cast<Constant>(StoredVal)) {