1*9880d681SAndroid Build Coastguard Worker; RUN: opt -S -basicaa -licm < %s | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker; RUN: opt -aa-pipeline=basic-aa -passes='loop-simplify,require<aa>,require<targetir>,require<scalar-evolution>,loop(simplify-cfg,licm)' -S < %s | FileCheck %s 3*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-m:e-i64:64-f80: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; Make sure the basic alloca pointer hoisting works: 7*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test1 8*9880d681SAndroid Build Coastguard Worker; CHECK: load i32, i32* %c, align 4 9*9880d681SAndroid Build Coastguard Worker; CHECK: for.body: 10*9880d681SAndroid Build Coastguard Worker 11*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind uwtable 12*9880d681SAndroid Build Coastguard Workerdefine void @test1(i32* nocapture %a, i32* nocapture readonly %b, i32 %n) #0 { 13*9880d681SAndroid Build Coastguard Workerentry: 14*9880d681SAndroid Build Coastguard Worker %cmp6 = icmp sgt i32 %n, 0 15*9880d681SAndroid Build Coastguard Worker %c = alloca i32 16*9880d681SAndroid Build Coastguard Worker br i1 %cmp6, label %for.body, label %for.end 17*9880d681SAndroid Build Coastguard Worker 18*9880d681SAndroid Build Coastguard Workerfor.body: ; preds = %entry, %for.inc 19*9880d681SAndroid Build Coastguard Worker %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ] 20*9880d681SAndroid Build Coastguard Worker %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv 21*9880d681SAndroid Build Coastguard Worker %0 = load i32, i32* %arrayidx, align 4 22*9880d681SAndroid Build Coastguard Worker %cmp1 = icmp sgt i32 %0, 0 23*9880d681SAndroid Build Coastguard Worker br i1 %cmp1, label %if.then, label %for.inc 24*9880d681SAndroid Build Coastguard Worker 25*9880d681SAndroid Build Coastguard Workerif.then: ; preds = %for.body 26*9880d681SAndroid Build Coastguard Worker %1 = load i32, i32* %c, align 4 27*9880d681SAndroid Build Coastguard Worker %arrayidx3 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv 28*9880d681SAndroid Build Coastguard Worker %2 = load i32, i32* %arrayidx3, align 4 29*9880d681SAndroid Build Coastguard Worker %mul = mul nsw i32 %2, %1 30*9880d681SAndroid Build Coastguard Worker store i32 %mul, i32* %arrayidx, align 4 31*9880d681SAndroid Build Coastguard Worker br label %for.inc 32*9880d681SAndroid Build Coastguard Worker 33*9880d681SAndroid Build Coastguard Workerfor.inc: ; preds = %for.body, %if.then 34*9880d681SAndroid Build Coastguard Worker %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 35*9880d681SAndroid Build Coastguard Worker %lftr.wideiv = trunc i64 %indvars.iv.next to i32 36*9880d681SAndroid Build Coastguard Worker %exitcond = icmp eq i32 %lftr.wideiv, %n 37*9880d681SAndroid Build Coastguard Worker br i1 %exitcond, label %for.end, label %for.body 38*9880d681SAndroid Build Coastguard Worker 39*9880d681SAndroid Build Coastguard Workerfor.end: ; preds = %for.inc, %entry 40*9880d681SAndroid Build Coastguard Worker ret void 41*9880d681SAndroid Build Coastguard Worker} 42*9880d681SAndroid Build Coastguard Worker 43*9880d681SAndroid Build Coastguard Worker; Make sure the basic alloca pointer hoisting works through a bitcast to a 44*9880d681SAndroid Build Coastguard Worker; pointer to a smaller type: 45*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test2 46*9880d681SAndroid Build Coastguard Worker; CHECK: load i32, i32* %c, align 4 47*9880d681SAndroid Build Coastguard Worker; CHECK: for.body: 48*9880d681SAndroid Build Coastguard Worker 49*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind uwtable 50*9880d681SAndroid Build Coastguard Workerdefine void @test2(i32* nocapture %a, i32* nocapture readonly %b, i32 %n) #0 { 51*9880d681SAndroid Build Coastguard Workerentry: 52*9880d681SAndroid Build Coastguard Worker %cmp6 = icmp sgt i32 %n, 0 53*9880d681SAndroid Build Coastguard Worker %ca = alloca i64 54*9880d681SAndroid Build Coastguard Worker %c = bitcast i64* %ca to i32* 55*9880d681SAndroid Build Coastguard Worker br i1 %cmp6, label %for.body, label %for.end 56*9880d681SAndroid Build Coastguard Worker 57*9880d681SAndroid Build Coastguard Workerfor.body: ; preds = %entry, %for.inc 58*9880d681SAndroid Build Coastguard Worker %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ] 59*9880d681SAndroid Build Coastguard Worker %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv 60*9880d681SAndroid Build Coastguard Worker %0 = load i32, i32* %arrayidx, align 4 61*9880d681SAndroid Build Coastguard Worker %cmp1 = icmp sgt i32 %0, 0 62*9880d681SAndroid Build Coastguard Worker br i1 %cmp1, label %if.then, label %for.inc 63*9880d681SAndroid Build Coastguard Worker 64*9880d681SAndroid Build Coastguard Workerif.then: ; preds = %for.body 65*9880d681SAndroid Build Coastguard Worker %1 = load i32, i32* %c, align 4 66*9880d681SAndroid Build Coastguard Worker %arrayidx3 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv 67*9880d681SAndroid Build Coastguard Worker %2 = load i32, i32* %arrayidx3, align 4 68*9880d681SAndroid Build Coastguard Worker %mul = mul nsw i32 %2, %1 69*9880d681SAndroid Build Coastguard Worker store i32 %mul, i32* %arrayidx, align 4 70*9880d681SAndroid Build Coastguard Worker br label %for.inc 71*9880d681SAndroid Build Coastguard Worker 72*9880d681SAndroid Build Coastguard Workerfor.inc: ; preds = %for.body, %if.then 73*9880d681SAndroid Build Coastguard Worker %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 74*9880d681SAndroid Build Coastguard Worker %lftr.wideiv = trunc i64 %indvars.iv.next to i32 75*9880d681SAndroid Build Coastguard Worker %exitcond = icmp eq i32 %lftr.wideiv, %n 76*9880d681SAndroid Build Coastguard Worker br i1 %exitcond, label %for.end, label %for.body 77*9880d681SAndroid Build Coastguard Worker 78*9880d681SAndroid Build Coastguard Workerfor.end: ; preds = %for.inc, %entry 79*9880d681SAndroid Build Coastguard Worker ret void 80*9880d681SAndroid Build Coastguard Worker} 81*9880d681SAndroid Build Coastguard Worker 82*9880d681SAndroid Build Coastguard Worker; Make sure the basic alloca pointer hoisting works through an addrspacecast 83*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test2_addrspacecast 84*9880d681SAndroid Build Coastguard Worker; CHECK: load i32, i32 addrspace(1)* %c, align 4 85*9880d681SAndroid Build Coastguard Worker; CHECK: for.body: 86*9880d681SAndroid Build Coastguard Worker 87*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind uwtable 88*9880d681SAndroid Build Coastguard Workerdefine void @test2_addrspacecast(i32 addrspace(1)* nocapture %a, i32 addrspace(1)* nocapture readonly %b, i32 %n) #0 { 89*9880d681SAndroid Build Coastguard Workerentry: 90*9880d681SAndroid Build Coastguard Worker %cmp6 = icmp sgt i32 %n, 0 91*9880d681SAndroid Build Coastguard Worker %ca = alloca i64 92*9880d681SAndroid Build Coastguard Worker %c = addrspacecast i64* %ca to i32 addrspace(1)* 93*9880d681SAndroid Build Coastguard Worker br i1 %cmp6, label %for.body, label %for.end 94*9880d681SAndroid Build Coastguard Worker 95*9880d681SAndroid Build Coastguard Workerfor.body: ; preds = %entry, %for.inc 96*9880d681SAndroid Build Coastguard Worker %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ] 97*9880d681SAndroid Build Coastguard Worker %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %a, i64 %indvars.iv 98*9880d681SAndroid Build Coastguard Worker %0 = load i32, i32 addrspace(1)* %arrayidx, align 4 99*9880d681SAndroid Build Coastguard Worker %cmp1 = icmp sgt i32 %0, 0 100*9880d681SAndroid Build Coastguard Worker br i1 %cmp1, label %if.then, label %for.inc 101*9880d681SAndroid Build Coastguard Worker 102*9880d681SAndroid Build Coastguard Workerif.then: ; preds = %for.body 103*9880d681SAndroid Build Coastguard Worker %1 = load i32, i32 addrspace(1)* %c, align 4 104*9880d681SAndroid Build Coastguard Worker %arrayidx3 = getelementptr inbounds i32, i32 addrspace(1)* %b, i64 %indvars.iv 105*9880d681SAndroid Build Coastguard Worker %2 = load i32, i32 addrspace(1)* %arrayidx3, align 4 106*9880d681SAndroid Build Coastguard Worker %mul = mul nsw i32 %2, %1 107*9880d681SAndroid Build Coastguard Worker store i32 %mul, i32 addrspace(1)* %arrayidx, align 4 108*9880d681SAndroid Build Coastguard Worker br label %for.inc 109*9880d681SAndroid Build Coastguard Worker 110*9880d681SAndroid Build Coastguard Workerfor.inc: ; preds = %for.body, %if.then 111*9880d681SAndroid Build Coastguard Worker %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 112*9880d681SAndroid Build Coastguard Worker %lftr.wideiv = trunc i64 %indvars.iv.next to i32 113*9880d681SAndroid Build Coastguard Worker %exitcond = icmp eq i32 %lftr.wideiv, %n 114*9880d681SAndroid Build Coastguard Worker br i1 %exitcond, label %for.end, label %for.body 115*9880d681SAndroid Build Coastguard Worker 116*9880d681SAndroid Build Coastguard Workerfor.end: ; preds = %for.inc, %entry 117*9880d681SAndroid Build Coastguard Worker ret void 118*9880d681SAndroid Build Coastguard Worker} 119*9880d681SAndroid Build Coastguard Worker 120*9880d681SAndroid Build Coastguard Worker; Make sure the basic alloca pointer hoisting works through a bitcast to a 121*9880d681SAndroid Build Coastguard Worker; pointer to a smaller type (where the bitcast also needs to be hoisted): 122*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test3 123*9880d681SAndroid Build Coastguard Worker; CHECK: load i32, i32* %c, align 4 124*9880d681SAndroid Build Coastguard Worker; CHECK: for.body: 125*9880d681SAndroid Build Coastguard Worker 126*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind uwtable 127*9880d681SAndroid Build Coastguard Workerdefine void @test3(i32* nocapture %a, i32* nocapture readonly %b, i32 %n) #0 { 128*9880d681SAndroid Build Coastguard Workerentry: 129*9880d681SAndroid Build Coastguard Worker %cmp6 = icmp sgt i32 %n, 0 130*9880d681SAndroid Build Coastguard Worker %ca = alloca i64 131*9880d681SAndroid Build Coastguard Worker br i1 %cmp6, label %for.body, label %for.end 132*9880d681SAndroid Build Coastguard Worker 133*9880d681SAndroid Build Coastguard Workerfor.body: ; preds = %entry, %for.inc 134*9880d681SAndroid Build Coastguard Worker %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ] 135*9880d681SAndroid Build Coastguard Worker %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv 136*9880d681SAndroid Build Coastguard Worker %0 = load i32, i32* %arrayidx, align 4 137*9880d681SAndroid Build Coastguard Worker %cmp1 = icmp sgt i32 %0, 0 138*9880d681SAndroid Build Coastguard Worker br i1 %cmp1, label %if.then, label %for.inc 139*9880d681SAndroid Build Coastguard Worker 140*9880d681SAndroid Build Coastguard Workerif.then: ; preds = %for.body 141*9880d681SAndroid Build Coastguard Worker %c = bitcast i64* %ca to i32* 142*9880d681SAndroid Build Coastguard Worker %1 = load i32, i32* %c, align 4 143*9880d681SAndroid Build Coastguard Worker %arrayidx3 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv 144*9880d681SAndroid Build Coastguard Worker %2 = load i32, i32* %arrayidx3, align 4 145*9880d681SAndroid Build Coastguard Worker %mul = mul nsw i32 %2, %1 146*9880d681SAndroid Build Coastguard Worker store i32 %mul, i32* %arrayidx, align 4 147*9880d681SAndroid Build Coastguard Worker br label %for.inc 148*9880d681SAndroid Build Coastguard Worker 149*9880d681SAndroid Build Coastguard Workerfor.inc: ; preds = %for.body, %if.then 150*9880d681SAndroid Build Coastguard Worker %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 151*9880d681SAndroid Build Coastguard Worker %lftr.wideiv = trunc i64 %indvars.iv.next to i32 152*9880d681SAndroid Build Coastguard Worker %exitcond = icmp eq i32 %lftr.wideiv, %n 153*9880d681SAndroid Build Coastguard Worker br i1 %exitcond, label %for.end, label %for.body 154*9880d681SAndroid Build Coastguard Worker 155*9880d681SAndroid Build Coastguard Workerfor.end: ; preds = %for.inc, %entry 156*9880d681SAndroid Build Coastguard Worker ret void 157*9880d681SAndroid Build Coastguard Worker} 158*9880d681SAndroid Build Coastguard Worker 159*9880d681SAndroid Build Coastguard Worker; Make sure the basic alloca pointer hoisting does not happen through a bitcast 160*9880d681SAndroid Build Coastguard Worker; to a pointer to a larger type: 161*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test4 162*9880d681SAndroid Build Coastguard Worker; CHECK: for.body: 163*9880d681SAndroid Build Coastguard Worker; CHECK: load i32, i32* %c, align 4 164*9880d681SAndroid Build Coastguard Worker 165*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind uwtable 166*9880d681SAndroid Build Coastguard Workerdefine void @test4(i32* nocapture %a, i32* nocapture readonly %b, i32 %n) #0 { 167*9880d681SAndroid Build Coastguard Workerentry: 168*9880d681SAndroid Build Coastguard Worker %cmp6 = icmp sgt i32 %n, 0 169*9880d681SAndroid Build Coastguard Worker %ca = alloca i16 170*9880d681SAndroid Build Coastguard Worker %c = bitcast i16* %ca to i32* 171*9880d681SAndroid Build Coastguard Worker br i1 %cmp6, label %for.body, label %for.end 172*9880d681SAndroid Build Coastguard Worker 173*9880d681SAndroid Build Coastguard Workerfor.body: ; preds = %entry, %for.inc 174*9880d681SAndroid Build Coastguard Worker %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ] 175*9880d681SAndroid Build Coastguard Worker %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv 176*9880d681SAndroid Build Coastguard Worker %0 = load i32, i32* %arrayidx, align 4 177*9880d681SAndroid Build Coastguard Worker %cmp1 = icmp sgt i32 %0, 0 178*9880d681SAndroid Build Coastguard Worker br i1 %cmp1, label %if.then, label %for.inc 179*9880d681SAndroid Build Coastguard Worker 180*9880d681SAndroid Build Coastguard Workerif.then: ; preds = %for.body 181*9880d681SAndroid Build Coastguard Worker %1 = load i32, i32* %c, align 4 182*9880d681SAndroid Build Coastguard Worker %arrayidx3 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv 183*9880d681SAndroid Build Coastguard Worker %2 = load i32, i32* %arrayidx3, align 4 184*9880d681SAndroid Build Coastguard Worker %mul = mul nsw i32 %2, %1 185*9880d681SAndroid Build Coastguard Worker store i32 %mul, i32* %arrayidx, align 4 186*9880d681SAndroid Build Coastguard Worker br label %for.inc 187*9880d681SAndroid Build Coastguard Worker 188*9880d681SAndroid Build Coastguard Workerfor.inc: ; preds = %for.body, %if.then 189*9880d681SAndroid Build Coastguard Worker %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 190*9880d681SAndroid Build Coastguard Worker %lftr.wideiv = trunc i64 %indvars.iv.next to i32 191*9880d681SAndroid Build Coastguard Worker %exitcond = icmp eq i32 %lftr.wideiv, %n 192*9880d681SAndroid Build Coastguard Worker br i1 %exitcond, label %for.end, label %for.body 193*9880d681SAndroid Build Coastguard Worker 194*9880d681SAndroid Build Coastguard Workerfor.end: ; preds = %for.inc, %entry 195*9880d681SAndroid Build Coastguard Worker ret void 196*9880d681SAndroid Build Coastguard Worker} 197*9880d681SAndroid Build Coastguard Worker 198*9880d681SAndroid Build Coastguard Worker; Don't crash on bitcasts to unsized types. 199*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test5 200*9880d681SAndroid Build Coastguard Worker; CHECK: for.body: 201*9880d681SAndroid Build Coastguard Worker; CHECK: load i32, i32* %c, align 4 202*9880d681SAndroid Build Coastguard Worker 203*9880d681SAndroid Build Coastguard Worker%atype = type opaque 204*9880d681SAndroid Build Coastguard Worker 205*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind uwtable 206*9880d681SAndroid Build Coastguard Workerdefine void @test5(i32* nocapture %a, i32* nocapture readonly %b, i32 %n) #0 { 207*9880d681SAndroid Build Coastguard Workerentry: 208*9880d681SAndroid Build Coastguard Worker %cmp6 = icmp sgt i32 %n, 0 209*9880d681SAndroid Build Coastguard Worker %ca = alloca i16 210*9880d681SAndroid Build Coastguard Worker %cab = bitcast i16* %ca to %atype* 211*9880d681SAndroid Build Coastguard Worker %c = bitcast %atype* %cab to i32* 212*9880d681SAndroid Build Coastguard Worker br i1 %cmp6, label %for.body, label %for.end 213*9880d681SAndroid Build Coastguard Worker 214*9880d681SAndroid Build Coastguard Workerfor.body: ; preds = %entry, %for.inc 215*9880d681SAndroid Build Coastguard Worker %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ] 216*9880d681SAndroid Build Coastguard Worker %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv 217*9880d681SAndroid Build Coastguard Worker %0 = load i32, i32* %arrayidx, align 4 218*9880d681SAndroid Build Coastguard Worker %cmp1 = icmp sgt i32 %0, 0 219*9880d681SAndroid Build Coastguard Worker br i1 %cmp1, label %if.then, label %for.inc 220*9880d681SAndroid Build Coastguard Worker 221*9880d681SAndroid Build Coastguard Workerif.then: ; preds = %for.body 222*9880d681SAndroid Build Coastguard Worker %1 = load i32, i32* %c, align 4 223*9880d681SAndroid Build Coastguard Worker %arrayidx3 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv 224*9880d681SAndroid Build Coastguard Worker %2 = load i32, i32* %arrayidx3, align 4 225*9880d681SAndroid Build Coastguard Worker %mul = mul nsw i32 %2, %1 226*9880d681SAndroid Build Coastguard Worker store i32 %mul, i32* %arrayidx, align 4 227*9880d681SAndroid Build Coastguard Worker br label %for.inc 228*9880d681SAndroid Build Coastguard Worker 229*9880d681SAndroid Build Coastguard Workerfor.inc: ; preds = %for.body, %if.then 230*9880d681SAndroid Build Coastguard Worker %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 231*9880d681SAndroid Build Coastguard Worker %lftr.wideiv = trunc i64 %indvars.iv.next to i32 232*9880d681SAndroid Build Coastguard Worker %exitcond = icmp eq i32 %lftr.wideiv, %n 233*9880d681SAndroid Build Coastguard Worker br i1 %exitcond, label %for.end, label %for.body 234*9880d681SAndroid Build Coastguard Worker 235*9880d681SAndroid Build Coastguard Workerfor.end: ; preds = %for.inc, %entry 236*9880d681SAndroid Build Coastguard Worker ret void 237*9880d681SAndroid Build Coastguard Worker} 238*9880d681SAndroid Build Coastguard Worker 239*9880d681SAndroid Build Coastguard Workerattributes #0 = { nounwind uwtable } 240*9880d681SAndroid Build Coastguard Worker 241