[llvm] 999bab7 - [SimplifyCFG] Add tests for sinking of load/store + gep (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 7 07:51:35 PDT 2024
Author: Nikita Popov
Date: 2024-08-07T16:51:18+02:00
New Revision: 999bab711e19b897bb7d86433f72f1b8eeaa4891
URL: https://github.com/llvm/llvm-project/commit/999bab711e19b897bb7d86433f72f1b8eeaa4891
DIFF: https://github.com/llvm/llvm-project/commit/999bab711e19b897bb7d86433f72f1b8eeaa4891.diff
LOG: [SimplifyCFG] Add tests for sinking of load/store + gep (NFC)
Added:
Modified:
llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll b/llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll
index be2f17dc1c780..0150b3b60d9e4 100644
--- a/llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll
+++ b/llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll
@@ -1846,6 +1846,193 @@ join:
ret i64 %phi1
}
+define i64 @load_with_sunk_gep(i1 %cond, ptr %p, i64 %a, i64 %b) {
+; CHECK-LABEL: @load_with_sunk_gep(
+; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF:%.*]], label [[JOIN:%.*]]
+; CHECK: if:
+; CHECK-NEXT: call void @dummy()
+; CHECK-NEXT: br label [[JOIN]]
+; CHECK: join:
+; CHECK-NEXT: [[B_SINK:%.*]] = phi i64 [ [[A:%.*]], [[IF]] ], [ [[B:%.*]], [[TMP0:%.*]] ]
+; CHECK-NEXT: [[GEP_B:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 [[B_SINK]]
+; CHECK-NEXT: [[V_B:%.*]] = load i64, ptr [[GEP_B]], align 8
+; CHECK-NEXT: ret i64 [[V_B]]
+;
+ br i1 %cond, label %if, label %else
+
+if:
+ call void @dummy()
+ %gep.a = getelementptr i8, ptr %p, i64 %a
+ %v.a = load i64, ptr %gep.a
+ br label %join
+
+else:
+ %gep.b = getelementptr i8, ptr %p, i64 %b
+ %v.b = load i64, ptr %gep.b
+ br label %join
+
+join:
+ %v = phi i64 [ %v.a, %if ], [ %v.b, %else ]
+ ret i64 %v
+}
+
+define i64 @load_with_non_sunk_gep_both(i1 %cond, ptr %p.a, ptr %p.b, i64 %a, i64 %b) {
+; CHECK-LABEL: @load_with_non_sunk_gep_both(
+; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
+; CHECK: if:
+; CHECK-NEXT: call void @dummy()
+; CHECK-NEXT: [[GEP_A:%.*]] = getelementptr i8, ptr [[P_A:%.*]], i64 [[A:%.*]]
+; CHECK-NEXT: br label [[JOIN:%.*]]
+; CHECK: else:
+; CHECK-NEXT: [[GEP_B:%.*]] = getelementptr i8, ptr [[P_B:%.*]], i64 [[B:%.*]]
+; CHECK-NEXT: br label [[JOIN]]
+; CHECK: join:
+; CHECK-NEXT: [[GEP_B_SINK:%.*]] = phi ptr [ [[GEP_B]], [[ELSE]] ], [ [[GEP_A]], [[IF]] ]
+; CHECK-NEXT: [[V_B:%.*]] = load i64, ptr [[GEP_B_SINK]], align 8
+; CHECK-NEXT: ret i64 [[V_B]]
+;
+ br i1 %cond, label %if, label %else
+
+if:
+ call void @dummy()
+ %gep.a = getelementptr i8, ptr %p.a, i64 %a
+ %v.a = load i64, ptr %gep.a
+ br label %join
+
+else:
+ %gep.b = getelementptr i8, ptr %p.b, i64 %b
+ %v.b = load i64, ptr %gep.b
+ br label %join
+
+join:
+ %v = phi i64 [ %v.a, %if ], [ %v.b, %else ]
+ ret i64 %v
+}
+
+define i64 @load_with_non_sunk_gep_left(i1 %cond, ptr %p.a, ptr %p.b, i64 %b) {
+; CHECK-LABEL: @load_with_non_sunk_gep_left(
+; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
+; CHECK: if:
+; CHECK-NEXT: call void @dummy()
+; CHECK-NEXT: br label [[JOIN:%.*]]
+; CHECK: else:
+; CHECK-NEXT: [[GEP_B:%.*]] = getelementptr i8, ptr [[P_B:%.*]], i64 [[B:%.*]]
+; CHECK-NEXT: br label [[JOIN]]
+; CHECK: join:
+; CHECK-NEXT: [[GEP_B_SINK:%.*]] = phi ptr [ [[GEP_B]], [[ELSE]] ], [ [[P_A:%.*]], [[IF]] ]
+; CHECK-NEXT: [[V_B:%.*]] = load i64, ptr [[GEP_B_SINK]], align 8
+; CHECK-NEXT: ret i64 [[V_B]]
+;
+ br i1 %cond, label %if, label %else
+
+if:
+ call void @dummy()
+ %v.a = load i64, ptr %p.a
+ br label %join
+
+else:
+ %gep.b = getelementptr i8, ptr %p.b, i64 %b
+ %v.b = load i64, ptr %gep.b
+ br label %join
+
+join:
+ %v = phi i64 [ %v.a, %if ], [ %v.b, %else ]
+ ret i64 %v
+}
+
+define i64 @load_with_non_sunk_gep_right(i1 %cond, ptr %p.a, ptr %p.b, i64 %a) {
+; CHECK-LABEL: @load_with_non_sunk_gep_right(
+; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF:%.*]], label [[JOIN:%.*]]
+; CHECK: if:
+; CHECK-NEXT: call void @dummy()
+; CHECK-NEXT: [[GEP_A:%.*]] = getelementptr i8, ptr [[P_A:%.*]], i64 [[A:%.*]]
+; CHECK-NEXT: br label [[JOIN]]
+; CHECK: join:
+; CHECK-NEXT: [[P_B_SINK:%.*]] = phi ptr [ [[GEP_A]], [[IF]] ], [ [[P_B:%.*]], [[TMP0:%.*]] ]
+; CHECK-NEXT: [[V_B:%.*]] = load i64, ptr [[P_B_SINK]], align 8
+; CHECK-NEXT: ret i64 [[V_B]]
+;
+ br i1 %cond, label %if, label %else
+
+if:
+ call void @dummy()
+ %gep.a = getelementptr i8, ptr %p.a, i64 %a
+ %v.a = load i64, ptr %gep.a
+ br label %join
+
+else:
+ %v.b = load i64, ptr %p.b
+ br label %join
+
+join:
+ %v = phi i64 [ %v.a, %if ], [ %v.b, %else ]
+ ret i64 %v
+}
+
+define void @store_with_non_sunk_gep(i1 %cond, ptr %p.a, ptr %p.b, i64 %a, i64 %b) {
+; CHECK-LABEL: @store_with_non_sunk_gep(
+; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
+; CHECK: if:
+; CHECK-NEXT: call void @dummy()
+; CHECK-NEXT: [[GEP_A:%.*]] = getelementptr i8, ptr [[P_A:%.*]], i64 [[A:%.*]]
+; CHECK-NEXT: br label [[JOIN:%.*]]
+; CHECK: else:
+; CHECK-NEXT: [[GEP_B:%.*]] = getelementptr i8, ptr [[P_B:%.*]], i64 [[B:%.*]]
+; CHECK-NEXT: br label [[JOIN]]
+; CHECK: join:
+; CHECK-NEXT: [[GEP_B_SINK:%.*]] = phi ptr [ [[GEP_B]], [[ELSE]] ], [ [[GEP_A]], [[IF]] ]
+; CHECK-NEXT: store i64 0, ptr [[GEP_B_SINK]], align 8
+; CHECK-NEXT: ret void
+;
+ br i1 %cond, label %if, label %else
+
+if:
+ call void @dummy()
+ %gep.a = getelementptr i8, ptr %p.a, i64 %a
+ store i64 0, ptr %gep.a
+ br label %join
+
+else:
+ %gep.b = getelementptr i8, ptr %p.b, i64 %b
+ store i64 0, ptr %gep.b
+ br label %join
+
+join:
+ ret void
+}
+
+define void @store_with_non_sunk_gep_as_value(i1 %cond, ptr %p, ptr %p.a, ptr %p.b, i64 %a, i64 %b) {
+; CHECK-LABEL: @store_with_non_sunk_gep_as_value(
+; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
+; CHECK: if:
+; CHECK-NEXT: call void @dummy()
+; CHECK-NEXT: [[GEP_A:%.*]] = getelementptr i8, ptr [[P_A:%.*]], i64 [[A:%.*]]
+; CHECK-NEXT: br label [[JOIN:%.*]]
+; CHECK: else:
+; CHECK-NEXT: [[GEP_B:%.*]] = getelementptr i8, ptr [[P_B:%.*]], i64 [[B:%.*]]
+; CHECK-NEXT: br label [[JOIN]]
+; CHECK: join:
+; CHECK-NEXT: [[GEP_B_SINK:%.*]] = phi ptr [ [[GEP_B]], [[ELSE]] ], [ [[GEP_A]], [[IF]] ]
+; CHECK-NEXT: store ptr [[GEP_B_SINK]], ptr [[P:%.*]], align 8
+; CHECK-NEXT: ret void
+;
+ br i1 %cond, label %if, label %else
+
+if:
+ call void @dummy()
+ %gep.a = getelementptr i8, ptr %p.a, i64 %a
+ store ptr %gep.a, ptr %p
+ br label %join
+
+else:
+ %gep.b = getelementptr i8, ptr %p.b, i64 %b
+ store ptr %gep.b, ptr %p
+ br label %join
+
+join:
+ ret void
+}
+
declare void @dummy()
declare void @use.ptr(ptr)
More information about the llvm-commits
mailing list