dynamic_alloca_test.ll 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ; Test that functions with dynamic allocas get inlined in a case where
  2. ; naively inlining it would result in a miscompilation.
  3. ; Functions with dynamic allocas can only be inlined into functions that
  4. ; already have dynamic allocas.
  5. ; RUN: opt < %s -inline -S | FileCheck %s
  6. ;
  7. ; FIXME: This test is xfailed because the inline cost rewrite disabled *all*
  8. ; inlining of functions which contain a dynamic alloca. It should be re-enabled
  9. ; once that functionality is restored.
  10. ; XFAIL: *
  11. declare void @ext(i32*)
  12. define internal void @callee(i32 %N) {
  13. %P = alloca i32, i32 %N
  14. call void @ext(i32* %P)
  15. ret void
  16. }
  17. define void @foo(i32 %N) {
  18. ; CHECK-LABEL: @foo(
  19. ; CHECK: alloca i32, i32 %{{.*}}
  20. ; CHECK: call i8* @llvm.stacksave()
  21. ; CHECK: alloca i32, i32 %{{.*}}
  22. ; CHECK: call void @ext
  23. ; CHECK: call void @llvm.stackrestore
  24. ; CHECK: ret
  25. entry:
  26. %P = alloca i32, i32 %N
  27. call void @ext(i32* %P)
  28. br label %loop
  29. loop:
  30. %count = phi i32 [ 0, %entry ], [ %next, %loop ]
  31. %next = add i32 %count, 1
  32. call void @callee(i32 %N)
  33. %cond = icmp eq i32 %count, 100000
  34. br i1 %cond, label %out, label %loop
  35. out:
  36. ret void
  37. }