1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -loop-reduce -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-ni:1-p2:32:8:8:32-ni:2"
5 target triple = "x86_64-unknown-linux-gnu"
7 ; Make sure we do not crash when applying info from loop guards to expressions in @bar.
8 ; Test case for PR47776.
10 define void @bar() personality i32* ()* @zot {
13 ; CHECK-NEXT: br label [[BB1:%.*]]
14 ; CHECK: bb1.loopexit:
15 ; CHECK-NEXT: br label [[BB1]]
17 ; CHECK-NEXT: [[TMP:%.*]] = phi i32 [ 1, [[BB:%.*]] ], [ 0, [[BB1_LOOPEXIT:%.*]] ]
18 ; CHECK-NEXT: br label [[BB2:%.*]]
20 ; CHECK-NEXT: [[TMP3:%.*]] = phi i64 [ 0, [[BB1]] ], [ [[TMP7:%.*]], [[BB5:%.*]] ]
21 ; CHECK-NEXT: [[TMP4:%.*]] = invoke i32 @fn()
22 ; CHECK-NEXT: to label [[BB5]] unwind label [[BB23_LOOPEXIT_SPLIT_LP:%.*]]
24 ; CHECK-NEXT: [[TMP6:%.*]] = load atomic i32, i32 addrspace(1)* undef unordered, align 8
25 ; CHECK-NEXT: [[TMP7]] = add nuw nsw i64 [[TMP3]], 1
26 ; CHECK-NEXT: [[C_0:%.*]] = icmp ult i64 [[TMP7]], 10000
27 ; CHECK-NEXT: br i1 [[C_0]], label [[BB2]], label [[BB8:%.*]]
29 ; CHECK-NEXT: [[TMP9:%.*]] = icmp ult i32 [[TMP]], [[TMP6]]
30 ; CHECK-NEXT: br i1 [[TMP9]], label [[BB10:%.*]], label [[BB29:%.*]]
32 ; CHECK-NEXT: [[TMP11:%.*]] = mul i32 [[TMP]], -1
33 ; CHECK-NEXT: [[TMP0:%.*]] = sext i32 [[TMP11]] to i64
34 ; CHECK-NEXT: [[TMP1:%.*]] = add nsw i64 [[TMP0]], 1
35 ; CHECK-NEXT: [[TMP2:%.*]] = sub i64 [[TMP1]], [[TMP7]]
36 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[TMP2]] to i32
37 ; CHECK-NEXT: [[TMP16:%.*]] = and i32 [[TMP1]], 7
38 ; CHECK-NEXT: br label [[BB17:%.*]]
40 ; CHECK-NEXT: [[TMP18:%.*]] = phi i32 [ [[TMP21:%.*]], [[BB20:%.*]] ], [ [[TMP16]], [[BB10]] ]
41 ; CHECK-NEXT: [[TMP19:%.*]] = invoke i32 @fn()
42 ; CHECK-NEXT: to label [[BB20]] unwind label [[BB23_LOOPEXIT:%.*]]
44 ; CHECK-NEXT: [[TMP21]] = add i32 [[TMP18]], -1
45 ; CHECK-NEXT: [[TMP22:%.*]] = icmp eq i32 [[TMP21]], 0
46 ; CHECK-NEXT: br i1 [[TMP22]], label [[BB1_LOOPEXIT]], label [[BB17]]
47 ; CHECK: bb23.loopexit:
48 ; CHECK-NEXT: [[LPAD_LOOPEXIT:%.*]] = landingpad token
50 ; CHECK-NEXT: br label [[BB23:%.*]]
51 ; CHECK: bb23.loopexit.split-lp:
52 ; CHECK-NEXT: [[LPAD_LOOPEXIT_SPLIT_LP:%.*]] = landingpad token
54 ; CHECK-NEXT: br label [[BB23]]
56 ; CHECK-NEXT: ret void
58 ; CHECK-NEXT: ret void
63 bb1: ; preds = %bb20, %bb
64 %tmp = phi i32 [ 1, %bb ], [ 0, %bb20 ]
67 bb2: ; preds = %bb5, %bb1
68 %tmp3 = phi i64 [ 0, %bb1 ], [ %tmp7, %bb5 ]
69 %tmp4 = invoke i32 @fn()
70 to label %bb5 unwind label %bb23
73 %tmp6 = load atomic i32, i32 addrspace(1)* undef unordered, align 8
74 %tmp7 = add nuw nsw i64 %tmp3, 1
75 %c.0 = icmp ult i64 %tmp7, 10000
76 br i1 %c.0, label %bb2, label %bb8
79 %tmp9 = icmp ult i32 %tmp, %tmp6
80 br i1 %tmp9, label %bb10, label %bb29
83 %tmp11 = mul i32 %tmp, -1
84 %tmp12 = zext i32 %tmp11 to i64
85 %tmp13 = sub i64 %tmp12, %tmp7
86 %tmp14 = add i64 %tmp13, 1
87 %tmp15 = trunc i64 %tmp14 to i32
88 %tmp16 = and i32 %tmp15, 7
91 bb17: ; preds = %bb20, %bb10
92 %tmp18 = phi i32 [ %tmp21, %bb20 ], [ %tmp16, %bb10 ]
93 %tmp19 = invoke i32 @fn()
94 to label %bb20 unwind label %bb23
97 %tmp21 = add i32 %tmp18, -1
98 %tmp22 = icmp eq i32 %tmp21, 0
99 br i1 %tmp22, label %bb1, label %bb17
101 bb23: ; preds = %bb17
102 %tmp24 = landingpad token
110 declare i32* @zot() #1