1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -gvn -S %s | 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 declare void @foo(i64 %v) readonly
8 define void @non_local_load(i32* %ptr) {
9 ; CHECK-LABEL: @non_local_load(
11 ; CHECK-NEXT: store i32 0, i32* [[PTR:%.*]], align 4
12 ; CHECK-NEXT: br label [[LOOP:%.*]]
14 ; CHECK-NEXT: [[VAL:%.*]] = phi i32 [ [[VAL_INC:%.*]], [[LOOP]] ], [ 0, [[ENTRY:%.*]] ]
15 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[LOOP]] ], [ 0, [[ENTRY]] ]
16 ; CHECK-NEXT: [[VAL_INC]] = add i32 [[VAL]], 1
17 ; CHECK-NEXT: store i32 [[VAL_INC]], i32* [[PTR]], align 4
18 ; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1
19 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp eq i32 [[IV]], 1000
20 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[EXIT:%.*]], label [[LOOP]]
22 ; CHECK-NEXT: ret void
25 store i32 0, i32* %ptr
29 %iv = phi i32 [ %iv.next, %loop ], [ 0, %entry ]
30 %val = load i32, i32* %ptr
31 %val.inc = add i32 %val, 1
32 store i32 %val.inc, i32* %ptr
33 %iv.next = add i32 %iv, 1
34 %loop.cond = icmp eq i32 %iv, 1000
35 br i1 %loop.cond, label %exit, label %loop
41 define void @non_local_load_with_iv_zext(i32* %ptr) {
42 ; CHECK-LABEL: @non_local_load_with_iv_zext(
44 ; CHECK-NEXT: store i32 0, i32* [[PTR:%.*]], align 4
45 ; CHECK-NEXT: br label [[LOOP:%.*]]
47 ; CHECK-NEXT: [[VAL:%.*]] = phi i32 [ [[VAL_INC:%.*]], [[LOOP]] ], [ 0, [[ENTRY:%.*]] ]
48 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[LOOP]] ], [ 0, [[ENTRY]] ]
49 ; CHECK-NEXT: [[VAL_INC]] = add i32 [[VAL]], 1
50 ; CHECK-NEXT: store i32 [[VAL_INC]], i32* [[PTR]], align 4
51 ; CHECK-NEXT: [[IV_WIDE:%.*]] = zext i32 [[IV]] to i64
52 ; CHECK-NEXT: call void @foo(i64 [[IV_WIDE]])
53 ; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1
54 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp eq i32 [[IV]], 1000
55 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[EXIT:%.*]], label [[LOOP]]
57 ; CHECK-NEXT: ret void
60 store i32 0, i32* %ptr
64 %iv = phi i32 [ %iv.next, %loop ], [ 0, %entry ]
65 %val = load i32, i32* %ptr
66 %val.inc = add i32 %val, 1
67 store i32 %val.inc, i32* %ptr
68 %iv.wide = zext i32 %iv to i64
69 call void @foo(i64 %iv.wide)
70 %iv.next = add i32 %iv, 1
71 %loop.cond = icmp eq i32 %iv, 1000
72 br i1 %loop.cond, label %exit, label %loop
78 define void @two_non_local_loads(i32* %ptr1) {
79 ; CHECK-LABEL: @two_non_local_loads(
81 ; CHECK-NEXT: [[PTR2:%.*]] = getelementptr inbounds i32, i32* [[PTR1:%.*]], i64 1
82 ; CHECK-NEXT: store i32 0, i32* [[PTR1]], align 4
83 ; CHECK-NEXT: store i32 0, i32* [[PTR2]], align 4
84 ; CHECK-NEXT: br label [[LOOP:%.*]]
86 ; CHECK-NEXT: [[VAL2:%.*]] = phi i32 [ [[VAL2_INC:%.*]], [[LOOP]] ], [ 0, [[ENTRY:%.*]] ]
87 ; CHECK-NEXT: [[VAL1:%.*]] = phi i32 [ [[VAL1_INC:%.*]], [[LOOP]] ], [ 0, [[ENTRY]] ]
88 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[LOOP]] ], [ 0, [[ENTRY]] ]
89 ; CHECK-NEXT: [[VAL1_INC]] = add i32 [[VAL1]], 1
90 ; CHECK-NEXT: store i32 [[VAL1_INC]], i32* [[PTR1]], align 4
91 ; CHECK-NEXT: [[VAL2_INC]] = add i32 [[VAL2]], 1
92 ; CHECK-NEXT: store i32 [[VAL2_INC]], i32* [[PTR2]], align 4
93 ; CHECK-NEXT: [[IV_WIDE:%.*]] = zext i32 [[IV]] to i64
94 ; CHECK-NEXT: call void @foo(i64 [[IV_WIDE]])
95 ; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1
96 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp eq i32 [[IV]], 1000
97 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[EXIT:%.*]], label [[LOOP]]
99 ; CHECK-NEXT: ret void
102 %ptr2 = getelementptr inbounds i32, i32* %ptr1, i64 1
103 store i32 0, i32* %ptr1
104 store i32 0, i32* %ptr2
108 %iv = phi i32 [ %iv.next, %loop ], [ 0, %entry ]
109 %val1 = load i32, i32* %ptr1
110 %val1.inc = add i32 %val1, 1
111 store i32 %val1.inc, i32* %ptr1
112 %val2 = load i32, i32* %ptr2
113 %val2.inc = add i32 %val2, 1
114 store i32 %val2.inc, i32* %ptr2
115 %iv.wide = zext i32 %iv to i64
116 call void @foo(i64 %iv.wide)
117 %iv.next = add i32 %iv, 1
118 %loop.cond = icmp eq i32 %iv, 1000
119 br i1 %loop.cond, label %exit, label %loop