[PATCH] D59661: [GVN] Try to be more permissive with non-integral pointers zeros [NFCI]
Jameson Nash via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 6 10:18:26 PST 2019
vtjnash updated this revision to Diff 228092.
vtjnash edited the summary of this revision.
vtjnash added a comment.
Herald added a subscriber: hiraditya.
Split commit into two pieces, each more clearly NFCI
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D59661/new/
https://reviews.llvm.org/D59661
Files:
llvm/lib/Transforms/Utils/VNCoercion.cpp
Index: llvm/lib/Transforms/Utils/VNCoercion.cpp
===================================================================
--- llvm/lib/Transforms/Utils/VNCoercion.cpp
+++ llvm/lib/Transforms/Utils/VNCoercion.cpp
@@ -11,10 +11,8 @@
namespace llvm {
namespace VNCoercion {
-/// Return true if coerceAvailableValueToLoadType will succeed.
-bool canCoerceMustAliasedValueToLoad(Value *StoredVal, Type *LoadTy,
+bool canCoerceMustAliasedValueToLoad(Type *StoredTy, Type *LoadTy,
const DataLayout &DL) {
- Type *StoredTy = StoredVal->getType();
if (StoredTy == LoadTy)
return true;
@@ -35,19 +33,24 @@
return false;
// Don't coerce non-integral pointers to integers or vice versa.
- if (DL.isNonIntegralPointerType(StoredVal->getType()->getScalarType()) !=
- DL.isNonIntegralPointerType(LoadTy->getScalarType())) {
- // As a special case, allow coercion of memset used to initialize
- // an array w/null. Despite non-integral pointers not generally having a
- // specific bit pattern, we do assume null is zero.
- if (auto *CI = dyn_cast<Constant>(StoredVal))
- return CI->isNullValue();
+ if (DL.isNonIntegralPointerType(StoredTy->getScalarType()) !=
+ DL.isNonIntegralPointerType(LoadTy->getScalarType()))
return false;
- }
-
+
return true;
}
+/// Return true if coerceAvailableValueToLoadType will succeed.
+bool canCoerceMustAliasedValueToLoad(Value *StoredVal, Type *LoadTy,
+ const DataLayout &DL) {
+ Type *StoredTy = StoredVal->getType();
+ if (auto *CI = dyn_cast<Constant>(StoredVal))
+ if (CI->isNullValue())
+ if (StoredTy == LoadTy || DL.getTypeSizeInBits(StoredTy) >= DL.getTypeSizeInBits(LoadTy))
+ return true;
+ return canCoerceMustAliasedValueToLoad(StoredTy, LoadTy, DL);
+}
+
template <class T, class HelperClass>
static T *coerceAvailableValueToLoadTypeHelper(T *StoredVal, Type *LoadedTy,
HelperClass &Helper,
@@ -341,6 +344,9 @@
HelperClass &Helper,
const DataLayout &DL) {
LLVMContext &Ctx = SrcVal->getType()->getContext();
+ if (auto *CI = dyn_cast<Constant>(GetUnderlyingObject(SrcVal, DL)))
+ if (CI->isNullValue())
+ return Constant::getNullValue(LoadTy);
// If two pointers are in the same address space, they have the same size,
// so we don't need to do any truncation, etc. This avoids introducing
@@ -468,6 +474,12 @@
// memset(P, 'x', 1234) -> splat('x'), even if x is a variable, and
// independently of what the offset is.
T *Val = cast<T>(MSI->getValue());
+ if (auto *CI = dyn_cast<Constant>(Val)) {
+ // memset(P, '\0', 1234) -> just directly create the null value for *P
+ // by-passing any later validity checks
+ if (CI->isNullValue())
+ return Constant::getNullValue(LoadTy);
+ }
if (LoadSize != 1)
Val =
Helper.CreateZExtOrBitCast(Val, IntegerType::get(Ctx, LoadSize * 8));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59661.228092.patch
Type: text/x-patch
Size: 3092 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191106/4573be49/attachment-0001.bin>
More information about the llvm-commits
mailing list