[llvm] [InstCombine] Fix select combine with null_pointer_is_valid. (PR #227168)
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 30 09:49:44 PDT 2026
https://github.com/efriedma-quic updated https://github.com/llvm/llvm-project/pull/227168
>From a9d8aaf84e8680afb16ea401a7726e99452bf55f Mon Sep 17 00:00:00 2001
From: Eli Friedman <efriedma at qti.qualcomm.com>
Date: Mon, 28 Sep 2026 17:46:43 -0700
Subject: [PATCH 1/5] [InstCombine] Fix select combine with
null_pointer_is_valid.
When null_pointer_is_valid is set, make sure we don't treat an inbounds
gep of "ptr null" as poison.
While I'm here, also write out the justification of
simplifyNonNullOperand, since it's pretty unintuitive.
Fixes #227002
---
.../InstCombine/InstCombineCalls.cpp | 19 ++++++++++++-------
.../InstCombineLoadStoreAlloca.cpp | 11 +++++++++++
.../Transforms/InstCombine/nonnull-select.ll | 13 +++++++++++++
3 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 86dd4397f22c9..e139975fce9d8 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -5046,18 +5046,23 @@ Instruction *InstCombinerImpl::visitCallBase(CallBase &Call) {
for (Value *V : Call.args()) {
if (V->getType()->isPointerTy()) {
- // Simplify the nonnull operand if the parameter is known to be nonnull.
- // Otherwise, try to infer nonnull for it.
+ // If the operand is dereferenceable, it must be a valid pointer to a
+ // part of some object which is not located at null. If the operand is
+ // marked nonnull, it must not be null. Try to simplify the argument
+ // based on this.
+ //
+ // Otherwise, try to infer nonnull.
bool HasDereferenceable = Call.getParamDereferenceableBytes(ArgNo) > 0;
- if (Call.paramHasAttr(ArgNo, Attribute::NonNull) ||
- (HasDereferenceable &&
- !NullPointerIsDefined(Call.getFunction(),
- V->getType()->getPointerAddressSpace()))) {
+ if ((Call.paramHasAttr(ArgNo, Attribute::NonNull) ||
+ HasDereferenceable) &&
+ !NullPointerIsDefined(Call.getFunction(),
+ V->getType()->getPointerAddressSpace())) {
if (Value *Res = simplifyNonNullOperand(V, HasDereferenceable)) {
replaceOperand(Call, ArgNo, Res);
Changed = true;
}
- } else if (isKnownNonZero(V,
+ } else if (!Call.paramHasAttr(ArgNo, Attribute::NonNull) &&
+ isKnownNonZero(V,
getSimplifyQuery().getWithInstruction(&Call))) {
ArgNos.push_back(ArgNo);
}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 8e2a0c5376d8e..181754c9c30f3 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -1063,6 +1063,17 @@ Value *InstCombinerImpl::simplifyNonNullOperand(Value *V,
return nullptr;
if (auto *GEP = dyn_cast<GetElementPtrInst>(V)) {
+ // We know by precondition that null pointers are not defined in this
+ // address-space.
+ //
+ // If HasDereferenceable is true, we know that the GEP does not have null
+ // provenance. Therefore, the operand must also not have null provenance.
+ // We assume ConstantPointerNull does not have provenance. (The address
+ // could be equal to zero, but that doesn't matter.)
+ //
+ // If HasDeferenceable is false, we know that the address is some non-zero
+ // value. If the GEP is inbounds, the operand must also have a non-zero
+ // value.
if (HasDereferenceable || GEP->isInBounds()) {
if (auto *Res = simplifyNonNullOperand(GEP->getPointerOperand(),
HasDereferenceable, Depth + 1)) {
diff --git a/llvm/test/Transforms/InstCombine/nonnull-select.ll b/llvm/test/Transforms/InstCombine/nonnull-select.ll
index 929919f9c42c7..10b3fa5f16003 100644
--- a/llvm/test/Transforms/InstCombine/nonnull-select.ll
+++ b/llvm/test/Transforms/InstCombine/nonnull-select.ll
@@ -141,6 +141,19 @@ define void @nonnull_call_gep_inbounds(i1 %cond, ptr %p, i64 %off) {
ret void
}
+define void @nonnull_call_gep_inbounds_nullvalid(i1 %cond, ptr %p, i64 %off) null_pointer_is_valid {
+; CHECK-LABEL: @nonnull_call_gep_inbounds_nullvalid(
+; CHECK-NEXT: [[P:%.*]] = select i1 [[COND:%.*]], ptr null, ptr [[P1:%.*]]
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 [[OFF:%.*]]
+; CHECK-NEXT: call void @f(ptr nonnull [[GEP]])
+; CHECK-NEXT: ret void
+;
+ %ptr = select i1 %cond, ptr null, ptr %p
+ %gep = getelementptr inbounds i8, ptr %ptr, i64 %off
+ call void @f(ptr nonnull %gep)
+ ret void
+}
+
define void @nonnull_dereferenceable_call_gep(i1 %cond, ptr %p, i64 %off) {
; CHECK-LABEL: @nonnull_dereferenceable_call_gep(
; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[PTR:%.*]], i64 [[OFF:%.*]]
>From 138d256dab7f2d269736949f599ff7ab26d14dd0 Mon Sep 17 00:00:00 2001
From: Eli Friedman <efriedma at qti.qualcomm.com>
Date: Mon, 28 Sep 2026 19:18:05 -0700
Subject: [PATCH 2/5] Also fix ret. Allow transforming cases which don't
involve GEP.
---
.../InstCombine/InstCombineCalls.cpp | 19 ++++-----
.../InstCombineLoadStoreAlloca.cpp | 20 ++++-----
.../InstCombine/InstructionCombining.cpp | 7 ++--
.../Transforms/InstCombine/nonnull-select.ll | 42 +++++++++++++++++++
4 files changed, 62 insertions(+), 26 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index e139975fce9d8..da783a41d46b2 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -5046,23 +5046,18 @@ Instruction *InstCombinerImpl::visitCallBase(CallBase &Call) {
for (Value *V : Call.args()) {
if (V->getType()->isPointerTy()) {
- // If the operand is dereferenceable, it must be a valid pointer to a
- // part of some object which is not located at null. If the operand is
- // marked nonnull, it must not be null. Try to simplify the argument
- // based on this.
- //
- // Otherwise, try to infer nonnull.
- bool HasDereferenceable = Call.getParamDereferenceableBytes(ArgNo) > 0;
- if ((Call.paramHasAttr(ArgNo, Attribute::NonNull) ||
- HasDereferenceable) &&
+ // Simplify the nonnull operand if the parameter is known to be nonnull.
+ // Otherwise, try to infer nonnull for it.
+ bool HasDereferenceable =
+ Call.getParamDereferenceableBytes(ArgNo) > 0 &&
!NullPointerIsDefined(Call.getFunction(),
- V->getType()->getPointerAddressSpace())) {
+ V->getType()->getPointerAddressSpace());
+ if (Call.paramHasAttr(ArgNo, Attribute::NonNull) || HasDereferenceable) {
if (Value *Res = simplifyNonNullOperand(V, HasDereferenceable)) {
replaceOperand(Call, ArgNo, Res);
Changed = true;
}
- } else if (!Call.paramHasAttr(ArgNo, Attribute::NonNull) &&
- isKnownNonZero(V,
+ } else if (isKnownNonZero(V,
getSimplifyQuery().getWithInstruction(&Call))) {
ArgNos.push_back(ArgNo);
}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 181754c9c30f3..544e421f8b115 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -1063,18 +1063,18 @@ Value *InstCombinerImpl::simplifyNonNullOperand(Value *V,
return nullptr;
if (auto *GEP = dyn_cast<GetElementPtrInst>(V)) {
- // We know by precondition that null pointers are not defined in this
- // address-space.
- //
- // If HasDereferenceable is true, we know that the GEP does not have null
- // provenance. Therefore, the operand must also not have null provenance.
- // We assume ConstantPointerNull does not have provenance. (The address
- // could be equal to zero, but that doesn't matter.)
+ // If HasDereferenceable is true, we know by precondition that null pointers
+ // are not defined in this address-space. And we know that the GEP has
+ // provenance for a valid object. Therefore, the operand must also have
+ // valid provenance. We assume ConstantPointerNull does not have provenance.
+ // (The address could be equal to zero, but that doesn't matter.)
//
// If HasDeferenceable is false, we know that the address is some non-zero
- // value. If the GEP is inbounds, the operand must also have a non-zero
- // value.
- if (HasDereferenceable || GEP->isInBounds()) {
+ // value. If the GEP is inbounds, and null pointers can't point to valid
+ // objects, the operand must also have a non-zero value.
+ if (HasDereferenceable ||
+ (GEP->isInBounds() &&
+ !NullPointerIsDefined(GEP->getFunction(), GEP->getAddressSpace()))) {
if (auto *Res = simplifyNonNullOperand(GEP->getPointerOperand(),
HasDereferenceable, Depth + 1)) {
replaceOperand(*GEP, 0, Res);
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 4b09510933d0c..35c5483709e16 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -4172,10 +4172,9 @@ Instruction *InstCombinerImpl::visitReturnInst(ReturnInst &RI) {
Type *RetTy = RetVal->getType();
if (RetTy->isPointerTy()) {
bool HasDereferenceable =
- F->getAttributes().getRetDereferenceableBytes() > 0;
- if (F->hasRetAttribute(Attribute::NonNull) ||
- (HasDereferenceable &&
- !NullPointerIsDefined(F, RetTy->getPointerAddressSpace()))) {
+ F->getAttributes().getRetDereferenceableBytes() > 0 &&
+ !NullPointerIsDefined(F, RetTy->getPointerAddressSpace());
+ if (F->hasRetAttribute(Attribute::NonNull) || HasDereferenceable) {
if (Value *V = simplifyNonNullOperand(RetVal, HasDereferenceable))
return replaceOperand(RI, 0, V);
}
diff --git a/llvm/test/Transforms/InstCombine/nonnull-select.ll b/llvm/test/Transforms/InstCombine/nonnull-select.ll
index 10b3fa5f16003..d486529993787 100644
--- a/llvm/test/Transforms/InstCombine/nonnull-select.ll
+++ b/llvm/test/Transforms/InstCombine/nonnull-select.ll
@@ -21,6 +21,14 @@ define nonnull ptr @nonnull_ret(i1 %cond, ptr %p) {
ret ptr %res
}
+define nonnull ptr @nonnull_ret_nullvalid(i1 %cond, ptr %p) null_pointer_is_valid {
+; CHECK-LABEL: @nonnull_ret_nullvalid(
+; CHECK-NEXT: ret ptr [[P:%.*]]
+;
+ %res = select i1 %cond, ptr %p, ptr null
+ ret ptr %res
+}
+
define nonnull ptr @nonnull_ret2(i1 %cond, ptr %p) {
; CHECK-LABEL: @nonnull_ret2(
; CHECK-NEXT: ret ptr [[RES:%.*]]
@@ -56,6 +64,16 @@ define void @nonnull_call(i1 %cond, ptr %p) {
ret void
}
+define void @nonnull_call_nullvalid(i1 %cond, ptr %p) null_pointer_is_valid {
+; CHECK-LABEL: @nonnull_call_nullvalid(
+; CHECK-NEXT: call void @f(ptr nonnull [[P:%.*]])
+; CHECK-NEXT: ret void
+;
+ %res = select i1 %cond, ptr %p, ptr null
+ call void @f(ptr nonnull %res)
+ ret void
+}
+
define void @nonnull_call2(i1 %cond, ptr %p) {
; CHECK-LABEL: @nonnull_call2(
; CHECK-NEXT: call void @f(ptr nonnull [[RES:%.*]])
@@ -166,6 +184,19 @@ define void @nonnull_dereferenceable_call_gep(i1 %cond, ptr %p, i64 %off) {
ret void
}
+define void @nonnull_dereferenceable_call_gep_nullvalid(i1 %cond, ptr %p, i64 %off) null_pointer_is_valid {
+; CHECK-LABEL: @nonnull_dereferenceable_call_gep_nullvalid(
+; CHECK-NEXT: [[P:%.*]] = select i1 [[COND:%.*]], ptr null, ptr [[P1:%.*]]
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[P]], i64 [[OFF:%.*]]
+; CHECK-NEXT: call void @f(ptr dereferenceable(1) [[GEP]])
+; CHECK-NEXT: ret void
+;
+ %ptr = select i1 %cond, ptr null, ptr %p
+ %gep = getelementptr i8, ptr %ptr, i64 %off
+ call void @f(ptr dereferenceable(1) %gep)
+ ret void
+}
+
define nonnull ptr @nonnull_ret_gep(i1 %cond, ptr %p, i64 %off) {
; CHECK-LABEL: @nonnull_ret_gep(
; CHECK-NEXT: [[PTR:%.*]] = select i1 [[COND:%.*]], ptr null, ptr [[P:%.*]]
@@ -187,6 +218,17 @@ define nonnull ptr @nonnull_ret_gep_inbounds(i1 %cond, ptr %p, i64 %off) {
ret ptr %gep
}
+define nonnull ptr @nonnull_ret_gep_inbounds_nullvalid(i1 %cond, ptr %p, i64 %off) null_pointer_is_valid {
+; CHECK-LABEL: @nonnull_ret_gep_inbounds_nullvalid(
+; CHECK-NEXT: [[PTR:%.*]] = select i1 [[COND:%.*]], ptr null, ptr [[P:%.*]]
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i64 [[OFF:%.*]]
+; CHECK-NEXT: ret ptr [[GEP]]
+;
+ %ptr = select i1 %cond, ptr null, ptr %p
+ %gep = getelementptr inbounds i8, ptr %ptr, i64 %off
+ ret ptr %gep
+}
+
define dereferenceable(1) ptr @nonnull_dereferenceable_ret_gep(i1 %cond, ptr %p, i64 %off) {
; CHECK-LABEL: @nonnull_dereferenceable_ret_gep(
; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[PTR:%.*]], i64 [[OFF:%.*]]
>From 23acf6c3f953f60a62e8ee2628a4b8e892373c66 Mon Sep 17 00:00:00 2001
From: Eli Friedman <efriedma at qti.qualcomm.com>
Date: Tue, 29 Sep 2026 21:20:27 -0700
Subject: [PATCH 3/5] Rename argument
---
.../Transforms/InstCombine/InstCombineCalls.cpp | 6 +++---
.../Transforms/InstCombine/InstCombineInternal.h | 7 ++++---
.../InstCombine/InstCombineLoadStoreAlloca.cpp | 16 ++++++++--------
.../InstCombine/InstructionCombining.cpp | 6 +++---
4 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index da783a41d46b2..25781b49fe67e 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -5048,12 +5048,12 @@ Instruction *InstCombinerImpl::visitCallBase(CallBase &Call) {
if (V->getType()->isPointerTy()) {
// Simplify the nonnull operand if the parameter is known to be nonnull.
// Otherwise, try to infer nonnull for it.
- bool HasDereferenceable =
+ bool UseProvenance =
Call.getParamDereferenceableBytes(ArgNo) > 0 &&
!NullPointerIsDefined(Call.getFunction(),
V->getType()->getPointerAddressSpace());
- if (Call.paramHasAttr(ArgNo, Attribute::NonNull) || HasDereferenceable) {
- if (Value *Res = simplifyNonNullOperand(V, HasDereferenceable)) {
+ if (Call.paramHasAttr(ArgNo, Attribute::NonNull) || UseProvenance) {
+ if (Value *Res = simplifyNonNullOperand(V, UseProvenance)) {
replaceOperand(Call, ArgNo, Res);
Changed = true;
}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index f2549bad3a852..2ab004ce37e09 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -468,9 +468,10 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
/// Simplify \p V given that it is known to be non-null.
/// Returns the simplified value if possible, otherwise returns nullptr.
- /// If \p HasDereferenceable is true, the simplification will not perform
- /// same object checks.
- Value *simplifyNonNullOperand(Value *V, bool HasDereferenceable,
+ /// If \p UseProvenance is true, the simplification will use provenance-based
+ /// reasoning (if the pointer is known to be dereferenceable in an
+ /// address-space where null is not defined).
+ Value *simplifyNonNullOperand(Value *V, bool UseProvenance,
unsigned Depth = 0);
/// Create `select C, S1, S2`. Use only when the profile cannot be calculated
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 544e421f8b115..a5688ee521a5f 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -1045,7 +1045,7 @@ static bool canSimplifyNullLoadOrGEP(LoadInst &LI, Value *Op) {
}
Value *InstCombinerImpl::simplifyNonNullOperand(Value *V,
- bool HasDereferenceable,
+ bool UseProvenance,
unsigned Depth) {
if (auto *Sel = dyn_cast<SelectInst>(V)) {
if (isa<ConstantPointerNull>(Sel->getOperand(1)))
@@ -1063,8 +1063,8 @@ Value *InstCombinerImpl::simplifyNonNullOperand(Value *V,
return nullptr;
if (auto *GEP = dyn_cast<GetElementPtrInst>(V)) {
- // If HasDereferenceable is true, we know by precondition that null pointers
- // are not defined in this address-space. And we know that the GEP has
+ // If UseProvenance is true, we know by precondition that null pointers are
+ // not defined in this address-space. And we know that the GEP has
// provenance for a valid object. Therefore, the operand must also have
// valid provenance. We assume ConstantPointerNull does not have provenance.
// (The address could be equal to zero, but that doesn't matter.)
@@ -1072,11 +1072,11 @@ Value *InstCombinerImpl::simplifyNonNullOperand(Value *V,
// If HasDeferenceable is false, we know that the address is some non-zero
// value. If the GEP is inbounds, and null pointers can't point to valid
// objects, the operand must also have a non-zero value.
- if (HasDereferenceable ||
+ if (UseProvenance ||
(GEP->isInBounds() &&
!NullPointerIsDefined(GEP->getFunction(), GEP->getAddressSpace()))) {
if (auto *Res = simplifyNonNullOperand(GEP->getPointerOperand(),
- HasDereferenceable, Depth + 1)) {
+ UseProvenance, Depth + 1)) {
replaceOperand(*GEP, 0, Res);
addToWorklist(GEP);
return nullptr;
@@ -1088,7 +1088,7 @@ Value *InstCombinerImpl::simplifyNonNullOperand(Value *V,
bool Changed = false;
for (Use &U : PHI->incoming_values()) {
// We set Depth to RecursionLimit to avoid expensive recursion.
- if (auto *Res = simplifyNonNullOperand(U.get(), HasDereferenceable,
+ if (auto *Res = simplifyNonNullOperand(U.get(), UseProvenance,
RecursionLimit)) {
replaceUse(U, Res);
Changed = true;
@@ -1197,7 +1197,7 @@ Instruction *InstCombinerImpl::visitLoadInst(LoadInst &LI) {
}
if (!NullPointerIsDefined(LI.getFunction(), LI.getPointerAddressSpace()))
- if (Value *V = simplifyNonNullOperand(Op, /*HasDereferenceable=*/true))
+ if (Value *V = simplifyNonNullOperand(Op, /*UseProvenance=*/true))
return replaceOperand(LI, 0, V);
// load(llvm.protected.field.ptr(ptr)) -> llvm.ptrauth.auth(load(ptr))
@@ -1605,7 +1605,7 @@ Instruction *InstCombinerImpl::visitStoreInst(StoreInst &SI) {
ConstantExpr::getBitCast(C, Type::getIntFromByteType(C->getType())));
if (!NullPointerIsDefined(SI.getFunction(), SI.getPointerAddressSpace()))
- if (Value *V = simplifyNonNullOperand(Ptr, /*HasDereferenceable=*/true))
+ if (Value *V = simplifyNonNullOperand(Ptr, /*UseProvenance=*/true))
return replaceOperand(SI, 1, V);
// store(ptr1, llvm.protected.field.ptr(ptr2)) ->
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 35c5483709e16..92c441f24e36b 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -4171,11 +4171,11 @@ Instruction *InstCombinerImpl::visitReturnInst(ReturnInst &RI) {
Function *F = RI.getFunction();
Type *RetTy = RetVal->getType();
if (RetTy->isPointerTy()) {
- bool HasDereferenceable =
+ bool UseProvenance =
F->getAttributes().getRetDereferenceableBytes() > 0 &&
!NullPointerIsDefined(F, RetTy->getPointerAddressSpace());
- if (F->hasRetAttribute(Attribute::NonNull) || HasDereferenceable) {
- if (Value *V = simplifyNonNullOperand(RetVal, HasDereferenceable))
+ if (F->hasRetAttribute(Attribute::NonNull) || UseProvenance) {
+ if (Value *V = simplifyNonNullOperand(RetVal, UseProvenance))
return replaceOperand(RI, 0, V);
}
}
>From 430d75d954359776738c2c8948124158defc530f Mon Sep 17 00:00:00 2001
From: Eli Friedman <efriedma at qti.qualcomm.com>
Date: Tue, 29 Sep 2026 23:29:55 -0700
Subject: [PATCH 4/5] Fix format
---
.../Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index a5688ee521a5f..3efdfbfadaa09 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -1044,8 +1044,7 @@ static bool canSimplifyNullLoadOrGEP(LoadInst &LI, Value *Op) {
return false;
}
-Value *InstCombinerImpl::simplifyNonNullOperand(Value *V,
- bool UseProvenance,
+Value *InstCombinerImpl::simplifyNonNullOperand(Value *V, bool UseProvenance,
unsigned Depth) {
if (auto *Sel = dyn_cast<SelectInst>(V)) {
if (isa<ConstantPointerNull>(Sel->getOperand(1)))
@@ -1088,8 +1087,8 @@ Value *InstCombinerImpl::simplifyNonNullOperand(Value *V,
bool Changed = false;
for (Use &U : PHI->incoming_values()) {
// We set Depth to RecursionLimit to avoid expensive recursion.
- if (auto *Res = simplifyNonNullOperand(U.get(), UseProvenance,
- RecursionLimit)) {
+ if (auto *Res =
+ simplifyNonNullOperand(U.get(), UseProvenance, RecursionLimit)) {
replaceUse(U, Res);
Changed = true;
}
>From a4e215272c55150ecf709a0cd6b125db7cc1190a Mon Sep 17 00:00:00 2001
From: Eli Friedman <efriedma at qti.qualcomm.com>
Date: Wed, 30 Sep 2026 09:49:07 -0700
Subject: [PATCH 5/5] Fix stray HasDereferenceable
---
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 3efdfbfadaa09..b5bd184d0d8cf 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -1068,7 +1068,7 @@ Value *InstCombinerImpl::simplifyNonNullOperand(Value *V, bool UseProvenance,
// valid provenance. We assume ConstantPointerNull does not have provenance.
// (The address could be equal to zero, but that doesn't matter.)
//
- // If HasDeferenceable is false, we know that the address is some non-zero
+ // If UseProvenance is false, we know that the address is some non-zero
// value. If the GEP is inbounds, and null pointers can't point to valid
// objects, the operand must also have a non-zero value.
if (UseProvenance ||
More information about the llvm-commits
mailing list