globalsra-unknown-index.ll 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ; RUN: opt < %s -globalopt -S > %t
  2. ; RUN: grep "@Y = internal unnamed_addr global \[3 x [%]struct.X\] zeroinitializer" %t
  3. ; RUN: grep load %t | count 6
  4. ; RUN: grep "add i32 [%]a, [%]b" %t | count 3
  5. ; globalopt should not sra the global, because it can't see the index.
  6. %struct.X = type { [3 x i32], [3 x i32] }
  7. @Y = internal global [3 x %struct.X] zeroinitializer
  8. @addr = external global i8
  9. define void @frob() {
  10. 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
  11. ret void
  12. }
  13. define i32 @borf(i64 %i, i64 %j) {
  14. %p = getelementptr inbounds [3 x %struct.X], [3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 0
  15. %a = load i32, i32* %p
  16. %q = getelementptr inbounds [3 x %struct.X], [3 x %struct.X]* @Y, i64 0, i64 0, i32 1, i64 0
  17. %b = load i32, i32* %q
  18. %c = add i32 %a, %b
  19. ret i32 %c
  20. }
  21. define i32 @borg(i64 %i, i64 %j) {
  22. %p = getelementptr inbounds [3 x %struct.X], [3 x %struct.X]* @Y, i64 0, i64 1, i32 0, i64 1
  23. %a = load i32, i32* %p
  24. %q = getelementptr inbounds [3 x %struct.X], [3 x %struct.X]* @Y, i64 0, i64 1, i32 1, i64 1
  25. %b = load i32, i32* %q
  26. %c = add i32 %a, %b
  27. ret i32 %c
  28. }
  29. define i32 @borh(i64 %i, i64 %j) {
  30. %p = getelementptr inbounds [3 x %struct.X], [3 x %struct.X]* @Y, i64 0, i64 2, i32 0, i64 2
  31. %a = load i32, i32* %p
  32. %q = getelementptr inbounds [3 x %struct.X], [3 x %struct.X]* @Y, i64 0, i64 2, i32 1, i64 2
  33. %b = load i32, i32* %q
  34. %c = add i32 %a, %b
  35. ret i32 %c
  36. }