cond_br.ll 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ; RUN: opt -basicaa -gvn -S < %s | FileCheck %s
  2. @y = external global i32
  3. @z = external global i32
  4. ; Function Attrs: nounwind ssp uwtable
  5. define void @foo(i32 %x) {
  6. ; CHECK: @foo(i32 %x)
  7. ; CHECK: %.pre = load i32, i32* @y
  8. ; CHECK: call void @bar(i32 %.pre)
  9. %t = sub i32 %x, %x
  10. %.pre = load i32, i32* @y, align 4
  11. %cmp = icmp sgt i32 %t, 2
  12. br i1 %cmp, label %if.then, label %entry.if.end_crit_edge
  13. entry.if.end_crit_edge: ; preds = %entry
  14. br label %if.end
  15. if.then: ; preds = %entry
  16. %add = add nsw i32 %x, 3
  17. store i32 %add, i32* @y, align 4
  18. br label %if.end
  19. if.end: ; preds = %entry.if.end_crit_edge, %if.then
  20. %1 = phi i32 [ %.pre, %entry.if.end_crit_edge ], [ %add, %if.then ]
  21. tail call void @bar(i32 %1)
  22. ret void
  23. }
  24. define void @foo2(i32 %x) {
  25. ; CHECK: @foo2(i32 %x)
  26. ; CHECK: %.pre = load i32, i32* @y
  27. ; CHECK: tail call void @bar(i32 %.pre)
  28. entry:
  29. %t = sub i32 %x, %x
  30. %.pre = load i32, i32* @y, align 4
  31. %cmp = icmp sgt i32 %t, 2
  32. br i1 %cmp, label %if.then, label %if.else
  33. if.then: ; preds = %entry
  34. %add = add nsw i32 %x, 3
  35. store i32 %add, i32* @y, align 4
  36. br label %if.end
  37. if.else: ; preds = %entry
  38. store i32 1, i32* @z, align 4
  39. br label %if.end
  40. if.end: ; preds = %if.else, %if.then
  41. %0 = phi i32 [ %.pre, %if.else ], [ %add, %if.then ]
  42. tail call void @bar(i32 %0)
  43. ret void
  44. }
  45. declare void @bar(i32)