1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; TODO: Run under new PM after switch. The IR is the same but basic block labels are different.
3 ; RUN: opt -S -O2 -scev-cheap-expansion-budget=1024 %s -enable-new-pm=0 | FileCheck %s
5 ; See https://bugs.llvm.org/show_bug.cgi?id=45360
6 ; This is reduced from that (runnable) test.
7 ; The remainder operation is originally guarded, it never divides by zero.
8 ; Indvars should not make it execute unconditionally.
10 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
11 target triple = "x86_64-pc-linux-gnu"
13 @f = dso_local global i32 0, align 4
14 @a = dso_local global i32 0, align 4
15 @d = dso_local global i32 0, align 4
16 @c = dso_local global i32 0, align 4
17 @b = dso_local global i32 0, align 4
18 @e = dso_local global i32 0, align 4
20 define dso_local i32 @main() {
23 ; CHECK-NEXT: [[I6:%.*]] = load i32, i32* @a, align 4
24 ; CHECK-NEXT: [[I24:%.*]] = load i32, i32* @b, align 4
25 ; CHECK-NEXT: [[D_PROMOTED7:%.*]] = load i32, i32* @d, align 4
26 ; CHECK-NEXT: [[TMP0:%.*]] = and i32 [[D_PROMOTED7]], [[I6]]
27 ; CHECK-NEXT: [[I21:%.*]] = icmp eq i32 [[TMP0]], 0
28 ; CHECK-NEXT: br i1 [[I21]], label [[BB27_THREAD:%.*]], label [[BB27_PREHEADER:%.*]]
29 ; CHECK: bb27.preheader:
30 ; CHECK-NEXT: [[I26:%.*]] = urem i32 [[I24]], [[TMP0]]
31 ; CHECK-NEXT: store i32 [[I26]], i32* @e, align 4
32 ; CHECK-NEXT: [[I30_NOT:%.*]] = icmp eq i32 [[I26]], 0
33 ; CHECK-NEXT: br label [[BB27:%.*]]
35 ; CHECK-NEXT: store i32 0, i32* @d, align 4
36 ; CHECK-NEXT: store i32 -1, i32* @f, align 4
37 ; CHECK-NEXT: store i32 0, i32* @c, align 4
38 ; CHECK-NEXT: br label [[BB32:%.*]]
40 ; CHECK-NEXT: br i1 [[I30_NOT]], label [[BB32_LOOPEXIT:%.*]], label [[BB36:%.*]]
41 ; CHECK: bb32.loopexit:
42 ; CHECK-NEXT: store i32 [[TMP0]], i32* @d, align 4
43 ; CHECK-NEXT: store i32 -1, i32* @f, align 4
44 ; CHECK-NEXT: br label [[BB32]]
46 ; CHECK-NEXT: [[C_SINK:%.*]] = phi i32* [ @c, [[BB32_LOOPEXIT]] ], [ @e, [[BB27_THREAD]] ]
47 ; CHECK-NEXT: store i32 0, i32* [[C_SINK]], align 4
48 ; CHECK-NEXT: ret i32 0
50 ; CHECK-NEXT: store i32 1, i32* @c, align 4
51 ; CHECK-NEXT: br i1 [[I21]], label [[BB27_THREAD]], label [[BB27]]
54 %i = alloca i32, align 4
55 store i32 0, i32* %i, align 4
59 store i32 0, i32* @f, align 4
63 %i3 = load i32, i32* @f, align 4
64 %i4 = icmp sge i32 %i3, 0
65 br i1 %i4, label %bb5, label %bb12
68 %i6 = load i32, i32* @a, align 4
69 %i7 = load i32, i32* @d, align 4
70 %i8 = and i32 %i7, %i6
71 store i32 %i8, i32* @d, align 4
75 %i10 = load i32, i32* @f, align 4
76 %i11 = add nsw i32 %i10, -1
77 store i32 %i11, i32* @f, align 4
81 store i32 0, i32* @c, align 4
85 %i14 = load i32, i32* @c, align 4
86 %i15 = icmp sle i32 %i14, 0
87 br i1 %i15, label %bb16, label %bb39
90 %i17 = load i32, i32* @f, align 4
91 %i18 = icmp ne i32 %i17, 0
92 br i1 %i18, label %bb19, label %bb34
95 %i20 = load i32, i32* @d, align 4
96 %i21 = icmp eq i32 %i20, 0
97 br i1 %i21, label %bb22, label %bb23
103 %i24 = load i32, i32* @b, align 4
104 %i25 = load i32, i32* @d, align 4
105 %i26 = urem i32 %i24, %i25
109 %i28 = phi i32 [ 0, %bb22 ], [ %i26, %bb23 ]
110 store i32 %i28, i32* @e, align 4
111 %i29 = load i32, i32* @e, align 4
112 %i30 = icmp ne i32 %i29, 0
113 br i1 %i30, label %bb31, label %bb32
125 store i32 0, i32* @d, align 4
132 %i37 = load i32, i32* @c, align 4
133 %i38 = add nsw i32 %i37, 1
134 store i32 %i38, i32* @c, align 4