Index: llvm/test/Transforms/AggressiveInstCombine/patterned-load.ll =================================================================== --- llvm/test/Transforms/AggressiveInstCombine/patterned-load.ll +++ llvm/test/Transforms/AggressiveInstCombine/patterned-load.ll @@ -1,30 +1,10 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py -; RUN: opt < %s -passes=instsimplify -S | FileCheck %s -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32" -@constzeroarray = internal constant [4 x i32] zeroinitializer +; RUN: opt < %s -passes=aggressive-instcombine -S -data-layout="e" | FileCheck %s --check-prefixes=CHECK,LE +; RUN: opt < %s -passes=aggressive-instcombine -S -data-layout="E" | FileCheck %s --check-prefixes=CHECK,BE @constarray = internal constant [8 x i8] c"\01\00\01\00\01\00\01\00", align 4 @constpackedstruct = internal constant <{[8 x i8]}> <{[8 x i8] c"\01\00\01\00\01\00\01\00"}>, align 4 -define i32 @load_gep_const_zero_array(i64 %idx) { -; CHECK-LABEL: @load_gep_const_zero_array( -; CHECK-NEXT: ret i32 0 -; - %gep = getelementptr inbounds [4 x i32], ptr @constzeroarray, i64 0, i64 %idx - %load = load i32, ptr %gep - ret i32 %load -} - -define i8 @load_i8_multi_gep_const_zero_array(i64 %idx1, i64 %idx2) { -; CHECK-LABEL: @load_i8_multi_gep_const_zero_array( -; CHECK-NEXT: ret i8 0 -; - %gep1 = getelementptr inbounds i8, ptr @constzeroarray, i64 %idx1 - %gep = getelementptr inbounds i8, ptr %gep1, i64 %idx2 - %load = load i8, ptr %gep - ret i8 %load -} - define i8 @gep_load_i8_align2(i64 %idx){ ; CHECK-LABEL: @gep_load_i8_align2( ; CHECK-NEXT: ret i8 1 @@ -47,8 +27,11 @@ } define i32 @gep_i32_load_i32_align4(i64 %idx){ -; CHECK-LABEL: @gep_i32_load_i32_align4( -; CHECK-NEXT: ret i32 65537 +; LE-LABEL: @gep_i32_load_i32_align4( +; LE-NEXT: ret i32 65537 +; +; BE-LABEL: @gep_i32_load_i32_align4( +; BE-NEXT: ret i32 16777472 ; %1 = getelementptr inbounds i32, ptr @constarray, i64 %idx %2 = load i32, ptr %1, align 4 @@ -56,8 +39,11 @@ } define i32 @gep_i32_load_i32_align4_packedstruct(i64 %idx){ -; CHECK-LABEL: @gep_i32_load_i32_align4_packedstruct( -; CHECK-NEXT: ret i32 65537 +; LE-LABEL: @gep_i32_load_i32_align4_packedstruct( +; LE-NEXT: ret i32 65537 +; +; BE-LABEL: @gep_i32_load_i32_align4_packedstruct( +; BE-NEXT: ret i32 16777472 ; %1 = getelementptr inbounds i32, ptr @constpackedstruct, i64 %idx %2 = load i32, ptr %1, align 4 @@ -88,12 +74,12 @@ ret i32 %2 } -; TODO: This could be folded but need to see GEP source types define i32 @gep_i16_load_i32_align1(i64 %idx){ -; CHECK-LABEL: @gep_i16_load_i32_align1( -; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i16, ptr @constarray, i64 [[IDX:%.*]] -; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[TMP1]], align 1 -; CHECK-NEXT: ret i32 [[TMP2]] +; LE-LABEL: @gep_i16_load_i32_align1( +; LE-NEXT: ret i32 65537 +; +; BE-LABEL: @gep_i16_load_i32_align1( +; BE-NEXT: ret i32 16777472 ; %1 = getelementptr inbounds i16, ptr @constarray, i64 %idx %2 = load i32, ptr %1, align 1 Index: llvm/test/Transforms/InstSimplify/load.ll =================================================================== --- llvm/test/Transforms/InstSimplify/load.ll +++ llvm/test/Transforms/InstSimplify/load.ll @@ -3,6 +3,7 @@ @zeroinit = constant {} zeroinitializer @poison = constant {} poison +@constzeroarray = internal constant [4 x i32] zeroinitializer define i32 @crash_on_zeroinit() { ; CHECK-LABEL: @crash_on_zeroinit( @@ -40,3 +41,22 @@ %1 = load <3 x float>, ptr getelementptr inbounds (<3 x float>, ptr @constvec, i64 1) ret <3 x float> %1 } + +define i32 @load_gep_const_zero_array(i64 %idx) { +; CHECK-LABEL: @load_gep_const_zero_array( +; CHECK-NEXT: ret i32 0 +; + %gep = getelementptr inbounds [4 x i32], ptr @constzeroarray, i64 0, i64 %idx + %load = load i32, ptr %gep + ret i32 %load +} + +define i8 @load_i8_multi_gep_const_zero_array(i64 %idx1, i64 %idx2) { +; CHECK-LABEL: @load_i8_multi_gep_const_zero_array( +; CHECK-NEXT: ret i8 0 +; + %gep1 = getelementptr inbounds i8, ptr @constzeroarray, i64 %idx1 + %gep = getelementptr inbounds i8, ptr %gep1, i64 %idx2 + %load = load i8, ptr %gep + ret i8 %load +}