switch_switch_fold.ll 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. ; RUN: opt < %s -simplifycfg -S | \
  2. ; RUN: grep switch | count 1
  3. ; Test that a switch going to a switch on the same value can be merged. All
  4. ; three switches in this example can be merged into one big one.
  5. declare void @foo1()
  6. declare void @foo2()
  7. declare void @foo3()
  8. declare void @foo4()
  9. define void @test1(i32 %V) {
  10. switch i32 %V, label %F [
  11. i32 4, label %T
  12. i32 17, label %T
  13. i32 5, label %T
  14. i32 1234, label %F
  15. ]
  16. T: ; preds = %0, %0, %0
  17. switch i32 %V, label %F [
  18. i32 4, label %A
  19. i32 17, label %B
  20. i32 42, label %C
  21. ]
  22. A: ; preds = %T
  23. call void @foo1( )
  24. ret void
  25. B: ; preds = %F, %F, %T
  26. call void @foo2( )
  27. ret void
  28. C: ; preds = %T
  29. call void @foo3( )
  30. ret void
  31. F: ; preds = %F, %T, %0, %0
  32. switch i32 %V, label %F [
  33. i32 4, label %B
  34. i32 18, label %B
  35. i32 42, label %D
  36. ]
  37. D: ; preds = %F
  38. call void @foo4( )
  39. ret void
  40. }