[llvm] 5ec99c7 - [InstCombine] Add test for freeze of PHI with noundef start value (NFC) (#157112)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 9 00:50:29 PDT 2025
Author: Cullen Rhodes
Date: 2025-09-09T08:50:24+01:00
New Revision: 5ec99c7e8f5ea8bf333bfcc84020d29a62deb25e
URL: https://github.com/llvm/llvm-project/commit/5ec99c7e8f5ea8bf333bfcc84020d29a62deb25e
DIFF: https://github.com/llvm/llvm-project/commit/5ec99c7e8f5ea8bf333bfcc84020d29a62deb25e.diff
LOG: [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
Added:
Modified:
llvm/test/Transforms/InstCombine/freeze.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/freeze.ll b/llvm/test/Transforms/InstCombine/freeze.ll
index b29421a655fa8..f63489bbab4c0 100644
--- a/llvm/test/Transforms/InstCombine/freeze.ll
+++ b/llvm/test/Transforms/InstCombine/freeze.ll
@@ -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:.*]]
+; CHECK: [[LOOP]]:
+; CHECK-NEXT: [[IV_0:%.*]] = phi ptr [ [[INIT]], %[[ENTRY]] ], [ [[IV_0_NEXT:%.*]], %[[LOOP_LATCH:.*]] ]
+; CHECK-NEXT: br i1 [[COND_0]], label %[[LOOP_LATCH]], label %[[IF_ELSE:.*]]
+; CHECK: [[IF_ELSE]]:
+; CHECK-NEXT: [[IV_1:%.*]] = getelementptr i8, ptr [[IV_0]], i64 -8
+; CHECK-NEXT: br label %[[LOOP_LATCH]]
+; CHECK: [[LOOP_LATCH]]:
+; CHECK-NEXT: [[IV_2:%.*]] = phi ptr [ [[IV_0]], %[[LOOP]] ], [ [[IV_1]], %[[IF_ELSE]] ]
+; 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]]
+; CHECK: [[EXIT]]:
+; CHECK-NEXT: ret void
+;
+entry:
+ br label %loop
+
+loop:
+ %iv.0 = phi ptr [ %init, %entry ], [ %iv.0.next, %loop.latch ]
+ br i1 %cond.0, label %loop.latch, label %if.else
+
+if.else:
+ %iv.1 = getelementptr i8, ptr %iv.0, i64 -8
+ br label %loop.latch
+
+loop.latch:
+ %iv.2 = phi ptr [ %iv.0, %loop ], [ %iv.1, %if.else ]
+ %iv.2.fr = freeze ptr %iv.2
+ %iv.2.fr.int = ptrtoint ptr %iv.2.fr to i64
+ %iv.0.int = ptrtoint ptr %iv.0 to i64
+ %idx = sub i64 %iv.0.int, %iv.2.fr.int
+ %iv.0.next = getelementptr i8, ptr %iv.0, i64 %idx
+ br i1 %cond.2, label %exit, label %loop
+
+exit:
+ ret void
+}
+
define void @fold_phi_invoke_start_value(i32 %n) personality ptr undef {
; CHECK-LABEL: define void @fold_phi_invoke_start_value(
; CHECK-SAME: i32 [[N:%.*]]) personality ptr undef {
More information about the llvm-commits
mailing list