1*9880d681SAndroid Build Coastguard Worker; Test the static branch probability heuristics for error-reporting functions. 2*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -instcombine -S | FileCheck %s 3*9880d681SAndroid Build Coastguard Workertarget 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*9880d681SAndroid Build Coastguard Workertarget triple = "x86_64-unknown-linux-gnu" 5*9880d681SAndroid Build Coastguard Worker 6*9880d681SAndroid Build Coastguard Worker%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] } 7*9880d681SAndroid Build Coastguard Worker%struct._IO_marker = type { %struct._IO_marker*, %struct._IO_FILE*, i32 } 8*9880d681SAndroid Build Coastguard Worker 9*9880d681SAndroid Build Coastguard Worker@stdout = external global %struct._IO_FILE* 10*9880d681SAndroid Build Coastguard Worker@stderr = external global %struct._IO_FILE* 11*9880d681SAndroid Build Coastguard Worker@.str = private unnamed_addr constant [13 x i8] c"an error: %d\00", align 1 12*9880d681SAndroid Build Coastguard Worker@.str1 = private unnamed_addr constant [9 x i8] c"an error\00", align 1 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Workerdefine i32 @test1(i32 %a) #0 { 15*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test1 16*9880d681SAndroid Build Coastguard Workerentry: 17*9880d681SAndroid Build Coastguard Worker %cmp = icmp sgt i32 %a, 8 18*9880d681SAndroid Build Coastguard Worker br i1 %cmp, label %if.then, label %return 19*9880d681SAndroid Build Coastguard Worker 20*9880d681SAndroid Build Coastguard Workerif.then: ; preds = %entry 21*9880d681SAndroid Build Coastguard Worker %0 = load %struct._IO_FILE*, %struct._IO_FILE** @stderr, align 8 22*9880d681SAndroid Build Coastguard Worker %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 23*9880d681SAndroid Build Coastguard Worker br label %return 24*9880d681SAndroid Build Coastguard Worker 25*9880d681SAndroid Build Coastguard Worker; 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]+]] 26*9880d681SAndroid Build Coastguard Worker 27*9880d681SAndroid Build Coastguard Workerreturn: ; preds = %entry, %if.then 28*9880d681SAndroid Build Coastguard Worker %retval.0 = phi i32 [ 1, %if.then ], [ 0, %entry ] 29*9880d681SAndroid Build Coastguard Worker ret i32 %retval.0 30*9880d681SAndroid Build Coastguard Worker} 31*9880d681SAndroid Build Coastguard Worker 32*9880d681SAndroid Build Coastguard Workerdeclare i32 @fprintf(%struct._IO_FILE* nocapture, i8* nocapture readonly, ...) #1 33*9880d681SAndroid Build Coastguard Worker 34*9880d681SAndroid Build Coastguard Workerdefine i32 @test2(i32 %a) #0 { 35*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test2 36*9880d681SAndroid Build Coastguard Workerentry: 37*9880d681SAndroid Build Coastguard Worker %cmp = icmp sgt i32 %a, 8 38*9880d681SAndroid Build Coastguard Worker br i1 %cmp, label %if.then, label %return 39*9880d681SAndroid Build Coastguard Worker 40*9880d681SAndroid Build Coastguard Workerif.then: ; preds = %entry 41*9880d681SAndroid Build Coastguard Worker %0 = load %struct._IO_FILE*, %struct._IO_FILE** @stderr, align 8 42*9880d681SAndroid Build Coastguard Worker %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) 43*9880d681SAndroid Build Coastguard Worker br label %return 44*9880d681SAndroid Build Coastguard Worker 45*9880d681SAndroid Build Coastguard Worker; 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]+]] 46*9880d681SAndroid Build Coastguard Worker 47*9880d681SAndroid Build Coastguard Workerreturn: ; preds = %entry, %if.then 48*9880d681SAndroid Build Coastguard Worker %retval.0 = phi i32 [ 1, %if.then ], [ 0, %entry ] 49*9880d681SAndroid Build Coastguard Worker ret i32 %retval.0 50*9880d681SAndroid Build Coastguard Worker} 51*9880d681SAndroid Build Coastguard Worker 52*9880d681SAndroid Build Coastguard Workerdeclare i64 @fwrite(i8* nocapture, i64, i64, %struct._IO_FILE* nocapture) #1 53*9880d681SAndroid Build Coastguard Worker 54*9880d681SAndroid Build Coastguard Workerdefine i32 @test3(i32 %a) #0 { 55*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test3 56*9880d681SAndroid Build Coastguard Workerentry: 57*9880d681SAndroid Build Coastguard Worker %cmp = icmp sgt i32 %a, 8 58*9880d681SAndroid Build Coastguard Worker br i1 %cmp, label %if.then, label %return 59*9880d681SAndroid Build Coastguard Worker 60*9880d681SAndroid Build Coastguard Workerif.then: ; preds = %entry 61*9880d681SAndroid Build Coastguard Worker %0 = load %struct._IO_FILE*, %struct._IO_FILE** @stdout, align 8 62*9880d681SAndroid Build Coastguard Worker %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) 63*9880d681SAndroid Build Coastguard Worker br label %return 64*9880d681SAndroid Build Coastguard Worker 65*9880d681SAndroid Build Coastguard Worker; 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]] 66*9880d681SAndroid Build Coastguard Worker 67*9880d681SAndroid Build Coastguard Workerreturn: ; preds = %entry, %if.then 68*9880d681SAndroid Build Coastguard Worker %retval.0 = phi i32 [ 1, %if.then ], [ 0, %entry ] 69*9880d681SAndroid Build Coastguard Worker ret i32 %retval.0 70*9880d681SAndroid Build Coastguard Worker} 71*9880d681SAndroid Build Coastguard Worker 72*9880d681SAndroid Build Coastguard Workerattributes #0 = { nounwind uwtable } 73*9880d681SAndroid Build Coastguard Workerattributes #1 = { nounwind } 74*9880d681SAndroid Build Coastguard Worker 75*9880d681SAndroid Build Coastguard Worker; CHECK: attributes #[[AT1]] = { cold nounwind } 76*9880d681SAndroid Build Coastguard Worker; CHECK: attributes #[[AT2]] = { cold } 77*9880d681SAndroid Build Coastguard Worker 78