phi-cycle.ll 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. ; RUN: opt -S -scalarrepl-ssa < %s | FileCheck %s
  2. ; rdar://10589171
  3. target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
  4. target triple = "x86_64-unknown-linux-gnu"
  5. %struct.foo = type { i32, i32 }
  6. @.str = private unnamed_addr constant [6 x i8] c"x=%d\0A\00", align 1
  7. define i32 @main(i32 %argc, i8** nocapture %argv) nounwind uwtable {
  8. entry:
  9. %f = alloca %struct.foo, align 4
  10. %x.i = getelementptr inbounds %struct.foo, %struct.foo* %f, i64 0, i32 0
  11. store i32 1, i32* %x.i, align 4
  12. %y.i = getelementptr inbounds %struct.foo, %struct.foo* %f, i64 0, i32 1
  13. br label %while.cond.i
  14. ; CHECK: while.cond.i:
  15. ; CHECK-NEXT: %tmp = phi i32 [ 1, %entry ], [ %tmp2, %while.cond.backedge.i ]
  16. ; CHECK-NEXT: %pos.0.i = phi i32 [ 1, %entry ], [ %xtmp.i, %while.cond.backedge.i ]
  17. ; CHECK-NEXT: %left.0.i = phi i32 [ 1, %entry ], [ %dec.i, %while.cond.backedge.i ]
  18. ; CHECK-NOT: phi
  19. while.cond.i: ; preds = %while.cond.backedge.i, %entry
  20. %tmp = phi i32 [ 1, %entry ], [ %tmp2, %while.cond.backedge.i ]
  21. %pos.0.i = phi i32 [ 1, %entry ], [ %xtmp.i, %while.cond.backedge.i ]
  22. %left.0.i = phi i32 [ 1, %entry ], [ %dec.i, %while.cond.backedge.i ]
  23. %cmp.i = icmp sgt i32 %left.0.i, 0
  24. br i1 %cmp.i, label %while.body.i, label %while.cond.i.func.exit_crit_edge
  25. while.cond.i.func.exit_crit_edge: ; preds = %while.cond.i
  26. br label %func.exit
  27. while.body.i: ; preds = %while.cond.i
  28. %dec.i = add nsw i32 %left.0.i, -1
  29. switch i32 1, label %while.body.i.func.exit_crit_edge [
  30. i32 0, label %while.cond.backedge.i
  31. i32 1, label %sw.bb.i
  32. ]
  33. while.body.i.func.exit_crit_edge: ; preds = %while.body.i
  34. br label %func.exit
  35. sw.bb.i: ; preds = %while.body.i
  36. %cmp2.i = icmp eq i32 %tmp, 1
  37. br i1 %cmp2.i, label %if.then.i, label %if.end.i
  38. if.then.i: ; preds = %sw.bb.i
  39. store i32 %pos.0.i, i32* %x.i, align 4
  40. br label %if.end.i
  41. ; CHECK: if.end.i:
  42. ; CHECK-NEXT: %tmp1 = phi i32 [ %pos.0.i, %if.then.i ], [ %tmp, %sw.bb.i ]
  43. ; CHECK-NOT: phi
  44. if.end.i: ; preds = %if.then.i, %sw.bb.i
  45. %tmp1 = phi i32 [ %pos.0.i, %if.then.i ], [ %tmp, %sw.bb.i ]
  46. store i32 %tmp1, i32* %y.i, align 4
  47. br label %while.cond.backedge.i
  48. ; CHECK: while.cond.backedge.i:
  49. ; CHECK-NEXT: %tmp2 = phi i32 [ %tmp1, %if.end.i ], [ %tmp, %while.body.i ]
  50. ; CHECK-NOT: phi
  51. while.cond.backedge.i: ; preds = %if.end.i, %while.body.i
  52. %tmp2 = phi i32 [ %tmp1, %if.end.i ], [ %tmp, %while.body.i ]
  53. %xtmp.i = add i32 %pos.0.i, 1
  54. br label %while.cond.i
  55. ; CHECK: func.exit:
  56. ; CHECK-NOT: load
  57. ; CHECK: %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %tmp) [[NUW:#[0-9]+]]
  58. func.exit: ; preds = %while.body.i.func.exit_crit_edge, %while.cond.i.func.exit_crit_edge
  59. %tmp3 = load i32, i32* %x.i, align 4
  60. %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %tmp3) nounwind
  61. ret i32 0
  62. }
  63. declare i32 @printf(i8* nocapture, ...) nounwind
  64. ; CHECK: attributes #0 = { nounwind uwtable }
  65. ; CHECK: attributes [[NUW]] = { nounwind }