return-argument.ll 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. ; RUN: opt < %s -ipconstprop -S > %t
  2. ; RUN: cat %t | grep "store i32 %Z, i32\* %Q"
  3. ; RUN: cat %t | grep "add i32 1, 3"
  4. ;; This function returns its second argument on all return statements
  5. define internal i32* @incdec(i1 %C, i32* %V) {
  6. %X = load i32, i32* %V
  7. br i1 %C, label %T, label %F
  8. T: ; preds = %0
  9. %X1 = add i32 %X, 1
  10. store i32 %X1, i32* %V
  11. ret i32* %V
  12. F: ; preds = %0
  13. %X2 = sub i32 %X, 1
  14. store i32 %X2, i32* %V
  15. ret i32* %V
  16. }
  17. ;; This function returns its first argument as a part of a multiple return
  18. ;; value
  19. define internal { i32, i32 } @foo(i32 %A, i32 %B) {
  20. %X = add i32 %A, %B
  21. %Y = insertvalue { i32, i32 } undef, i32 %A, 0
  22. %Z = insertvalue { i32, i32 } %Y, i32 %X, 1
  23. ret { i32, i32 } %Z
  24. }
  25. define void @caller(i1 %C) personality i32 (...)* @__gxx_personality_v0 {
  26. %Q = alloca i32
  27. ;; Call incdec to see if %W is properly replaced by %Q
  28. %W = call i32* @incdec(i1 %C, i32* %Q ) ; <i32> [#uses=1]
  29. ;; Call @foo twice, to prevent the arguments from propagating into the
  30. ;; function (so we can check the returned argument is properly
  31. ;; propagated per-caller).
  32. %S1 = call { i32, i32 } @foo(i32 1, i32 2)
  33. %X1 = extractvalue { i32, i32 } %S1, 0
  34. %S2 = invoke { i32, i32 } @foo(i32 3, i32 4) to label %OK unwind label %LPAD
  35. OK:
  36. %X2 = extractvalue { i32, i32 } %S2, 0
  37. ;; Do some stuff with the returned values which we can grep for
  38. %Z = add i32 %X1, %X2
  39. store i32 %Z, i32* %W
  40. br label %RET
  41. LPAD:
  42. %exn = landingpad {i8*, i32}
  43. cleanup
  44. br label %RET
  45. RET:
  46. ret void
  47. }
  48. declare i32 @__gxx_personality_v0(...)