[llvm] [InstCombine] Add test for freeze of PHI with noundef start value (NFC) (PR #157112)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 5 07:39:21 PDT 2025
================
@@ -1135,6 +1135,55 @@ exit:
ret void
}
+; We can 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.
+define void @fold_phi_noundef_start_value(ptr noundef %init, i1 %cond.0, i1 %cond.1, i1 %cond.2) {
+; CHECK-LABEL: define void @fold_phi_noundef_start_value(
+; CHECK-SAME: ptr noundef [[INIT:%.*]], i1 [[COND_0:%.*]], i1 [[COND_1:%.*]], i1 [[COND_2:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*]]:
+; CHECK-NEXT: br label %[[LOOP_PH_0:.*]]
+; CHECK: [[LOOP_PH_0]]:
+; CHECK-NEXT: [[IV_0:%.*]] = phi ptr [ [[INIT]], %[[ENTRY]] ], [ [[IV_0_NEXT:%.*]], %[[LOOP:.*]] ]
+; CHECK-NEXT: br i1 [[COND_0]], label %[[LOOP]], label %[[LOOP_PH_1:.*]]
+; CHECK: [[LOOP_PH_1]]:
+; CHECK-NEXT: [[IV_1:%.*]] = getelementptr i8, ptr [[IV_0]], i64 -8
+; CHECK-NEXT: br label %[[LOOP]]
+; CHECK: [[LOOP]]:
+; CHECK-NEXT: [[IV_2:%.*]] = phi ptr [ [[IV_0]], %[[LOOP_PH_0]] ], [ [[IV_1]], %[[LOOP_PH_1]] ]
+; CHECK-NEXT: [[IV_2_FR:%.*]] = freeze ptr [[IV_2]]
+; CHECK-NEXT: [[IV_2_FR_INT:%.*]] = ptrtoint ptr [[IV_2_FR]] to i64
+; CHECK-NEXT: [[IV_0_INT:%.*]] = ptrtoint ptr [[IV_0]] to i64
+; CHECK-NEXT: [[IDX:%.*]] = sub i64 [[IV_0_INT]], [[IV_2_FR_INT]]
+; CHECK-NEXT: [[IV_0_NEXT]] = getelementptr i8, ptr [[IV_0]], i64 [[IDX]]
+; CHECK-NEXT: br i1 [[COND_2]], label %[[EXIT:.*]], label %[[LOOP_PH_0]]
+; CHECK: [[EXIT]]:
+; CHECK-NEXT: ret void
+;
+entry:
+ br label %loop.ph.0
+
+loop.ph.0:
----------------
nikic wrote:
```suggestion
loop:
```
Looks like this is the actual loop, not a pre-header?
https://github.com/llvm/llvm-project/pull/157112
More information about the llvm-commits
mailing list