1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=gvn -enable-split-backedge-in-load-pre -S %s | FileCheck %s
4 ; Test case for PR31651.
6 target datalayout = "p:16:16"
8 declare void @use(i16) readonly
10 define i16 @test_PR31651(ptr %ub.16) {
11 ; CHECK-LABEL: @test_PR31651(
12 ; CHECK-NEXT: br label [[LOOP_1_HEADER:%.*]]
13 ; CHECK: loop.1.header:
14 ; CHECK-NEXT: [[IV_1:%.*]] = phi i16 [ 0, [[TMP0:%.*]] ], [ [[IV_1_NEXT:%.*]], [[LOOP_1_LATCH:%.*]] ]
15 ; CHECK-NEXT: [[CMP_1:%.*]] = icmp eq i16 [[IV_1]], 0
16 ; CHECK-NEXT: br i1 [[CMP_1]], label [[CONT_1:%.*]], label [[THEN_1:%.*]]
18 ; CHECK-NEXT: [[_TMP18:%.*]] = add i16 [[IV_1]], -1
19 ; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr [4 x i16], ptr [[UB_16:%.*]], i16 1, i16 [[_TMP18]]
20 ; CHECK-NEXT: [[L_1:%.*]] = load i16, ptr [[GEP_1]], align 2
21 ; CHECK-NEXT: br label [[CONT_1]]
23 ; CHECK-NEXT: [[IV_1_SINK:%.*]] = phi i16 [ [[IV_1]], [[THEN_1]] ], [ 0, [[LOOP_1_HEADER]] ]
24 ; CHECK-NEXT: [[SINK:%.*]] = phi i16 [ [[L_1]], [[THEN_1]] ], [ 10, [[LOOP_1_HEADER]] ]
25 ; CHECK-NEXT: [[GEP_2:%.*]] = getelementptr [4 x i16], ptr [[UB_16]], i16 1, i16 [[IV_1_SINK]]
26 ; CHECK-NEXT: br i1 [[CMP_1]], label [[THEN_2:%.*]], label [[ELSE_2:%.*]]
28 ; CHECK-NEXT: [[GEP_3:%.*]] = getelementptr [4 x i16], ptr [[UB_16]], i16 1, i16 0
29 ; CHECK-NEXT: [[L_2:%.*]] = load i16, ptr [[GEP_3]], align 2
30 ; CHECK-NEXT: call void @use(i16 [[L_2]])
31 ; CHECK-NEXT: br label [[LOOP_1_LATCH]]
33 ; CHECK-NEXT: [[GEP_4:%.*]] = getelementptr [4 x i16], ptr [[UB_16]], i16 1, i16 [[IV_1]]
34 ; CHECK-NEXT: [[L_3:%.*]] = load i16, ptr [[GEP_4]], align 2
35 ; CHECK-NEXT: call void @use(i16 [[L_3]])
36 ; CHECK-NEXT: br label [[LOOP_1_LATCH]]
37 ; CHECK: loop.1.latch:
38 ; CHECK-NEXT: [[IV_1_NEXT]] = add i16 [[IV_1]], 1
39 ; CHECK-NEXT: [[CMP_3:%.*]] = icmp slt i16 [[IV_1_NEXT]], 2
40 ; CHECK-NEXT: br i1 [[CMP_3]], label [[LOOP_1_HEADER]], label [[LOOP_2:%.*]]
42 ; CHECK-NEXT: [[IV_2:%.*]] = phi i16 [ 0, [[LOOP_1_LATCH]] ], [ [[IV_2_NEXT:%.*]], [[LOOP_2]] ]
43 ; CHECK-NEXT: [[SUM:%.*]] = phi i16 [ 0, [[LOOP_1_LATCH]] ], [ [[SUM_NEXT:%.*]], [[LOOP_2]] ]
44 ; CHECK-NEXT: [[GEP_5:%.*]] = getelementptr [4 x i16], ptr [[UB_16]], i16 1, i16 [[IV_2]]
45 ; CHECK-NEXT: [[L_4:%.*]] = load i16, ptr [[GEP_5]], align 2
46 ; CHECK-NEXT: [[SUM_NEXT]] = add i16 [[SUM]], [[L_4]]
47 ; CHECK-NEXT: [[IV_2_NEXT]] = add i16 [[IV_2]], 1
48 ; CHECK-NEXT: [[CMP_4:%.*]] = icmp slt i16 [[IV_2_NEXT]], 2
49 ; CHECK-NEXT: br i1 [[CMP_4]], label [[LOOP_2]], label [[EXIT:%.*]]
51 ; CHECK-NEXT: ret i16 [[SUM_NEXT]]
53 br label %loop.1.header
56 %iv.1 = phi i16 [ 0, %0 ], [ %iv.1.next, %loop.1.latch ]
57 %cmp.1 = icmp eq i16 %iv.1, 0
58 br i1 %cmp.1 , label %cont.1, label %then.1
61 %_tmp18 = add i16 %iv.1, -1
62 %gep.1 = getelementptr [4 x i16], ptr %ub.16, i16 1, i16 %_tmp18
63 %l.1 = load i16, ptr %gep.1, align 2
67 %iv.1.sink = phi i16 [ %iv.1, %then.1 ], [ 0, %loop.1.header ]
68 %sink = phi i16 [ %l.1, %then.1 ], [ 10, %loop.1.header ]
69 %gep.2 = getelementptr [4 x i16], ptr %ub.16, i16 1, i16 %iv.1.sink
70 %cmp.2 = icmp eq i16 %iv.1, 0
71 br i1 %cmp.2, label %then.2, label %else.2
74 %gep.3 = getelementptr [4 x i16], ptr %ub.16, i16 1, i16 %iv.1
75 %l.2 = load i16, ptr %gep.3, align 2
76 call void @use(i16 %l.2)
77 br label %loop.1.latch
80 %gep.4 = getelementptr [4 x i16], ptr %ub.16, i16 1, i16 %iv.1
81 %l.3 = load i16, ptr %gep.4, align 2
82 call void @use(i16 %l.3)
83 br label %loop.1.latch
86 %iv.1.next = add i16 %iv.1, 1
87 %cmp.3 = icmp slt i16 %iv.1.next, 2
88 br i1 %cmp.3, label %loop.1.header, label %loop.2
91 %iv.2 = phi i16 [ 0, %loop.1.latch ], [ %iv.2.next, %loop.2 ]
92 %sum = phi i16 [ 0, %loop.1.latch ], [ %sum.next, %loop.2 ]
93 %gep.5 = getelementptr [4 x i16], ptr %ub.16, i16 1, i16 %iv.2
94 %l.4 = load i16, ptr %gep.5, align 2
95 %sum.next = add i16 %sum, %l.4
96 %iv.2.next = add i16 %iv.2, 1
97 %cmp.4 = icmp slt i16 %iv.2.next, 2
98 br i1 %cmp.4, label %loop.2, label %exit
103 uselistorder ptr %ub.16, { 4, 3, 2, 0, 1 }