1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -newgvn -S %s | FileCheck %s
4 @a = local_unnamed_addr global i32 9, align 4
5 @.str4 = private unnamed_addr constant [6 x i8] c"D:%d\0A\00", align 1
7 define i32 @test1() local_unnamed_addr {
10 ; CHECK-NEXT: [[TMP:%.*]] = load i32, i32* @a, align 4
11 ; CHECK-NEXT: [[CMP1_I:%.*]] = icmp ne i32 [[TMP]], 0
12 ; CHECK-NEXT: br label [[FOR_BODY_I:%.*]]
14 ; CHECK-NEXT: [[TMP1:%.*]] = phi i1 [ true, [[ENTRY:%.*]] ], [ false, [[COND_END_I:%.*]] ]
15 ; CHECK-NEXT: [[F_08_I:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[INC_I:%.*]], [[COND_END_I]] ]
16 ; CHECK-NEXT: [[MUL_I:%.*]] = select i1 [[CMP1_I]], i32 [[F_08_I]], i32 0
17 ; CHECK-NEXT: br i1 [[TMP1]], label [[COND_END_I]], label [[COND_TRUE_I:%.*]]
19 ; CHECK-NEXT: [[DIV_I:%.*]] = udiv i32 [[MUL_I]], [[F_08_I]]
20 ; CHECK-NEXT: br label [[COND_END_I]]
22 ; CHECK-NEXT: [[COND_I:%.*]] = phi i32 [ [[DIV_I]], [[COND_TRUE_I]] ], [ 0, [[FOR_BODY_I]] ]
23 ; CHECK-NEXT: [[INC_I]] = add nuw nsw i32 [[F_08_I]], 1
24 ; CHECK-NEXT: [[EXITCOND_I:%.*]] = icmp eq i32 [[INC_I]], 4
25 ; CHECK-NEXT: br i1 [[EXITCOND_I]], label [[FN1_EXIT:%.*]], label [[FOR_BODY_I]]
27 ; CHECK-NEXT: [[CALL4:%.*]] = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str4, i64 0, i64 0), i32 [[COND_I]])
28 ; CHECK-NEXT: ret i32 0
31 %tmp = load i32, i32* @a, align 4
32 %cmp1.i = icmp ne i32 %tmp, 0
36 %tmp1 = phi i1 [ true, %entry ], [ false, %cond.end.i ]
37 %f.08.i = phi i32 [ 0, %entry ], [ %inc.i, %cond.end.i ]
38 %mul.i = select i1 %cmp1.i, i32 %f.08.i, i32 0
39 br i1 %tmp1, label %cond.end.i, label %cond.true.i
42 ;; Ensure we don't replace this divide with a phi of ops that merges the wrong loop iteration value
43 %div.i = udiv i32 %mul.i, %f.08.i
47 %cond.i = phi i32 [ %div.i, %cond.true.i ], [ 0, %for.body.i ]
48 %inc.i = add nuw nsw i32 %f.08.i, 1
49 %exitcond.i = icmp eq i32 %inc.i, 4
50 br i1 %exitcond.i, label %fn1.exit, label %for.body.i
53 %cond.i.lcssa = phi i32 [ %cond.i, %cond.end.i ]
54 %call4= tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str4, i64 0, i64 0), i32 %cond.i.lcssa)
58 declare i32 @printf(i8* nocapture readonly, ...)
60 ;; Variant of the above where we have made the udiv available in each predecessor with the wrong values.
61 ;; In the entry block, it is always 0, so we don't try to create a leader there, only in %cond.end.i.
62 ;; We should not create a phi of ops for it using these leaders.
63 ;; A correct phi of ops for this udiv would be phi(0, 1), which we are not smart enough to figure out.
64 ;; If we reuse the incorrect leaders, we will get phi(0, 0).
65 define i32 @test2() local_unnamed_addr {
66 ; CHECK-LABEL: @test2(
68 ; CHECK-NEXT: [[TMP:%.*]] = load i32, i32* @a, align 4
69 ; CHECK-NEXT: [[CMP1_I:%.*]] = icmp ne i32 [[TMP]], 0
70 ; CHECK-NEXT: br label [[FOR_BODY_I:%.*]]
72 ; CHECK-NEXT: [[TMP1:%.*]] = phi i1 [ true, [[ENTRY:%.*]] ], [ false, [[COND_END_I:%.*]] ]
73 ; CHECK-NEXT: [[F_08_I:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[INC_I:%.*]], [[COND_END_I]] ]
74 ; CHECK-NEXT: [[MUL_I:%.*]] = select i1 [[CMP1_I]], i32 [[F_08_I]], i32 0
75 ; CHECK-NEXT: br i1 [[TMP1]], label [[COND_END_I]], label [[COND_TRUE_I:%.*]]
77 ; CHECK-NEXT: [[DIV_I:%.*]] = udiv i32 [[MUL_I]], [[F_08_I]]
78 ; CHECK-NEXT: br label [[COND_END_I]]
80 ; CHECK-NEXT: [[COND_I:%.*]] = phi i32 [ [[DIV_I]], [[COND_TRUE_I]] ], [ 0, [[FOR_BODY_I]] ]
81 ; CHECK-NEXT: [[INC_I]] = add nuw nsw i32 [[F_08_I]], 1
82 ; CHECK-NEXT: [[TEST:%.*]] = udiv i32 [[MUL_I]], [[INC_I]]
83 ; CHECK-NEXT: [[CALL5:%.*]] = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str4, i64 0, i64 0), i32 [[TEST]])
84 ; CHECK-NEXT: [[EXITCOND_I:%.*]] = icmp eq i32 [[INC_I]], 4
85 ; CHECK-NEXT: br i1 [[EXITCOND_I]], label [[FN1_EXIT:%.*]], label [[FOR_BODY_I]]
87 ; CHECK-NEXT: [[CALL4:%.*]] = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str4, i64 0, i64 0), i32 [[COND_I]])
88 ; CHECK-NEXT: ret i32 0
91 %tmp = load i32, i32* @a, align 4
92 %cmp1.i = icmp ne i32 %tmp, 0
96 %tmp1 = phi i1 [ true, %entry ], [ false, %cond.end.i ]
97 %f.08.i = phi i32 [ 0, %entry ], [ %inc.i, %cond.end.i ]
98 %mul.i = select i1 %cmp1.i, i32 %f.08.i, i32 0
99 br i1 %tmp1, label %cond.end.i, label %cond.true.i
102 ;; Ensure we don't replace this divide with a phi of ops that merges the wrong loop iteration value
103 %div.i = udiv i32 %mul.i, %f.08.i
107 %cond.i = phi i32 [ %div.i, %cond.true.i ], [ 0, %for.body.i ]
108 %inc.i = add nuw nsw i32 %f.08.i, 1
109 %test = udiv i32 %mul.i, %inc.i
110 %call5= tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str4, i64 0, i64 0), i32 %test)
111 %exitcond.i = icmp eq i32 %inc.i, 4
112 br i1 %exitcond.i, label %fn1.exit, label %for.body.i
115 %cond.i.lcssa = phi i32 [ %cond.i, %cond.end.i ]
116 %call4= tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str4, i64 0, i64 0), i32 %cond.i.lcssa)