1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -S -passes='move-auto-init' -verify-memoryssa | FileCheck %s
4 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
6 define void @foo(i32 %x) {
9 ; CHECK-NEXT: [[BUFFER:%.*]] = alloca [80 x i32], align 16
10 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 16 [[BUFFER]], i8 -86, i64 320, i1 false), !annotation [[META0:![0-9]+]]
11 ; CHECK-NEXT: br label [[DO_BODY:%.*]]
13 ; CHECK-NEXT: [[X_ADDR_0:%.*]] = phi i32 [ [[X:%.*]], [[ENTRY:%.*]] ], [ [[DEC:%.*]], [[DO_COND:%.*]] ]
14 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [80 x i32], ptr [[BUFFER]], i64 0, i64 0
15 ; CHECK-NEXT: call void @dump(ptr [[ARRAYIDX]])
16 ; CHECK-NEXT: br label [[DO_COND]]
18 ; CHECK-NEXT: [[DEC]] = add nsw i32 [[X_ADDR_0]], -1
19 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne i32 [[X_ADDR_0]], 0
20 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[DO_BODY]], label [[DO_END:%.*]]
22 ; CHECK-NEXT: ret void
26 %buffer = alloca [80 x i32], align 16
27 call void @llvm.memset.p0.i64(ptr align 16 %buffer, i8 -86, i64 320, i1 false), !annotation !0
30 do.body: ; preds = %do.cond, %entry
31 %x.addr.0 = phi i32 [ %x, %entry ], [ %dec, %do.cond ]
32 %arrayidx = getelementptr inbounds [80 x i32], ptr %buffer, i64 0, i64 0
33 call void @dump(ptr %arrayidx)
36 do.cond: ; preds = %do.body
37 %dec = add nsw i32 %x.addr.0, -1
38 %tobool = icmp ne i32 %x.addr.0, 0
39 br i1 %tobool, label %do.body, label %do.end
41 do.end: ; preds = %do.cond
45 declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg)
47 declare void @dump(ptr )
49 define void @bar(i32 %x, i32 %y) {
52 ; CHECK-NEXT: [[BUFFER:%.*]] = alloca [80 x i32], align 16
53 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne i32 [[Y:%.*]], 0
54 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
56 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 16 [[BUFFER]], i8 -86, i64 320, i1 false), !annotation [[META0]]
57 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[X:%.*]], [[Y]]
58 ; CHECK-NEXT: br label [[DO_BODY:%.*]]
60 ; CHECK-NEXT: [[X_ADDR_0:%.*]] = phi i32 [ [[ADD]], [[IF_THEN]] ], [ [[DEC:%.*]], [[DO_COND:%.*]] ]
61 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [80 x i32], ptr [[BUFFER]], i64 0, i64 0
62 ; CHECK-NEXT: call void @dump(ptr [[ARRAYIDX]])
63 ; CHECK-NEXT: br label [[DO_COND]]
65 ; CHECK-NEXT: [[DEC]] = add nsw i32 [[X_ADDR_0]], -1
66 ; CHECK-NEXT: [[TOBOOL1:%.*]] = icmp ne i32 [[X_ADDR_0]], 0
67 ; CHECK-NEXT: br i1 [[TOBOOL1]], label [[DO_BODY]], label [[DO_END:%.*]]
69 ; CHECK-NEXT: br label [[IF_END]]
71 ; CHECK-NEXT: ret void
75 %buffer = alloca [80 x i32], align 16
76 call void @llvm.memset.p0.i64(ptr align 16 %buffer, i8 -86, i64 320, i1 false), !annotation !0
77 %tobool = icmp ne i32 %y, 0
78 br i1 %tobool, label %if.then, label %if.end
80 if.then: ; preds = %entry
81 %add = add nsw i32 %x, %y
84 do.body: ; preds = %do.cond, %if.then
85 %x.addr.0 = phi i32 [ %add, %if.then ], [ %dec, %do.cond ]
86 %arrayidx = getelementptr inbounds [80 x i32], ptr %buffer, i64 0, i64 0
87 call void @dump(ptr %arrayidx)
90 do.cond: ; preds = %do.body
91 %dec = add nsw i32 %x.addr.0, -1
92 %tobool1 = icmp ne i32 %x.addr.0, 0
93 br i1 %tobool1, label %do.body, label %do.end
95 do.end: ; preds = %do.cond
98 if.end: ; preds = %do.end, %entry
102 declare void @dummy()
104 define void @unreachable_pred() {
105 ; CHECK-LABEL: @unreachable_pred(
107 ; CHECK-NEXT: [[P:%.*]] = alloca [2 x i16], i32 0, align 2
108 ; CHECK-NEXT: store i32 0, ptr [[P]], align 2, !annotation [[META0]]
109 ; CHECK-NEXT: br i1 true, label [[LOOP:%.*]], label [[USEBB:%.*]]
111 ; CHECK-NEXT: call void @dummy()
112 ; CHECK-NEXT: br label [[LOOP]]
114 ; CHECK-NEXT: br label [[LOOP]]
116 ; CHECK-NEXT: br label [[LOOP]]
118 ; CHECK-NEXT: [[USE_P:%.*]] = icmp ult ptr null, [[P]]
119 ; CHECK-NEXT: ret void
122 %p = alloca [2 x i16], i32 0, align 2
123 store i32 0, ptr %p, align 2, !annotation !0
124 br i1 true, label %loop, label %usebb
137 %use_p = icmp ult ptr null, %p