• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -newgvn -S %s | FileCheck %s
3
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
6
7define i32 @test1() local_unnamed_addr {
8; CHECK-LABEL: @test1(
9; CHECK-NEXT:  entry:
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:%.*]]
13; CHECK:       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:%.*]]
18; CHECK:       cond.true.i:
19; CHECK-NEXT:    [[DIV_I:%.*]] = udiv i32 [[MUL_I]], [[F_08_I]]
20; CHECK-NEXT:    br label [[COND_END_I]]
21; CHECK:       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]]
26; CHECK:       fn1.exit:
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
29;
30entry:
31  %tmp = load i32, i32* @a, align 4
32  %cmp1.i = icmp ne i32 %tmp, 0
33  br label %for.body.i
34
35for.body.i:
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
40
41cond.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
44  br label %cond.end.i
45
46cond.end.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
51
52fn1.exit:
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)
55  ret i32 0
56}
57
58declare i32 @printf(i8* nocapture readonly, ...)
59
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).
65define i32 @test2() local_unnamed_addr {
66; CHECK-LABEL: @test2(
67; CHECK-NEXT:  entry:
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:%.*]]
71; CHECK:       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:%.*]]
76; CHECK:       cond.true.i:
77; CHECK-NEXT:    [[DIV_I:%.*]] = udiv i32 [[MUL_I]], [[F_08_I]]
78; CHECK-NEXT:    br label [[COND_END_I]]
79; CHECK:       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:    [[CALL5:%.*]] = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str4, i64 0, i64 0), i32 0)
83; CHECK-NEXT:    [[EXITCOND_I:%.*]] = icmp eq i32 [[INC_I]], 4
84; CHECK-NEXT:    br i1 [[EXITCOND_I]], label [[FN1_EXIT:%.*]], label [[FOR_BODY_I]]
85; CHECK:       fn1.exit:
86; 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]])
87; CHECK-NEXT:    ret i32 0
88;
89entry:
90  %tmp = load i32, i32* @a, align 4
91  %cmp1.i = icmp ne i32 %tmp, 0
92  br label %for.body.i
93
94for.body.i:
95  %tmp1 = phi i1 [ true, %entry ], [ false, %cond.end.i ]
96  %f.08.i = phi i32 [ 0, %entry ], [ %inc.i, %cond.end.i ]
97  %mul.i = select i1 %cmp1.i, i32 %f.08.i, i32 0
98  br i1 %tmp1, label %cond.end.i, label %cond.true.i
99
100cond.true.i:
101  ;; Ensure we don't replace this divide with a phi of ops that merges the wrong loop iteration value
102  %div.i = udiv i32 %mul.i, %f.08.i
103  br label %cond.end.i
104
105cond.end.i:
106  %cond.i = phi i32 [ %div.i, %cond.true.i ], [ 0, %for.body.i ]
107  %inc.i = add nuw nsw i32 %f.08.i, 1
108  %test = udiv i32 %mul.i, %inc.i
109  %call5= tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str4, i64 0, i64 0), i32 %test)
110  %exitcond.i = icmp eq i32 %inc.i, 4
111  br i1 %exitcond.i, label %fn1.exit, label %for.body.i
112
113fn1.exit:
114  %cond.i.lcssa = phi i32 [ %cond.i, %cond.end.i ]
115  %call4= tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str4, i64 0, i64 0), i32 %cond.i.lcssa)
116  ret i32 0
117}
118
119
120