aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2024-05-07 09:47:28 +0900
committerGitHub <noreply@github.com>2024-05-07 09:47:28 +0900
commitf34d30cdae0f59698f660d5cc8fb993fb3441064 (patch)
treece1bf91852bdd4a4bf64aa4f6e802be8499a500a /llvm/lib/Transforms/IPO/FunctionAttrs.cpp
parentde8cf69abf4f8b16d5c5ecb77a6dfb1f5c09e45a (diff)
downloadllvm-f34d30cdae0f59698f660d5cc8fb993fb3441064.zip
llvm-f34d30cdae0f59698f660d5cc8fb993fb3441064.tar.gz
llvm-f34d30cdae0f59698f660d5cc8fb993fb3441064.tar.bz2
[FunctionAttrs] Fix incorrect nonnull inference for non-inbounds GEP (#91180)
For inbounds GEPs, if the source pointer is non-null, the result must also be non-null. However, this does not hold for non-inbounds GEPs. Fixes https://github.com/llvm/llvm-project/issues/91177.
Diffstat (limited to 'llvm/lib/Transforms/IPO/FunctionAttrs.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/FunctionAttrs.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index 8e11cbf..26a4508 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -1186,10 +1186,15 @@ static bool isReturnNonNull(Function *F, const SCCNodeSet &SCCNodes,
switch (RVI->getOpcode()) {
// Extend the analysis by looking upwards.
case Instruction::BitCast:
- case Instruction::GetElementPtr:
case Instruction::AddrSpaceCast:
FlowsToReturn.insert(RVI->getOperand(0));
continue;
+ case Instruction::GetElementPtr:
+ if (cast<GEPOperator>(RVI)->isInBounds()) {
+ FlowsToReturn.insert(RVI->getOperand(0));
+ continue;
+ }
+ return false;
case Instruction::Select: {
SelectInst *SI = cast<SelectInst>(RVI);
FlowsToReturn.insert(SI->getTrueValue());