1*9880d681SAndroid Build Coastguard Worker; RUN: opt -S -licm < %s | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' -S %s | FileCheck %s 3*9880d681SAndroid Build Coastguard Worker 4*9880d681SAndroid Build Coastguard Workerdeclare void @use_nothrow(i64 %a) nounwind 5*9880d681SAndroid Build Coastguard Workerdeclare void @use(i64 %a) 6*9880d681SAndroid Build Coastguard Worker 7*9880d681SAndroid Build Coastguard Workerdefine void @nothrow(i64 %x, i64 %y, i1* %cond) { 8*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: nothrow 9*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: entry 10*9880d681SAndroid Build Coastguard Worker; CHECK: %div = udiv i64 %x, %y 11*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: loop 12*9880d681SAndroid Build Coastguard Worker; CHECK: call void @use_nothrow(i64 %div) 13*9880d681SAndroid Build Coastguard Workerentry: 14*9880d681SAndroid Build Coastguard Worker br label %loop 15*9880d681SAndroid Build Coastguard Worker 16*9880d681SAndroid Build Coastguard Workerloop: ; preds = %entry, %for.inc 17*9880d681SAndroid Build Coastguard Worker %div = udiv i64 %x, %y 18*9880d681SAndroid Build Coastguard Worker br label %loop2 19*9880d681SAndroid Build Coastguard Worker 20*9880d681SAndroid Build Coastguard Workerloop2: 21*9880d681SAndroid Build Coastguard Worker call void @use_nothrow(i64 %div) 22*9880d681SAndroid Build Coastguard Worker br label %loop 23*9880d681SAndroid Build Coastguard Worker} 24*9880d681SAndroid Build Coastguard Worker; Negative test 25*9880d681SAndroid Build Coastguard Workerdefine void @throw_header(i64 %x, i64 %y, i1* %cond) { 26*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: throw_header 27*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: loop 28*9880d681SAndroid Build Coastguard Worker; CHECK: %div = udiv i64 %x, %y 29*9880d681SAndroid Build Coastguard Worker; CHECK: call void @use(i64 %div) 30*9880d681SAndroid Build Coastguard Workerentry: 31*9880d681SAndroid Build Coastguard Worker br label %loop 32*9880d681SAndroid Build Coastguard Worker 33*9880d681SAndroid Build Coastguard Workerloop: ; preds = %entry, %for.inc 34*9880d681SAndroid Build Coastguard Worker %div = udiv i64 %x, %y 35*9880d681SAndroid Build Coastguard Worker call void @use(i64 %div) 36*9880d681SAndroid Build Coastguard Worker br label %loop 37*9880d681SAndroid Build Coastguard Worker} 38*9880d681SAndroid Build Coastguard Worker 39*9880d681SAndroid Build Coastguard Worker; The header is known no throw, but the loop is not. We can 40*9880d681SAndroid Build Coastguard Worker; still lift out of the header. 41*9880d681SAndroid Build Coastguard Workerdefine void @nothrow_header(i64 %x, i64 %y, i1 %cond) { 42*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: nothrow_header 43*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: entry 44*9880d681SAndroid Build Coastguard Worker; CHECK: %div = udiv i64 %x, %y 45*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: loop 46*9880d681SAndroid Build Coastguard Worker; CHECK: call void @use(i64 %div) 47*9880d681SAndroid Build Coastguard Workerentry: 48*9880d681SAndroid Build Coastguard Worker br label %loop 49*9880d681SAndroid Build Coastguard Workerloop: ; preds = %entry, %for.inc 50*9880d681SAndroid Build Coastguard Worker %div = udiv i64 %x, %y 51*9880d681SAndroid Build Coastguard Worker br i1 %cond, label %loop-if, label %exit 52*9880d681SAndroid Build Coastguard Workerloop-if: 53*9880d681SAndroid Build Coastguard Worker call void @use(i64 %div) 54*9880d681SAndroid Build Coastguard Worker br label %loop 55*9880d681SAndroid Build Coastguard Workerexit: 56*9880d681SAndroid Build Coastguard Worker ret void 57*9880d681SAndroid Build Coastguard Worker} 58*9880d681SAndroid Build Coastguard Worker; Negative test - can't move out of throwing block 59*9880d681SAndroid Build Coastguard Workerdefine void @nothrow_header_neg(i64 %x, i64 %y, i1 %cond) { 60*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: nothrow_header_neg 61*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: entry 62*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: loop 63*9880d681SAndroid Build Coastguard Worker; CHECK: %div = udiv i64 %x, %y 64*9880d681SAndroid Build Coastguard Worker; CHECK: call void @use(i64 %div) 65*9880d681SAndroid Build Coastguard Workerentry: 66*9880d681SAndroid Build Coastguard Worker br label %loop 67*9880d681SAndroid Build Coastguard Workerloop: ; preds = %entry, %for.inc 68*9880d681SAndroid Build Coastguard Worker br label %loop-if 69*9880d681SAndroid Build Coastguard Workerloop-if: 70*9880d681SAndroid Build Coastguard Worker %div = udiv i64 %x, %y 71*9880d681SAndroid Build Coastguard Worker call void @use(i64 %div) 72*9880d681SAndroid Build Coastguard Worker br label %loop 73*9880d681SAndroid Build Coastguard Worker} 74