[PATCH] D144076: [test][InstCombine] Add a test case for constant folding for uniformly initialized array

Kohei Asano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 15 00:35:33 PST 2023


khei4 created this revision.
khei4 added reviewers: spatel, nikic.
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.

To enable ConstantFolding to handle load/GEP instruction for uniformly initialized aggregate types. This patch only contains tests. Implementation patches coming later. 
Goal proof: https://alive2.llvm.org/ce/z/oZtVby
motivated by https://github.com/rust-lang/rust/issues/107208 
(this is my first patch and I don't have commit access )


https://reviews.llvm.org/D144076

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


Index: llvm/test/Transforms/InstCombine/load.ll
===================================================================
--- llvm/test/Transforms/InstCombine/load.ll
+++ llvm/test/Transforms/InstCombine/load.ll
@@ -9,6 +9,7 @@
 @Z = constant [2 x { i32, float }] zeroinitializer		; <ptr> [#uses=1]
 
 @GLOBAL = internal constant [4 x i32] zeroinitializer
+ at GLOBAL1 = internal constant [4 x i32] [i32 1,i32 1,i32 1,i32 1]
 
 
 define i32 @test1() {
@@ -76,6 +77,29 @@
   ret i32 %R
 }
 
+; TODO: constant fold for global constant uniform array
+define i32 @load_gep_const_uniform_zero_array(i64 %X) {
+; CHECK-LABEL: @load_gep_const_uniform_zero_array(
+; CHECK-NEXT:    [[V:%.*]] = getelementptr inbounds [4 x i32], ptr @GLOBAL, i64 0, i64 [[X:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[V]], align 4
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %V = getelementptr inbounds [4 x i32], ptr @GLOBAL, i64 0, i64 %X
+  %R = load i32, ptr %V
+  ret i32 %R
+}
+
+define i32 @load_gep_const_uniform_array(i64 %X) {
+; CHECK-LABEL: @load_gep_const_uniform_array(
+; CHECK-NEXT:    [[V:%.*]] = getelementptr inbounds [4 x i32], ptr @GLOBAL1, i64 0, i64 [[X:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[V]], align 4
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %V = getelementptr inbounds [4 x i32], ptr @GLOBAL1, i64 0, i64 %X
+  %R = load i32, ptr %V
+  ret i32 %R
+}
+
 define i32 @test7_no_null_opt(i32 %X) #0 {
 ; CHECK-LABEL: @test7_no_null_opt(
 ; CHECK-NEXT:    [[TMP1:%.*]] = sext i32 [[X:%.*]] to i64


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144076.497577.patch
Type: text/x-patch
Size: 1497 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230215/fa4d686a/attachment.bin>


More information about the llvm-commits mailing list