aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2022-10-04 11:08:45 +0200
committerNikita Popov <npopov@redhat.com>2022-10-04 11:58:07 +0200
commit6e504d637dcf757c8840c36b01b03344c6b15cff (patch)
tree587ac79f7d0a57071aff7c7417bf322f9abe96ff /llvm/lib/Analysis/ValueTracking.cpp
parent0d30e92f59589de44a185c53671b7fe2e83cd2ae (diff)
downloadllvm-6e504d637dcf757c8840c36b01b03344c6b15cff.zip
llvm-6e504d637dcf757c8840c36b01b03344c6b15cff.tar.gz
llvm-6e504d637dcf757c8840c36b01b03344c6b15cff.tar.bz2
[ValueTracking] Handle constant exprs in isKnownNonZero()
Handle constant expressions by falling through to the general operator-based code. In particular, this adds support for bitcast and GEP expressions.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp20
1 files changed, 7 insertions, 13 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 81f606f..95f6e5d 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2481,16 +2481,6 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
// Must be non-zero due to null test above.
return true;
- if (auto *CE = dyn_cast<ConstantExpr>(C)) {
- // See the comment for IntToPtr/PtrToInt instructions below.
- if (CE->getOpcode() == Instruction::IntToPtr ||
- CE->getOpcode() == Instruction::PtrToInt)
- if (Q.DL.getTypeSizeInBits(CE->getOperand(0)->getType())
- .getFixedSize() <=
- Q.DL.getTypeSizeInBits(CE->getType()).getFixedSize())
- return isKnownNonZero(CE->getOperand(0), Depth, Q);
- }
-
// For constant vectors, check that all elements are undefined or known
// non-zero to determine that the whole vector is known non-zero.
if (auto *VecTy = dyn_cast<FixedVectorType>(C->getType())) {
@@ -2513,7 +2503,10 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
if (!GV->isAbsoluteSymbolRef() && !GV->hasExternalWeakLinkage() &&
GV->getType()->getAddressSpace() == 0)
return true;
- } else
+ }
+
+ // For constant expressions, fall through to the Operator code below.
+ if (!isa<ConstantExpr>(V))
return false;
}
@@ -2529,7 +2522,7 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
}
}
- if (isKnownNonZeroFromAssume(V, Q))
+ if (!isa<Constant>(V) && isKnownNonZeroFromAssume(V, Q))
return true;
// Some of the tests below are recursive, so bail out if we hit the limit.
@@ -2565,7 +2558,8 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
}
}
- if (isKnownNonNullFromDominatingCondition(V, Q.CxtI, Q.DT))
+ if (!isa<Constant>(V) &&
+ isKnownNonNullFromDominatingCondition(V, Q.CxtI, Q.DT))
return true;
const Operator *I = dyn_cast<Operator>(V);