dont_reorder_load.ll 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ; RUN: opt < %s -tailcallelim -S | grep call | count 3
  2. ; PR4323
  3. ; Several cases where tail call elimination should not move the load above the
  4. ; call, and thus can't eliminate the tail recursion.
  5. @extern_weak_global = extern_weak global i32 ; <i32*> [#uses=1]
  6. ; This load can't be safely moved above the call because the load is from an
  7. ; extern_weak global and may trap, but the call may unwind before that happens.
  8. define fastcc i32 @no_tailrecelim_1(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) readonly {
  9. entry:
  10. %tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
  11. br i1 %tmp2, label %if, label %else
  12. if: ; preds = %entry
  13. ret i32 37
  14. else: ; preds = %entry
  15. %tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
  16. %tmp8 = call fastcc i32 @no_tailrecelim_1(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
  17. %tmp9 = load i32, i32* @extern_weak_global ; <i32> [#uses=1]
  18. %tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
  19. ret i32 %tmp10
  20. }
  21. ; This load can't be safely moved above the call because function may write to the pointer.
  22. define fastcc i32 @no_tailrecelim_2(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) nounwind {
  23. entry:
  24. %tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
  25. br i1 %tmp2, label %if, label %else
  26. if: ; preds = %entry
  27. store i32 1, i32* %a_arg
  28. ret i32 0
  29. else: ; preds = %entry
  30. %tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
  31. %tmp8 = call fastcc i32 @no_tailrecelim_2(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
  32. %tmp9 = load i32, i32* %a_arg ; <i32> [#uses=1]
  33. %tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
  34. ret i32 %tmp10
  35. }
  36. ; This load can't be safely moved above the call because that would change the
  37. ; order in which the load volatiles are performed.
  38. define fastcc i32 @no_tailrecelim_3(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) nounwind {
  39. entry:
  40. %tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
  41. br i1 %tmp2, label %if, label %else
  42. if: ; preds = %entry
  43. ret i32 0
  44. else: ; preds = %entry
  45. %tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
  46. %tmp8 = call fastcc i32 @no_tailrecelim_3(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
  47. %tmp9 = load volatile i32, i32* %a_arg ; <i32> [#uses=1]
  48. %tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
  49. ret i32 %tmp10
  50. }