237 lines · plain
1; RUN: opt -aa-pipeline=basic-aa -passes='require<opt-remark-emit>,loop-mssa(loop-simplifycfg,licm)' -S < %s | FileCheck %s2; RUN: opt -S -passes=licm -verify-memoryssa < %s | FileCheck %s3 4target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"5target triple = "x86_64-unknown-linux-gnu"6 7; Make sure the basic alloca pointer hoisting works:8; CHECK-LABEL: @test19; CHECK: load i32, ptr %c, align 410; CHECK: for.body:11 12; Function Attrs: nounwind uwtable13define void @test1(ptr nocapture %a, ptr nocapture readonly %b, i32 %n) #0 {14entry:15 %cmp6 = icmp sgt i32 %n, 016 %c = alloca i3217 br i1 %cmp6, label %for.body, label %for.end18 19for.body: ; preds = %entry, %for.inc20 %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]21 %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv22 %0 = load i32, ptr %arrayidx, align 423 %cmp1 = icmp sgt i32 %0, 024 br i1 %cmp1, label %if.then, label %for.inc25 26if.then: ; preds = %for.body27 %1 = load i32, ptr %c, align 428 %arrayidx3 = getelementptr inbounds i32, ptr %b, i64 %indvars.iv29 %2 = load i32, ptr %arrayidx3, align 430 %mul = mul nsw i32 %2, %131 store i32 %mul, ptr %arrayidx, align 432 br label %for.inc33 34for.inc: ; preds = %for.body, %if.then35 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 136 %lftr.wideiv = trunc i64 %indvars.iv.next to i3237 %exitcond = icmp eq i32 %lftr.wideiv, %n38 br i1 %exitcond, label %for.end, label %for.body39 40for.end: ; preds = %for.inc, %entry41 ret void42}43 44; Make sure the basic alloca pointer hoisting works through a bitcast to a45; pointer to a smaller type:46; CHECK-LABEL: @test247; CHECK: load i32, ptr %ca, align 448; CHECK: for.body:49 50; Function Attrs: nounwind uwtable51define void @test2(ptr nocapture %a, ptr nocapture readonly %b, i32 %n) #0 {52entry:53 %cmp6 = icmp sgt i32 %n, 054 %ca = alloca i6455 br i1 %cmp6, label %for.body, label %for.end56 57for.body: ; preds = %entry, %for.inc58 %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]59 %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv60 %0 = load i32, ptr %arrayidx, align 461 %cmp1 = icmp sgt i32 %0, 062 br i1 %cmp1, label %if.then, label %for.inc63 64if.then: ; preds = %for.body65 %1 = load i32, ptr %ca, align 466 %arrayidx3 = getelementptr inbounds i32, ptr %b, i64 %indvars.iv67 %2 = load i32, ptr %arrayidx3, align 468 %mul = mul nsw i32 %2, %169 store i32 %mul, ptr %arrayidx, align 470 br label %for.inc71 72for.inc: ; preds = %for.body, %if.then73 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 174 %lftr.wideiv = trunc i64 %indvars.iv.next to i3275 %exitcond = icmp eq i32 %lftr.wideiv, %n76 br i1 %exitcond, label %for.end, label %for.body77 78for.end: ; preds = %for.inc, %entry79 ret void80}81 82; Make sure the basic alloca pointer hoisting works through an addrspacecast83; CHECK-LABEL: @test2_addrspacecast84; CHECK: load i32, ptr addrspace(1) %c, align 485; CHECK: for.body:86 87; Function Attrs: nounwind uwtable88define void @test2_addrspacecast(ptr addrspace(1) nocapture %a, ptr addrspace(1) nocapture readonly %b, i32 %n) #0 {89entry:90 %cmp6 = icmp sgt i32 %n, 091 %ca = alloca i6492 %c = addrspacecast ptr %ca to ptr addrspace(1)93 br i1 %cmp6, label %for.body, label %for.end94 95for.body: ; preds = %entry, %for.inc96 %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]97 %arrayidx = getelementptr inbounds i32, ptr addrspace(1) %a, i64 %indvars.iv98 %0 = load i32, ptr addrspace(1) %arrayidx, align 499 %cmp1 = icmp sgt i32 %0, 0100 br i1 %cmp1, label %if.then, label %for.inc101 102if.then: ; preds = %for.body103 %1 = load i32, ptr addrspace(1) %c, align 4104 %arrayidx3 = getelementptr inbounds i32, ptr addrspace(1) %b, i64 %indvars.iv105 %2 = load i32, ptr addrspace(1) %arrayidx3, align 4106 %mul = mul nsw i32 %2, %1107 store i32 %mul, ptr addrspace(1) %arrayidx, align 4108 br label %for.inc109 110for.inc: ; preds = %for.body, %if.then111 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1112 %lftr.wideiv = trunc i64 %indvars.iv.next to i32113 %exitcond = icmp eq i32 %lftr.wideiv, %n114 br i1 %exitcond, label %for.end, label %for.body115 116for.end: ; preds = %for.inc, %entry117 ret void118}119 120; Make sure the basic alloca pointer hoisting works through a bitcast to a121; pointer to a smaller type (where the bitcast also needs to be hoisted):122; CHECK-LABEL: @test3123; CHECK: load i32, ptr %ca, align 4124; CHECK: for.body:125 126; Function Attrs: nounwind uwtable127define void @test3(ptr nocapture %a, ptr nocapture readonly %b, i32 %n) #0 {128entry:129 %cmp6 = icmp sgt i32 %n, 0130 %ca = alloca i64131 br i1 %cmp6, label %for.body, label %for.end132 133for.body: ; preds = %entry, %for.inc134 %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]135 %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv136 %0 = load i32, ptr %arrayidx, align 4137 %cmp1 = icmp sgt i32 %0, 0138 br i1 %cmp1, label %if.then, label %for.inc139 140if.then: ; preds = %for.body141 %1 = load i32, ptr %ca, align 4142 %arrayidx3 = getelementptr inbounds i32, ptr %b, i64 %indvars.iv143 %2 = load i32, ptr %arrayidx3, align 4144 %mul = mul nsw i32 %2, %1145 store i32 %mul, ptr %arrayidx, align 4146 br label %for.inc147 148for.inc: ; preds = %for.body, %if.then149 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1150 %lftr.wideiv = trunc i64 %indvars.iv.next to i32151 %exitcond = icmp eq i32 %lftr.wideiv, %n152 br i1 %exitcond, label %for.end, label %for.body153 154for.end: ; preds = %for.inc, %entry155 ret void156}157 158; Make sure the basic alloca pointer hoisting does not happen through a bitcast159; to a pointer to a larger type:160; CHECK-LABEL: @test4161; CHECK: for.body:162; CHECK: load i32, ptr %ca, align 4163 164; Function Attrs: nounwind uwtable165define void @test4(ptr nocapture %a, ptr nocapture readonly %b, i32 %n) #0 {166entry:167 %cmp6 = icmp sgt i32 %n, 0168 %ca = alloca i16169 br i1 %cmp6, label %for.body, label %for.end170 171for.body: ; preds = %entry, %for.inc172 %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]173 %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv174 %0 = load i32, ptr %arrayidx, align 4175 %cmp1 = icmp sgt i32 %0, 0176 br i1 %cmp1, label %if.then, label %for.inc177 178if.then: ; preds = %for.body179 %1 = load i32, ptr %ca, align 4180 %arrayidx3 = getelementptr inbounds i32, ptr %b, i64 %indvars.iv181 %2 = load i32, ptr %arrayidx3, align 4182 %mul = mul nsw i32 %2, %1183 store i32 %mul, ptr %arrayidx, align 4184 br label %for.inc185 186for.inc: ; preds = %for.body, %if.then187 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1188 %lftr.wideiv = trunc i64 %indvars.iv.next to i32189 %exitcond = icmp eq i32 %lftr.wideiv, %n190 br i1 %exitcond, label %for.end, label %for.body191 192for.end: ; preds = %for.inc, %entry193 ret void194}195 196; Don't crash on bitcasts to unsized types.197; CHECK-LABEL: @test5198; CHECK: for.body:199; CHECK: load i32, ptr %ca, align 4200 201%atype = type opaque202 203; Function Attrs: nounwind uwtable204define void @test5(ptr nocapture %a, ptr nocapture readonly %b, i32 %n) #0 {205entry:206 %cmp6 = icmp sgt i32 %n, 0207 %ca = alloca i16208 br i1 %cmp6, label %for.body, label %for.end209 210for.body: ; preds = %entry, %for.inc211 %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]212 %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv213 %0 = load i32, ptr %arrayidx, align 4214 %cmp1 = icmp sgt i32 %0, 0215 br i1 %cmp1, label %if.then, label %for.inc216 217if.then: ; preds = %for.body218 %1 = load i32, ptr %ca, align 4219 %arrayidx3 = getelementptr inbounds i32, ptr %b, i64 %indvars.iv220 %2 = load i32, ptr %arrayidx3, align 4221 %mul = mul nsw i32 %2, %1222 store i32 %mul, ptr %arrayidx, align 4223 br label %for.inc224 225for.inc: ; preds = %for.body, %if.then226 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1227 %lftr.wideiv = trunc i64 %indvars.iv.next to i32228 %exitcond = icmp eq i32 %lftr.wideiv, %n229 br i1 %exitcond, label %for.end, label %for.body230 231for.end: ; preds = %for.inc, %entry232 ret void233}234 235attributes #0 = { nounwind uwtable }236 237