jmciver updated this revision to Diff 542618. jmciver added a comment. Remove reliance on TLI objects where only alloca instructions are processes
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D155773/new/ https://reviews.llvm.org/D155773 Files: llvm/include/llvm/Analysis/MemoryBuiltins.h llvm/lib/Analysis/MemoryBuiltins.cpp llvm/lib/Transforms/Scalar/GVN.cpp llvm/lib/Transforms/Scalar/NewGVN.cpp llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
Index: llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp =================================================================== --- llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -24,6 +24,7 @@ #include "llvm/Analysis/AssumptionCache.h" #include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/IteratedDominanceFrontier.h" +#include "llvm/Analysis/MemoryBuiltins.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/CFG.h" @@ -600,7 +601,7 @@ if (I == StoresByIndex.begin()) { if (StoresByIndex.empty()) // If there are no stores, the load takes the undef value. - ReplVal = UndefValue::get(LI->getType()); + ReplVal = getInitialValueOfAllocation(AI, nullptr, LI->getType()); else // There is no store before this load, bail out (load may be affected // by the following stores - see main comment). Index: llvm/lib/Transforms/Scalar/NewGVN.cpp =================================================================== --- llvm/lib/Transforms/Scalar/NewGVN.cpp +++ llvm/lib/Transforms/Scalar/NewGVN.cpp @@ -1489,21 +1489,18 @@ if (LoadPtr != lookupOperandLeader(DepInst) && !AA->isMustAlias(LoadPtr, DepInst)) return nullptr; - // If this load really doesn't depend on anything, then we must be loading an - // undef value. This can happen when loading for a fresh allocation with no - // intervening stores, for example. Note that this is only true in the case - // that the result of the allocation is pointer equal to the load ptr. - if (isa<AllocaInst>(DepInst)) { - return createConstantExpression(UndefValue::get(LoadType)); - } // If this load occurs either right after a lifetime begin, // then the loaded value is undefined. - else if (auto *II = dyn_cast<IntrinsicInst>(DepInst)) { + if (auto *II = dyn_cast<IntrinsicInst>(DepInst)) { if (II->getIntrinsicID() == Intrinsic::lifetime_start) return createConstantExpression(UndefValue::get(LoadType)); - } else if (auto *InitVal = - getInitialValueOfAllocation(DepInst, TLI, LoadType)) - return createConstantExpression(InitVal); + } + // If this load really doesn't depend on anything, then we must be loading an + // undef value. This can happen when loading for a fresh allocation with no + // intervening stores, for example. Note that this is only true in the case + // that the result of the allocation is pointer equal to the load ptr. + else if (auto *InitVal = getInitialValueOfAllocation(DepInst, TLI, LoadType)) + return createConstantExpression(InitVal); return nullptr; } Index: llvm/lib/Transforms/Scalar/GVN.cpp =================================================================== --- llvm/lib/Transforms/Scalar/GVN.cpp +++ llvm/lib/Transforms/Scalar/GVN.cpp @@ -1240,11 +1240,12 @@ } assert(DepInfo.isDef() && "follows from above"); - // Loading the alloca -> undef. // Loading immediately after lifetime begin -> undef. - if (isa<AllocaInst>(DepInst) || isLifetimeStart(DepInst)) + if (isLifetimeStart(DepInst)) return AvailableValue::get(UndefValue::get(Load->getType())); + // In addition to allocator function calls this includes loading the alloca -> + // undef. if (Constant *InitVal = getInitialValueOfAllocation(DepInst, TLI, Load->getType())) return AvailableValue::get(InitVal); Index: llvm/lib/Analysis/MemoryBuiltins.cpp =================================================================== --- llvm/lib/Analysis/MemoryBuiltins.cpp +++ llvm/lib/Analysis/MemoryBuiltins.cpp @@ -436,6 +436,9 @@ Constant *llvm::getInitialValueOfAllocation(const Value *V, const TargetLibraryInfo *TLI, Type *Ty) { + if (isa<AllocaInst>(V)) + return UndefValue::get(Ty); + auto *Alloc = dyn_cast<CallBase>(V); if (!Alloc) return nullptr; Index: llvm/include/llvm/Analysis/MemoryBuiltins.h =================================================================== --- llvm/include/llvm/Analysis/MemoryBuiltins.h +++ llvm/include/llvm/Analysis/MemoryBuiltins.h @@ -119,8 +119,8 @@ }); /// If this is a call to an allocation function that initializes memory to a -/// fixed value, return said value in the requested type. Otherwise, return -/// nullptr. +/// fixed value, return said value in the requested type. If this is a call to +/// alloca instruction the returned value is undef. Otherwise, return nullptr. Constant *getInitialValueOfAllocation(const Value *V, const TargetLibraryInfo *TLI, Type *Ty);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits