pr22718.ll 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. ; RUN: opt < %s -analyze -branch-prob | FileCheck %s
  2. ; In this test, the else clause is taken about 90% of the time. This was not
  3. ; reflected in the probability computation because the weight is larger than
  4. ; the branch weight cap (about 2 billion).
  5. ;
  6. ; CHECK: edge for.body -> if.then probability is 216661881 / 2166666667 = 9.9
  7. ; CHECK: edge for.body -> if.else probability is 1950004786 / 2166666667 = 90.0
  8. @y = common global i64 0, align 8
  9. @x = common global i64 0, align 8
  10. @.str = private unnamed_addr constant [17 x i8] c"x = %lu\0Ay = %lu\0A\00", align 1
  11. ; Function Attrs: inlinehint nounwind uwtable
  12. define i32 @main() #0 {
  13. entry:
  14. %retval = alloca i32, align 4
  15. %i = alloca i64, align 8
  16. store i32 0, i32* %retval
  17. store i64 0, i64* @y, align 8
  18. store i64 0, i64* @x, align 8
  19. call void @srand(i32 422304) #3
  20. store i64 0, i64* %i, align 8
  21. br label %for.cond
  22. for.cond: ; preds = %for.inc, %entry
  23. %0 = load i64, i64* %i, align 8
  24. %cmp = icmp ult i64 %0, 13000000000
  25. br i1 %cmp, label %for.body, label %for.end, !prof !1
  26. for.body: ; preds = %for.cond
  27. %call = call i32 @rand() #3
  28. %conv = sitofp i32 %call to double
  29. %mul = fmul double %conv, 1.000000e+02
  30. %div = fdiv double %mul, 0x41E0000000000000
  31. %cmp1 = fcmp ogt double %div, 9.000000e+01
  32. br i1 %cmp1, label %if.then, label %if.else, !prof !2
  33. if.then: ; preds = %for.body
  34. %1 = load i64, i64* @x, align 8
  35. %inc = add i64 %1, 1
  36. store i64 %inc, i64* @x, align 8
  37. br label %if.end
  38. if.else: ; preds = %for.body
  39. %2 = load i64, i64* @y, align 8
  40. %inc3 = add i64 %2, 1
  41. store i64 %inc3, i64* @y, align 8
  42. br label %if.end
  43. if.end: ; preds = %if.else, %if.then
  44. br label %for.inc
  45. for.inc: ; preds = %if.end
  46. %3 = load i64, i64* %i, align 8
  47. %inc4 = add i64 %3, 1
  48. store i64 %inc4, i64* %i, align 8
  49. br label %for.cond
  50. for.end: ; preds = %for.cond
  51. %4 = load i64, i64* @x, align 8
  52. %5 = load i64, i64* @y, align 8
  53. %call5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i32 0, i32 0), i64 %4, i64 %5)
  54. ret i32 0
  55. }
  56. ; Function Attrs: nounwind
  57. declare void @srand(i32) #1
  58. ; Function Attrs: nounwind
  59. declare i32 @rand() #1
  60. declare i32 @printf(i8*, ...) #2
  61. attributes #0 = { inlinehint nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
  62. attributes #1 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
  63. attributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
  64. attributes #3 = { nounwind }
  65. !llvm.ident = !{!0}
  66. !0 = !{!"clang version 3.7.0 (trunk 236218) (llvm/trunk 236235)"}
  67. !1 = !{!"branch_weights", i32 -1044967295, i32 1}
  68. !2 = !{!"branch_weights", i32 433323762, i32 -394957723}