nocapture.ll 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. ; RUN: opt < %s -basicaa -gvn -instcombine -S | FileCheck %s
  2. declare i32* @test(i32* nocapture)
  3. define i32 @test2() {
  4. ; CHECK: ret i32 0
  5. %P = alloca i32
  6. %Q = call i32* @test(i32* %P)
  7. %a = load i32, i32* %P
  8. store i32 4, i32* %Q ;; cannot clobber P since it is nocapture.
  9. %b = load i32, i32* %P
  10. %c = sub i32 %a, %b
  11. ret i32 %c
  12. }
  13. declare void @test3(i32** %p, i32* %q) nounwind
  14. define i32 @test4(i32* noalias nocapture %p) nounwind {
  15. ; CHECK: call void @test3
  16. ; CHECK: store i32 0, i32* %p
  17. ; CHECK: store i32 1, i32* %x
  18. ; CHECK: %y = load i32, i32* %p
  19. ; CHECK: ret i32 %y
  20. entry:
  21. %q = alloca i32*
  22. ; Here test3 might store %p to %q. This doesn't violate %p's nocapture
  23. ; attribute since the copy doesn't outlive the function.
  24. call void @test3(i32** %q, i32* %p) nounwind
  25. store i32 0, i32* %p
  26. %x = load i32*, i32** %q
  27. ; This store might write to %p and so we can't eliminate the subsequent
  28. ; load
  29. store i32 1, i32* %x
  30. %y = load i32, i32* %p
  31. ret i32 %y
  32. }