Skip to content

Commit 3b13bda

Browse files
committed
[InstCombine] Simplify nonnull phi nodes
1 parent cd2d4fc commit 3b13bda

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,20 @@ Value *InstCombinerImpl::simplifyNonNullOperand(Value *V,
10111011
}
10121012
}
10131013

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

llvm/test/Transforms/InstCombine/load.ll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,8 @@ define i32 @test_load_phi_with_select(ptr %p, i1 %cond1) {
487487
; CHECK-NEXT: entry:
488488
; CHECK-NEXT: br label [[LOOP_BODY:%.*]]
489489
; CHECK: loop.body:
490-
; CHECK-NEXT: [[BASE:%.*]] = phi ptr [ [[P1:%.*]], [[ENTRY:%.*]] ], [ [[P:%.*]], [[LOOP_BODY]] ]
491-
; CHECK-NEXT: [[TARGET:%.*]] = getelementptr inbounds nuw i8, ptr [[BASE]], i64 24
490+
; CHECK-NEXT: [[TARGET:%.*]] = getelementptr inbounds nuw i8, ptr [[BASE:%.*]], i64 24
492491
; CHECK-NEXT: [[LOAD:%.*]] = load i32, ptr [[TARGET]], align 4
493-
; CHECK-NEXT: [[P]] = select i1 [[COND1:%.*]], ptr null, ptr [[P1]]
494492
; CHECK-NEXT: [[COND21:%.*]] = icmp eq i32 [[LOAD]], 0
495493
; CHECK-NEXT: br i1 [[COND21]], label [[LOOP_BODY]], label [[EXIT:%.*]]
496494
; CHECK: exit:

0 commit comments

Comments
 (0)