[PATCH] D156141: [NFC][ValueTracking]: Move some code from isKnownNonZero to isKnownNonZeroFromOperator
Dhruv Chawla via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 25 05:40:28 PDT 2023
0xdc03 updated this revision to Diff 543936.
0xdc03 added a comment.
- Address reviewer comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156141/new/
https://reviews.llvm.org/D156141
Files:
llvm/lib/Analysis/ValueTracking.cpp
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -2454,6 +2454,9 @@
unsigned Depth, const SimplifyQuery &Q) {
unsigned BitWidth = getBitWidth(I->getType()->getScalarType(), Q.DL);
switch (I->getOpcode()) {
+ case Instruction::Alloca:
+ // Alloca never returns null, malloc might.
+ return I->getType()->getPointerAddressSpace() == 0;
case Instruction::GetElementPtr:
if (I->getType()->isPointerTy())
return isGEPKnownNonNull(cast<GEPOperator>(I), Depth, Q);
@@ -2688,6 +2691,15 @@
// handled in isKnownNonZero.
return false;
case Instruction::Call:
+ case Instruction::Invoke:
+ if (I->getType()->isPointerTy()) {
+ const auto *Call = cast<CallBase>(I);
+ if (Call->isReturnNonNull())
+ return true;
+ if (const auto *RP = getArgumentAliasingToReturnedPointer(Call, true))
+ return isKnownNonZero(RP, Depth, Q);
+ }
+
if (auto *II = dyn_cast<IntrinsicInst>(I)) {
switch (II->getIntrinsicID()) {
case Intrinsic::sshl_sat:
@@ -2838,10 +2850,6 @@
// Check for pointer simplifications.
if (PointerType *PtrTy = dyn_cast<PointerType>(V->getType())) {
- // Alloca never returns null, malloc might.
- if (isa<AllocaInst>(V) && PtrTy->getAddressSpace() == 0)
- return true;
-
// A byval, inalloca may not be null in a non-default addres space. A
// nonnull argument is assumed never 0.
if (const Argument *A = dyn_cast<Argument>(V)) {
@@ -2850,13 +2858,6 @@
A->hasNonNullAttr()))
return true;
}
-
- if (const auto *Call = dyn_cast<CallBase>(V)) {
- if (Call->isReturnNonNull())
- return true;
- if (const auto *RP = getArgumentAliasingToReturnedPointer(Call, true))
- return isKnownNonZero(RP, Depth, Q);
- }
}
if (const auto *I = dyn_cast<Operator>(V))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156141.543936.patch
Type: text/x-patch
Size: 2025 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230725/eb454892/attachment.bin>
More information about the llvm-commits
mailing list