[llvm] [SROA] analyze gep(ptr,phi(const...)) (PR #82425)
Artem Belevich via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 21 16:49:58 PST 2024
================
@@ -504,6 +505,47 @@ bb.4: ; preds = %bb.1, %bb.1, %bb
ret i32 %load
}
+
+define void @test_gep_phi_const(i32 %arg) {
+; CHECK-LABEL: @test_gep_phi_const(
+; CHECK-NEXT: bb:
+; CHECK-NEXT: switch i32 [[ARG:%.*]], label [[BB9:%.*]] [
+; CHECK-NEXT: i32 0, label [[BB11:%.*]]
+; CHECK-NEXT: i32 1, label [[BB10:%.*]]
+; CHECK-NEXT: ]
+; CHECK: bb9:
+; CHECK-NEXT: [[PHI:%.*]] = phi i64 [ 8, [[BB10]] ], [ 16, [[BB:%.*]] ]
+; CHECK-NEXT: [[PHI_SROA_PHI_SROA_SPECULATED:%.*]] = phi ptr [ undef, [[BB10]] ], [ undef, [[BB]] ]
+; CHECK-NEXT: br label [[BB11]]
+; CHECK: bb10:
+; CHECK-NEXT: br label [[BB9]]
+; CHECK: bb11:
+; CHECK-NEXT: [[PHI12:%.*]] = phi ptr [ [[PHI_SROA_PHI_SROA_SPECULATED]], [[BB9]] ], [ undef, [[BB]] ]
+; CHECK-NEXT: store i8 0, ptr [[PHI12]], align 1
+; CHECK-NEXT: ret void
+;
+bb:
+ %alloca = alloca %t1, align 8
+ switch i32 %arg, label %bb9 [
+ i32 0, label %bb11
+ i32 1, label %bb10
+ ]
+
+bb9: ; preds = %bb10, %bb
+ %phi = phi i64 [ 8, %bb10 ], [ 16, %bb ]
+ %getelementptr = getelementptr i8, ptr %alloca, i64 %phi
+ %load = load ptr, ptr %getelementptr, align 8
+ br label %bb11
+
+bb10: ; preds = %bb
+ br label %bb9
+
+bb11: ; preds = %bb9, %bb
+ %phi12 = phi ptr [ %load, %bb9 ], [ undef, %bb ]
+ store i8 0, ptr %phi12, align 1
+ ret void
+}
----------------
Artem-B wrote:
Would the test below do? It verifies that we only handle all-const phi indices. Or did you have something else in mind?
That got me thinking. Perhaps we should relax "phi(all-const)" into `phi(any-const)` as it will give SROA some more slices to analyze.
https://github.com/llvm/llvm-project/pull/82425
More information about the llvm-commits
mailing list