1*9880d681SAndroid Build Coastguard Worker; This file verifies the behavior of the OptBisect class, which is used to 2*9880d681SAndroid Build Coastguard Worker; diagnose optimization related failures. The tests check various 3*9880d681SAndroid Build Coastguard Worker; invocations that result in different sets of optimization passes that 4*9880d681SAndroid Build Coastguard Worker; are run in different ways. 5*9880d681SAndroid Build Coastguard Worker; 6*9880d681SAndroid Build Coastguard Worker; This set of tests exercises the legacy pass manager interface to the OptBisect 7*9880d681SAndroid Build Coastguard Worker; class. Because the exact set of optimizations that will be run may 8*9880d681SAndroid Build Coastguard Worker; change over time, these tests are written in a more general manner than the 9*9880d681SAndroid Build Coastguard Worker; corresponding tests for the new pass manager. 10*9880d681SAndroid Build Coastguard Worker; 11*9880d681SAndroid Build Coastguard Worker; Don't use NEXT checks or hard-code pass numbering so that this won't fail if 12*9880d681SAndroid Build Coastguard Worker; new passes are inserted. 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Worker 15*9880d681SAndroid Build Coastguard Worker; Verify that the file can be compiled to an object file at -O3 with all 16*9880d681SAndroid Build Coastguard Worker; skippable passes skipped. 17*9880d681SAndroid Build Coastguard Worker 18*9880d681SAndroid Build Coastguard Worker; RUN: opt -O3 -opt-bisect-limit=0 < %s | llc -O3 -opt-bisect-limit=0 19*9880d681SAndroid Build Coastguard Worker 20*9880d681SAndroid Build Coastguard Worker 21*9880d681SAndroid Build Coastguard Worker; Verify that no skippable passes are run with -opt-bisect-limit=0. 22*9880d681SAndroid Build Coastguard Worker 23*9880d681SAndroid Build Coastguard Worker; RUN: opt -disable-output -disable-verify -O3 -opt-bisect-limit=0 %s 2>&1 \ 24*9880d681SAndroid Build Coastguard Worker; RUN: | FileCheck %s --check-prefix=CHECK-SKIP-ALL 25*9880d681SAndroid Build Coastguard Worker; CHECK-SKIP-ALL: BISECT: NOT running pass ({{[0-9]+}}) 26*9880d681SAndroid Build Coastguard Worker; CHECK-SKIP-ALL-NOT: BISECT: running pass ({{[0-9]+}}) 27*9880d681SAndroid Build Coastguard Worker 28*9880d681SAndroid Build Coastguard Worker 29*9880d681SAndroid Build Coastguard Worker; Verify that no passes run at -O0 are skipped 30*9880d681SAndroid Build Coastguard Worker; RUN: opt -opt-bisect-limit=0 < %s 2>&1 | FileCheck %s --check-prefix=OPTBISECT-O0 31*9880d681SAndroid Build Coastguard Worker; OPTBISECT-O0-NOT: BISECT: NOT running 32*9880d681SAndroid Build Coastguard Worker 33*9880d681SAndroid Build Coastguard Worker; FIXME: There are still some AMDGPU passes being skipped that run at -O0. 34*9880d681SAndroid Build Coastguard Worker; XFAIL: r600, amdgcn 35*9880d681SAndroid Build Coastguard Worker 36*9880d681SAndroid Build Coastguard Worker; Verify that we can use the opt-bisect-helper.py script (derived from 37*9880d681SAndroid Build Coastguard Worker; utils/bisect) to locate the optimization that inlines the call to 38*9880d681SAndroid Build Coastguard Worker; f2() in f3(). 39*9880d681SAndroid Build Coastguard Worker 40*9880d681SAndroid Build Coastguard Worker; RUN: %python %S/opt-bisect-helper.py --start=0 --end=256 --optcmd=opt \ 41*9880d681SAndroid Build Coastguard Worker; RUN: --filecheckcmd=FileCheck --test=%s \ 42*9880d681SAndroid Build Coastguard Worker; RUN: --prefix=CHECK-BISECT-INLINE-HELPER \ 43*9880d681SAndroid Build Coastguard Worker; RUN: | FileCheck %s --check-prefix=CHECK-BISECT-INLINE-RESULT 44*9880d681SAndroid Build Coastguard Worker; The helper script uses this to find the optimization that inlines the call. 45*9880d681SAndroid Build Coastguard Worker; CHECK-BISECT-INLINE-HELPER: call i32 @f2() 46*9880d681SAndroid Build Coastguard Worker; These checks verifies that the optimization was found. 47*9880d681SAndroid Build Coastguard Worker; CHECK-BISECT-INLINE-RESULT-NOT: Last good count: 0 48*9880d681SAndroid Build Coastguard Worker; CHECK-BISECT-INLINE-RESULT: Last good count: {{[0-9]+}} 49*9880d681SAndroid Build Coastguard Worker 50*9880d681SAndroid Build Coastguard Worker 51*9880d681SAndroid Build Coastguard Worker; Test a module pass. 52*9880d681SAndroid Build Coastguard Worker 53*9880d681SAndroid Build Coastguard Worker; RUN: opt -disable-output -disable-verify -deadargelim -opt-bisect-limit=-1 %s \ 54*9880d681SAndroid Build Coastguard Worker; RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-DEADARG 55*9880d681SAndroid Build Coastguard Worker; CHECK-DEADARG: BISECT: running pass ({{[0-9]+}}) Dead Argument Elimination on module 56*9880d681SAndroid Build Coastguard Worker 57*9880d681SAndroid Build Coastguard Worker; RUN: opt -disable-output -disable-verify -deadargelim -opt-bisect-limit=0 %s \ 58*9880d681SAndroid Build Coastguard Worker; RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-DEADARG 59*9880d681SAndroid Build Coastguard Worker; CHECK-NOT-DEADARG: BISECT: NOT running pass ({{[0-9]+}}) Dead Argument Elimination on module 60*9880d681SAndroid Build Coastguard Worker 61*9880d681SAndroid Build Coastguard Worker 62*9880d681SAndroid Build Coastguard Worker; Test an SCC pass. 63*9880d681SAndroid Build Coastguard Worker 64*9880d681SAndroid Build Coastguard Worker; RUN: opt -disable-output -disable-verify -inline -opt-bisect-limit=-1 %s \ 65*9880d681SAndroid Build Coastguard Worker; RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-INLINE 66*9880d681SAndroid Build Coastguard Worker; CHECK-INLINE: BISECT: running pass ({{[0-9]+}}) Function Integration/Inlining on SCC (<<null function>>) 67*9880d681SAndroid Build Coastguard Worker; CHECK-INLINE: BISECT: running pass ({{[0-9]+}}) Function Integration/Inlining on SCC (g) 68*9880d681SAndroid Build Coastguard Worker; CHECK-INLINE: BISECT: running pass ({{[0-9]+}}) Function Integration/Inlining on SCC (f1) 69*9880d681SAndroid Build Coastguard Worker; CHECK-INLINE: BISECT: running pass ({{[0-9]+}}) Function Integration/Inlining on SCC (f2) 70*9880d681SAndroid Build Coastguard Worker; CHECK-INLINE: BISECT: running pass ({{[0-9]+}}) Function Integration/Inlining on SCC (f3) 71*9880d681SAndroid Build Coastguard Worker; CHECK-INLINE: BISECT: running pass ({{[0-9]+}}) Function Integration/Inlining on SCC (<<null function>>) 72*9880d681SAndroid Build Coastguard Worker 73*9880d681SAndroid Build Coastguard Worker; RUN: opt -disable-output -disable-verify -inline -opt-bisect-limit=0 %s \ 74*9880d681SAndroid Build Coastguard Worker; RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-INLINE 75*9880d681SAndroid Build Coastguard Worker; CHECK-NOT-INLINE: BISECT: NOT running pass ({{[0-9]+}}) Function Integration/Inlining on SCC (<<null function>>) 76*9880d681SAndroid Build Coastguard Worker; CHECK-NOT-INLINE: BISECT: NOT running pass ({{[0-9]+}}) Function Integration/Inlining on SCC (g) 77*9880d681SAndroid Build Coastguard Worker; CHECK-NOT-INLINE: BISECT: NOT running pass ({{[0-9]+}}) Function Integration/Inlining on SCC (f1) 78*9880d681SAndroid Build Coastguard Worker; CHECK-NOT-INLINE: BISECT: NOT running pass ({{[0-9]+}}) Function Integration/Inlining on SCC (f2) 79*9880d681SAndroid Build Coastguard Worker; CHECK-NOT-INLINE: BISECT: NOT running pass ({{[0-9]+}}) Function Integration/Inlining on SCC (f3) 80*9880d681SAndroid Build Coastguard Worker; CHECK-NOT-INLINE: BISECT: NOT running pass ({{[0-9]+}}) Function Integration/Inlining on SCC (<<null function>>) 81*9880d681SAndroid Build Coastguard Worker 82*9880d681SAndroid Build Coastguard Worker 83*9880d681SAndroid Build Coastguard Worker; Test a function pass. 84*9880d681SAndroid Build Coastguard Worker 85*9880d681SAndroid Build Coastguard Worker; RUN: opt -disable-output -disable-verify -early-cse -opt-bisect-limit=-1 \ 86*9880d681SAndroid Build Coastguard Worker; RUN: %s 2>&1 | FileCheck %s --check-prefix=CHECK-EARLY-CSE 87*9880d681SAndroid Build Coastguard Worker; CHECK-EARLY-CSE: BISECT: running pass ({{[0-9]+}}) Early CSE on function (f1) 88*9880d681SAndroid Build Coastguard Worker; CHECK-EARLY-CSE: BISECT: running pass ({{[0-9]+}}) Early CSE on function (f2) 89*9880d681SAndroid Build Coastguard Worker; CHECK-EARLY-CSE: BISECT: running pass ({{[0-9]+}}) Early CSE on function (f3) 90*9880d681SAndroid Build Coastguard Worker 91*9880d681SAndroid Build Coastguard Worker; RUN: opt -disable-output -disable-verify -early-cse -opt-bisect-limit=0 %s \ 92*9880d681SAndroid Build Coastguard Worker; RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-EARLY-CSE 93*9880d681SAndroid Build Coastguard Worker; CHECK-NOT-EARLY-CSE: BISECT: NOT running pass ({{[0-9]+}}) Early CSE on function (f1) 94*9880d681SAndroid Build Coastguard Worker; CHECK-NOT-EARLY-CSE: BISECT: NOT running pass ({{[0-9]+}}) Early CSE on function (f2) 95*9880d681SAndroid Build Coastguard Worker; CHECK-NOT-EARLY-CSE: BISECT: NOT running pass ({{[0-9]+}}) Early CSE on function (f3) 96*9880d681SAndroid Build Coastguard Worker 97*9880d681SAndroid Build Coastguard Worker 98*9880d681SAndroid Build Coastguard Worker; Test a loop pass. 99*9880d681SAndroid Build Coastguard Worker 100*9880d681SAndroid Build Coastguard Worker; RUN: opt -disable-output -disable-verify -loop-reduce -opt-bisect-limit=-1 \ 101*9880d681SAndroid Build Coastguard Worker; RUN: %s 2>&1 | FileCheck %s --check-prefix=CHECK-LOOP-REDUCE 102*9880d681SAndroid Build Coastguard Worker; CHECK-LOOP-REDUCE: BISECT: running pass ({{[0-9]+}}) Loop Strength Reduction on loop 103*9880d681SAndroid Build Coastguard Worker; CHECK-LOOP-REDUCE: BISECT: running pass ({{[0-9]+}}) Loop Strength Reduction on loop 104*9880d681SAndroid Build Coastguard Worker; CHECK-LOOP-REDUCE: BISECT: running pass ({{[0-9]+}}) Loop Strength Reduction on loop 105*9880d681SAndroid Build Coastguard Worker; CHECK-LOOP-REDUCE: BISECT: running pass ({{[0-9]+}}) Loop Strength Reduction on loop 106*9880d681SAndroid Build Coastguard Worker; CHECK-LOOP-REDUCE: BISECT: running pass ({{[0-9]+}}) Loop Strength Reduction on loop 107*9880d681SAndroid Build Coastguard Worker 108*9880d681SAndroid Build Coastguard Worker; RUN: opt -disable-output -disable-verify -loop-reduce -opt-bisect-limit=0 \ 109*9880d681SAndroid Build Coastguard Worker; RUN: %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-LOOP-REDUCE 110*9880d681SAndroid Build Coastguard Worker; CHECK-NOT-LOOP-REDUCE: BISECT: NOT running pass ({{[0-9]+}}) Loop Strength Reduction on loop 111*9880d681SAndroid Build Coastguard Worker; CHECK-NOT-LOOP-REDUCE: BISECT: NOT running pass ({{[0-9]+}}) Loop Strength Reduction on loop 112*9880d681SAndroid Build Coastguard Worker; CHECK-NOT-LOOP-REDUCE: BISECT: NOT running pass ({{[0-9]+}}) Loop Strength Reduction on loop 113*9880d681SAndroid Build Coastguard Worker; CHECK-NOT-LOOP-REDUCE: BISECT: NOT running pass ({{[0-9]+}}) Loop Strength Reduction on loop 114*9880d681SAndroid Build Coastguard Worker; CHECK-NOT-LOOP-REDUCE: BISECT: NOT running pass ({{[0-9]+}}) Loop Strength Reduction on loop 115*9880d681SAndroid Build Coastguard Worker 116*9880d681SAndroid Build Coastguard Worker 117*9880d681SAndroid Build Coastguard Workerdeclare i32 @g() 118*9880d681SAndroid Build Coastguard Worker 119*9880d681SAndroid Build Coastguard Workerdefine void @f1() { 120*9880d681SAndroid Build Coastguard Workerentry: 121*9880d681SAndroid Build Coastguard Worker br label %loop.0 122*9880d681SAndroid Build Coastguard Workerloop.0: 123*9880d681SAndroid Build Coastguard Worker br i1 undef, label %loop.0.0, label %loop.1 124*9880d681SAndroid Build Coastguard Workerloop.0.0: 125*9880d681SAndroid Build Coastguard Worker br i1 undef, label %loop.0.0, label %loop.0.1 126*9880d681SAndroid Build Coastguard Workerloop.0.1: 127*9880d681SAndroid Build Coastguard Worker br i1 undef, label %loop.0.1, label %loop.0 128*9880d681SAndroid Build Coastguard Workerloop.1: 129*9880d681SAndroid Build Coastguard Worker br i1 undef, label %loop.1, label %loop.1.bb1 130*9880d681SAndroid Build Coastguard Workerloop.1.bb1: 131*9880d681SAndroid Build Coastguard Worker br i1 undef, label %loop.1, label %loop.1.bb2 132*9880d681SAndroid Build Coastguard Workerloop.1.bb2: 133*9880d681SAndroid Build Coastguard Worker br i1 undef, label %end, label %loop.1.0 134*9880d681SAndroid Build Coastguard Workerloop.1.0: 135*9880d681SAndroid Build Coastguard Worker br i1 undef, label %loop.1.0, label %loop.1 136*9880d681SAndroid Build Coastguard Workerend: 137*9880d681SAndroid Build Coastguard Worker ret void 138*9880d681SAndroid Build Coastguard Worker} 139*9880d681SAndroid Build Coastguard Worker 140*9880d681SAndroid Build Coastguard Workerdefine i32 @f2() { 141*9880d681SAndroid Build Coastguard Workerentry: 142*9880d681SAndroid Build Coastguard Worker ret i32 0 143*9880d681SAndroid Build Coastguard Worker} 144*9880d681SAndroid Build Coastguard Worker 145*9880d681SAndroid Build Coastguard Workerdefine i32 @f3() { 146*9880d681SAndroid Build Coastguard Workerentry: 147*9880d681SAndroid Build Coastguard Worker %temp = call i32 @g() 148*9880d681SAndroid Build Coastguard Worker %icmp = icmp ugt i32 %temp, 2 149*9880d681SAndroid Build Coastguard Worker br i1 %icmp, label %bb.true, label %bb.false 150*9880d681SAndroid Build Coastguard Workerbb.true: 151*9880d681SAndroid Build Coastguard Worker %temp2 = call i32 @f2() 152*9880d681SAndroid Build Coastguard Worker ret i32 %temp2 153*9880d681SAndroid Build Coastguard Workerbb.false: 154*9880d681SAndroid Build Coastguard Worker ret i32 0 155*9880d681SAndroid Build Coastguard Worker} 156*9880d681SAndroid Build Coastguard Worker 157*9880d681SAndroid Build Coastguard Worker; This function is here to verify that opt-bisect can skip all passes for 158*9880d681SAndroid Build Coastguard Worker; functions that contain lifetime intrinsics. 159*9880d681SAndroid Build Coastguard Workerdefine void @f4() { 160*9880d681SAndroid Build Coastguard Workerentry: 161*9880d681SAndroid Build Coastguard Worker %i = alloca i32, align 4 162*9880d681SAndroid Build Coastguard Worker %tmp = bitcast i32* %i to i8* 163*9880d681SAndroid Build Coastguard Worker call void @llvm.lifetime.start(i64 4, i8* %tmp) 164*9880d681SAndroid Build Coastguard Worker br label %for.cond 165*9880d681SAndroid Build Coastguard Worker 166*9880d681SAndroid Build Coastguard Workerfor.cond: 167*9880d681SAndroid Build Coastguard Worker br i1 undef, label %for.body, label %for.end 168*9880d681SAndroid Build Coastguard Worker 169*9880d681SAndroid Build Coastguard Workerfor.body: 170*9880d681SAndroid Build Coastguard Worker br label %for.cond 171*9880d681SAndroid Build Coastguard Worker 172*9880d681SAndroid Build Coastguard Workerfor.end: 173*9880d681SAndroid Build Coastguard Worker ret void 174*9880d681SAndroid Build Coastguard Worker} 175*9880d681SAndroid Build Coastguard Worker 176*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.lifetime.start(i64, i8* nocapture) 177*9880d681SAndroid Build Coastguard Worker 178