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 ; [#uses=1] @GLOBAL = internal constant [4 x i32] zeroinitializer +@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