[PATCH] D144445: [ConstantFold][InstSimplify] pre-commit test for constant global all-element-equal arrays and structs

Kohei Asano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 20 20:10:02 PST 2023


khei4 created this revision.
khei4 added reviewers: nikic, spatel.
Herald added subscribers: StephenFan, JDevlieghere.
Herald added a project: All.
khei4 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This is a pre-commit test for folding loadInst for aggregate types those elements are all equal. 
alive proofs: https://alive2.llvm.org/ce/
these patches will solve the rust side issue https://github.com/rust-lang/rust/issues/107208


https://reviews.llvm.org/D144445

Files:
  llvm/test/Transforms/InstSimplify/load.ll


Index: llvm/test/Transforms/InstSimplify/load.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/load.ll
+++ llvm/test/Transforms/InstSimplify/load.ll
@@ -4,10 +4,18 @@
 @zeroinit = constant {} zeroinitializer
 @poison = constant {} poison
 
+%s = type {i32, i32, i32}
+
 @constzeroarray = internal constant [4 x i32] zeroinitializer
+ at constzerostruct = internal constant %s zeroinitializer
+
+ at constalleqarray = internal constant [4 x i32] [i32 1, i32 1, i32 1, i32 1]
+ at constalleqarrayi8 = internal constant [2 x i8] [i8 1, i8 1]
+ at constalleqstruct = internal constant %s {i32 1, i32 1, i32 1}
 
- at constarray = internal constant [4 x i32] [i32 1, i32 1, i32 1, i32 1]
- at constarrayi8 = internal constant [2 x i8] [i8 1, i8 1]
+ at constarray = internal constant [4 x i32] [i32 1, i32 2, i32 3, i32 4]
+ at constarrayi8 = internal constant [2 x i8] [i8 1, i8 2]
+ at conststruct = internal constant %s {i32 1, i32 2, i32 3}
 
 define i32 @crash_on_zeroinit() {
 ; CHECK-LABEL: @crash_on_zeroinit(
@@ -65,6 +73,50 @@
   ret i8 %load
 }
 
+define i32 @load_gep_const_zero_struct(i32 %idx) {
+; CHECK-LABEL: @load_gep_const_zero_struct(
+; CHECK-NEXT:    ret i32 0
+;
+  %gep = getelementptr inbounds %s, ptr @constzerostruct, i32 %idx
+  %load = load i32, ptr %gep
+  ret i32 %load
+}
+
+define i32 @load_gep_const_alleq_array(i64 %idx) {
+; CHECK-LABEL: @load_gep_const_alleq_array(
+; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds [4 x i32], ptr @constalleqarray, i64 0, i64 [[IDX:%.*]]
+; CHECK-NEXT:    [[LOAD:%.*]] = load i32, ptr [[GEP]], align 4
+; CHECK-NEXT:    ret i32 [[LOAD]]
+;
+  %gep = getelementptr inbounds [4 x i32], ptr @constalleqarray, i64 0, i64 %idx
+  %load = load i32, ptr %gep
+  ret i32 %load
+}
+
+define i8 @load_i8_multi_gep_const_alleq_array(i64 %idx1, i64 %idx2) {
+; CHECK-LABEL: @load_i8_multi_gep_const_alleq_array(
+; CHECK-NEXT:    [[GEP1:%.*]] = getelementptr inbounds i8, ptr @constalleqarrayi8, i64 [[IDX1:%.*]]
+; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds i8, ptr [[GEP1]], i64 [[IDX2:%.*]]
+; CHECK-NEXT:    [[LOAD:%.*]] = load i8, ptr [[GEP]], align 1
+; CHECK-NEXT:    ret i8 [[LOAD]]
+;
+  %gep1 = getelementptr inbounds i8, ptr @constalleqarrayi8, i64 %idx1
+  %gep = getelementptr inbounds i8, ptr %gep1, i64 %idx2
+  %load = load i8, ptr %gep
+  ret i8 %load
+}
+
+define i32 @load_gep_const_alleq_struct(i32 %idx) {
+; CHECK-LABEL: @load_gep_const_alleq_struct(
+; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds [[S:%.*]], ptr @constalleqstruct, i32 [[IDX:%.*]]
+; CHECK-NEXT:    [[LOAD:%.*]] = load i32, ptr [[GEP]], align 4
+; CHECK-NEXT:    ret i32 [[LOAD]]
+;
+  %gep = getelementptr inbounds %s, ptr @constalleqstruct, i32 %idx
+  %load = load i32, ptr %gep
+  ret i32 %load
+}
+
 define i32 @load_gep_const_array(i64 %idx) {
 ; CHECK-LABEL: @load_gep_const_array(
 ; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds [4 x i32], ptr @constarray, i64 0, i64 [[IDX:%.*]]
@@ -88,3 +140,14 @@
   %load = load i8, ptr %gep
   ret i8 %load
 }
+
+define i32 @load_gep_const_struct(i32 %idx) {
+; CHECK-LABEL: @load_gep_const_struct(
+; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds [[S:%.*]], ptr @conststruct, i32 [[IDX:%.*]]
+; CHECK-NEXT:    [[LOAD:%.*]] = load i32, ptr [[GEP]], align 4
+; CHECK-NEXT:    ret i32 [[LOAD]]
+;
+  %gep = getelementptr inbounds %s, ptr @conststruct, i32 %idx
+  %load = load i32, ptr %gep
+  ret i32 %load
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144445.499031.patch
Type: text/x-patch
Size: 3466 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230221/9188983a/attachment.bin>


More information about the llvm-commits mailing list