Skip to content

Commit eaeb10a

Browse files
committed
[InstCombine] Address review comments. NFC.
1 parent cc6fe76 commit eaeb10a

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3996,10 +3996,12 @@ Instruction *InstCombinerImpl::visitCallBase(CallBase &Call) {
39963996
if (V->getType()->isPointerTy()) {
39973997
// Simplify the nonnull operand if the parameter is known to be nonnull.
39983998
// Otherwise, try to infer nonnull for it.
3999-
if (Call.paramHasNonNullAttr(ArgNo, /*AllowUndefOrPoison=*/true)) {
4000-
if (Value *Res = simplifyNonNullOperand(
4001-
V, /*HasDereferenceable=*/Call.getParamDereferenceableBytes(
4002-
ArgNo) > 0)) {
3999+
bool HasDereferenceable = Call.getParamDereferenceableBytes(ArgNo) > 0;
4000+
if (Call.paramHasAttr(ArgNo, Attribute::NonNull) ||
4001+
(HasDereferenceable &&
4002+
!NullPointerIsDefined(Call.getFunction(),
4003+
V->getType()->getPointerAddressSpace()))) {
4004+
if (Value *Res = simplifyNonNullOperand(V, HasDereferenceable)) {
40034005
replaceOperand(Call, ArgNo, Res);
40044006
Changed = true;
40054007
}

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3593,12 +3593,12 @@ Instruction *InstCombinerImpl::visitReturnInst(ReturnInst &RI) {
35933593
Function *F = RI.getFunction();
35943594
Type *RetTy = RetVal->getType();
35953595
if (RetTy->isPointerTy()) {
3596+
bool HasDereferenceable =
3597+
F->getAttributes().getRetDereferenceableBytes() > 0;
35963598
if (F->hasRetAttribute(Attribute::NonNull) ||
3597-
(F->getAttributes().getRetDereferenceableBytes() > 0 &&
3599+
(HasDereferenceable &&
35983600
!NullPointerIsDefined(F, RetTy->getPointerAddressSpace()))) {
3599-
if (Value *V = simplifyNonNullOperand(
3600-
RetVal, /*HasDereferenceable=*/F->getAttributes()
3601-
.getRetDereferenceableBytes() > 0))
3601+
if (Value *V = simplifyNonNullOperand(RetVal, HasDereferenceable))
36023602
return replaceOperand(RI, 0, V);
36033603
}
36043604
}

0 commit comments

Comments
 (0)