err-rep-cold.ll 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. ; Test the static branch probability heuristics for error-reporting functions.
  2. ; RUN: opt < %s -instcombine -S | FileCheck %s
  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._IO_FILE = type { i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, %struct._IO_marker*, %struct._IO_FILE*, i32, i32, i64, i16, i8, [1 x i8], i8*, i64, i8*, i8*, i8*, i8*, i64, i32, [20 x i8] }
  6. %struct._IO_marker = type { %struct._IO_marker*, %struct._IO_FILE*, i32 }
  7. @stdout = external global %struct._IO_FILE*
  8. @stderr = external global %struct._IO_FILE*
  9. @.str = private unnamed_addr constant [13 x i8] c"an error: %d\00", align 1
  10. @.str1 = private unnamed_addr constant [9 x i8] c"an error\00", align 1
  11. define i32 @test1(i32 %a) #0 {
  12. ; CHECK-LABEL: @test1
  13. entry:
  14. %cmp = icmp sgt i32 %a, 8
  15. br i1 %cmp, label %if.then, label %return
  16. if.then: ; preds = %entry
  17. %0 = load %struct._IO_FILE*, %struct._IO_FILE** @stderr, align 8
  18. %call = tail call i32 (%struct._IO_FILE*, i8*, ...) @fprintf(%struct._IO_FILE* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %a) #1
  19. br label %return
  20. ; CHECK: %call = tail call i32 (%struct._IO_FILE*, i8*, ...) @fprintf(%struct._IO_FILE* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %a) #[[AT1:[0-9]+]]
  21. return: ; preds = %entry, %if.then
  22. %retval.0 = phi i32 [ 1, %if.then ], [ 0, %entry ]
  23. ret i32 %retval.0
  24. }
  25. declare i32 @fprintf(%struct._IO_FILE* nocapture, i8* nocapture readonly, ...) #1
  26. define i32 @test2(i32 %a) #0 {
  27. ; CHECK-LABEL: @test2
  28. entry:
  29. %cmp = icmp sgt i32 %a, 8
  30. br i1 %cmp, label %if.then, label %return
  31. if.then: ; preds = %entry
  32. %0 = load %struct._IO_FILE*, %struct._IO_FILE** @stderr, align 8
  33. %1 = tail call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str1, i64 0, i64 0), i64 8, i64 1, %struct._IO_FILE* %0)
  34. br label %return
  35. ; CHECK: tail call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str1, i64 0, i64 0), i64 8, i64 1, %struct._IO_FILE* %0) #[[AT2:[0-9]+]]
  36. return: ; preds = %entry, %if.then
  37. %retval.0 = phi i32 [ 1, %if.then ], [ 0, %entry ]
  38. ret i32 %retval.0
  39. }
  40. declare i64 @fwrite(i8* nocapture, i64, i64, %struct._IO_FILE* nocapture) #1
  41. define i32 @test3(i32 %a) #0 {
  42. ; CHECK-LABEL: @test3
  43. entry:
  44. %cmp = icmp sgt i32 %a, 8
  45. br i1 %cmp, label %if.then, label %return
  46. if.then: ; preds = %entry
  47. %0 = load %struct._IO_FILE*, %struct._IO_FILE** @stdout, align 8
  48. %1 = tail call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str1, i64 0, i64 0), i64 8, i64 1, %struct._IO_FILE* %0)
  49. br label %return
  50. ; CHECK-NOT: tail call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str1, i64 0, i64 0), i64 8, i64 1, %struct._IO_FILE* %0) #[[AT2]]
  51. return: ; preds = %entry, %if.then
  52. %retval.0 = phi i32 [ 1, %if.then ], [ 0, %entry ]
  53. ret i32 %retval.0
  54. }
  55. attributes #0 = { nounwind uwtable }
  56. attributes #1 = { nounwind }
  57. ; CHECK: attributes #[[AT1]] = { cold nounwind }
  58. ; CHECK: attributes #[[AT2]] = { cold }