nonzero-first-index.ll 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ; RUN: opt < %s -scalarrepl -S | FileCheck %s
  2. 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"
  3. target triple = "i386-pc-linux-gnu"
  4. %nested = type { i32, [4 x i32] }
  5. ; Check that a GEP with a non-zero first index does not prevent SROA as long
  6. ; as the resulting offset corresponds to an element in the alloca.
  7. define i32 @test1() {
  8. ; CHECK-LABEL: @test1(
  9. ; CHECK-NOT: = i160
  10. ; CHECK: ret i32 undef
  11. %A = alloca %nested
  12. %B = getelementptr %nested, %nested* %A, i32 0, i32 1, i32 0
  13. %C = getelementptr i32, i32* %B, i32 2
  14. %D = load i32, i32* %C
  15. ret i32 %D
  16. }
  17. ; But, if the offset is out of range, then it should not be transformed.
  18. define i32 @test2() {
  19. ; CHECK-LABEL: @test2(
  20. ; CHECK: i160
  21. %A = alloca %nested
  22. %B = getelementptr %nested, %nested* %A, i32 0, i32 1, i32 0
  23. %C = getelementptr i32, i32* %B, i32 4
  24. %D = load i32, i32* %C
  25. ret i32 %D
  26. }
  27. ; Try it with a bitcast and single GEP....
  28. define i32 @test3() {
  29. ; CHECK-LABEL: @test3(
  30. ; CHECK-NOT: = i160
  31. ; CHECK: ret i32 undef
  32. %A = alloca %nested
  33. %B = bitcast %nested* %A to i32*
  34. %C = getelementptr i32, i32* %B, i32 2
  35. %D = load i32, i32* %C
  36. ret i32 %D
  37. }
  38. ; ...and again make sure that out-of-range accesses are not transformed.
  39. define i32 @test4() {
  40. ; CHECK-LABEL: @test4(
  41. ; CHECK: i160
  42. %A = alloca %nested
  43. %B = bitcast %nested* %A to i32*
  44. %C = getelementptr i32, i32* %B, i32 -1
  45. %D = load i32, i32* %C
  46. ret i32 %D
  47. }