Home | History | Annotate | Download | only in GlobalOpt
      1 ; RUN: opt < %s -globalopt -S | FileCheck %s
      2 
      3 ; globalopt should not sra the global, because it can't see the index.
      4 
      5 %struct.X = type { [3 x i32], [3 x i32] }
      6 
      7 ; CHECK: @Y = internal unnamed_addr global [3 x %struct.X] zeroinitializer
      8 @Y = internal global [3 x %struct.X] zeroinitializer
      9 
     10 @addr = external global i8
     11 
     12 define void @frob() {
     13   store i32 1, i32* getelementptr inbounds ([3 x %struct.X], [3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 ptrtoint (i8* @addr to i64)), align 4
     14   ret void
     15 }
     16 
     17 ; CHECK-LABEL: @borf
     18 ; CHECK: %a = load
     19 ; CHECK: %b = load
     20 ; CHECK: add i32 %a, %b
     21 define i32 @borf(i64 %i, i64 %j) {
     22   %p = getelementptr inbounds [3 x %struct.X], [3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 0
     23   %a = load i32, i32* %p
     24   %q = getelementptr inbounds [3 x %struct.X], [3 x %struct.X]* @Y, i64 0, i64 0, i32 1, i64 0
     25   %b = load i32, i32* %q
     26   %c = add i32 %a, %b
     27   ret i32 %c
     28 }
     29 
     30 ; CHECK-LABEL: @borg
     31 ; CHECK: %a = load
     32 ; CHECK: %b = load
     33 ; CHECK: add i32 %a, %b
     34 define i32 @borg(i64 %i, i64 %j) {
     35   %p = getelementptr inbounds [3 x %struct.X], [3 x %struct.X]* @Y, i64 0, i64 1, i32 0, i64 1
     36   %a = load i32, i32* %p
     37   %q = getelementptr inbounds [3 x %struct.X], [3 x %struct.X]* @Y, i64 0, i64 1, i32 1, i64 1
     38   %b = load i32, i32* %q
     39   %c = add i32 %a, %b
     40   ret i32 %c
     41 }
     42 
     43 ; CHECK-LABEL: @borh
     44 ; CHECK: %a = load
     45 ; CHECK: %b = load
     46 ; CHECK: add i32 %a, %b
     47 define i32 @borh(i64 %i, i64 %j) {
     48   %p = getelementptr inbounds [3 x %struct.X], [3 x %struct.X]* @Y, i64 0, i64 2, i32 0, i64 2
     49   %a = load i32, i32* %p
     50   %q = getelementptr inbounds [3 x %struct.X], [3 x %struct.X]* @Y, i64 0, i64 2, i32 1, i64 2
     51   %b = load i32, i32* %q
     52   %c = add i32 %a, %b
     53   ret i32 %c
     54 }
     55