Skip to content

Commit c213cfd

Browse files
committed
[InstCombine] Simplify nonnull phi nodes
1 parent 353cb53 commit c213cfd

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ Value *InstCombinerImpl::simplifyNonNullOperand(Value *V,
996996
if (!V->hasOneUse())
997997
return nullptr;
998998

999-
if (Depth == 1)
999+
if (Depth == 2)
10001000
return nullptr;
10011001

10021002
if (auto *GEP = dyn_cast<GetElementPtrInst>(V)) {
@@ -1010,6 +1010,20 @@ Value *InstCombinerImpl::simplifyNonNullOperand(Value *V,
10101010
}
10111011
}
10121012

1013+
if (auto *PHI = dyn_cast<PHINode>(V)) {
1014+
bool Changed = false;
1015+
for (Use &U : PHI->incoming_values()) {
1016+
if (auto *Res =
1017+
simplifyNonNullOperand(U.get(), HasDereferenceable, Depth + 1)) {
1018+
replaceUse(U, Res);
1019+
Changed = true;
1020+
}
1021+
}
1022+
if (Changed)
1023+
addToWorklist(PHI);
1024+
return nullptr;
1025+
}
1026+
10131027
return nullptr;
10141028
}
10151029

llvm/test/Transforms/InstCombine/load.ll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,8 @@ define i32 @test_load_phi_with_select(ptr %p, i1 %cond1) {
457457
; CHECK-NEXT: entry:
458458
; CHECK-NEXT: br label [[LOOP_BODY:%.*]]
459459
; CHECK: loop.body:
460-
; CHECK-NEXT: [[BASE:%.*]] = phi ptr [ [[P1:%.*]], [[ENTRY:%.*]] ], [ [[P:%.*]], [[LOOP_BODY]] ]
461-
; CHECK-NEXT: [[TARGET:%.*]] = getelementptr inbounds nuw i8, ptr [[BASE]], i64 24
460+
; CHECK-NEXT: [[TARGET:%.*]] = getelementptr inbounds nuw i8, ptr [[BASE:%.*]], i64 24
462461
; CHECK-NEXT: [[LOAD:%.*]] = load i32, ptr [[TARGET]], align 4
463-
; CHECK-NEXT: [[P]] = select i1 [[COND1:%.*]], ptr null, ptr [[P1]]
464462
; CHECK-NEXT: [[COND21:%.*]] = icmp eq i32 [[LOAD]], 0
465463
; CHECK-NEXT: br i1 [[COND21]], label [[LOOP_BODY]], label [[EXIT:%.*]]
466464
; CHECK: exit:

0 commit comments

Comments
 (0)