[PATCH] D156141: [NFC][ValueTracking]: Move some code from isKnownNonZero to isKnownNonZeroFromOperator
Dhruv Chawla via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 24 10:11:44 PDT 2023
0xdc03 created this revision.
0xdc03 added a reviewer: nikic.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
0xdc03 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
There is some pointer simplification code originally from isKnownNonNull
that is now better suited to be in isKnownNonZeroFromOperator.
Repository:
rG LLVM Github Monorepo
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,12 @@
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.
+ if (PointerType *PtrTy = dyn_cast<PointerType>(I->getType());
+ PtrTy && PtrTy->getAddressSpace() == 0)
+ return true;
+ break;
case Instruction::GetElementPtr:
if (I->getType()->isPointerTy())
return isGEPKnownNonNull(cast<GEPOperator>(I), Depth, Q);
@@ -2688,6 +2694,13 @@
// handled in isKnownNonZero.
return false;
case Instruction::Call:
+ if (const auto *Call = dyn_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 +2851,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 +2859,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.543612.patch
Type: text/x-patch
Size: 2056 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230724/c1a31d56/attachment-0001.bin>
More information about the llvm-commits
mailing list