Skip to content

Commit 5ec99c7

Browse files
authored
[InstCombine] Add test for freeze of PHI with noundef start value (NFC) (#157112)
We should be able to remove this freeze as the incoming values to the PHI have the same well-defined start value and the GEP can't produce poison, but this is currently unsupported. If the freeze is pushed to the incoming values we can remove it: https://godbolt.org/z/8dE4o1bKf
1 parent 819aa35 commit 5ec99c7

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

llvm/test/Transforms/InstCombine/freeze.ll

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,55 @@ exit:
11351135
ret void
11361136
}
11371137

1138+
; We can remove this freeze as the incoming values to the PHI have the same
1139+
; well-defined start value and the GEP can't produce poison, but this is
1140+
; currently unsupported.
1141+
define void @fold_phi_noundef_start_value(ptr noundef %init, i1 %cond.0, i1 %cond.1, i1 %cond.2) {
1142+
; CHECK-LABEL: define void @fold_phi_noundef_start_value(
1143+
; CHECK-SAME: ptr noundef [[INIT:%.*]], i1 [[COND_0:%.*]], i1 [[COND_1:%.*]], i1 [[COND_2:%.*]]) {
1144+
; CHECK-NEXT: [[ENTRY:.*]]:
1145+
; CHECK-NEXT: br label %[[LOOP:.*]]
1146+
; CHECK: [[LOOP]]:
1147+
; CHECK-NEXT: [[IV_0:%.*]] = phi ptr [ [[INIT]], %[[ENTRY]] ], [ [[IV_0_NEXT:%.*]], %[[LOOP_LATCH:.*]] ]
1148+
; CHECK-NEXT: br i1 [[COND_0]], label %[[LOOP_LATCH]], label %[[IF_ELSE:.*]]
1149+
; CHECK: [[IF_ELSE]]:
1150+
; CHECK-NEXT: [[IV_1:%.*]] = getelementptr i8, ptr [[IV_0]], i64 -8
1151+
; CHECK-NEXT: br label %[[LOOP_LATCH]]
1152+
; CHECK: [[LOOP_LATCH]]:
1153+
; CHECK-NEXT: [[IV_2:%.*]] = phi ptr [ [[IV_0]], %[[LOOP]] ], [ [[IV_1]], %[[IF_ELSE]] ]
1154+
; CHECK-NEXT: [[IV_2_FR:%.*]] = freeze ptr [[IV_2]]
1155+
; CHECK-NEXT: [[IV_2_FR_INT:%.*]] = ptrtoint ptr [[IV_2_FR]] to i64
1156+
; CHECK-NEXT: [[IV_0_INT:%.*]] = ptrtoint ptr [[IV_0]] to i64
1157+
; CHECK-NEXT: [[IDX:%.*]] = sub i64 [[IV_0_INT]], [[IV_2_FR_INT]]
1158+
; CHECK-NEXT: [[IV_0_NEXT]] = getelementptr i8, ptr [[IV_0]], i64 [[IDX]]
1159+
; CHECK-NEXT: br i1 [[COND_2]], label %[[EXIT:.*]], label %[[LOOP]]
1160+
; CHECK: [[EXIT]]:
1161+
; CHECK-NEXT: ret void
1162+
;
1163+
entry:
1164+
br label %loop
1165+
1166+
loop:
1167+
%iv.0 = phi ptr [ %init, %entry ], [ %iv.0.next, %loop.latch ]
1168+
br i1 %cond.0, label %loop.latch, label %if.else
1169+
1170+
if.else:
1171+
%iv.1 = getelementptr i8, ptr %iv.0, i64 -8
1172+
br label %loop.latch
1173+
1174+
loop.latch:
1175+
%iv.2 = phi ptr [ %iv.0, %loop ], [ %iv.1, %if.else ]
1176+
%iv.2.fr = freeze ptr %iv.2
1177+
%iv.2.fr.int = ptrtoint ptr %iv.2.fr to i64
1178+
%iv.0.int = ptrtoint ptr %iv.0 to i64
1179+
%idx = sub i64 %iv.0.int, %iv.2.fr.int
1180+
%iv.0.next = getelementptr i8, ptr %iv.0, i64 %idx
1181+
br i1 %cond.2, label %exit, label %loop
1182+
1183+
exit:
1184+
ret void
1185+
}
1186+
11381187
define void @fold_phi_invoke_start_value(i32 %n) personality ptr undef {
11391188
; CHECK-LABEL: define void @fold_phi_invoke_start_value(
11401189
; CHECK-SAME: i32 [[N:%.*]]) personality ptr undef {

0 commit comments

Comments
 (0)