121 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt -passes=newgvn -S %s | FileCheck %s3 4@a = local_unnamed_addr global i32 9, align 45@.str4 = private unnamed_addr constant [6 x i8] c"D:%d\0A\00", align 16 7define i32 @test1() local_unnamed_addr {8; CHECK-LABEL: @test1(9; CHECK-NEXT: entry:10; CHECK-NEXT: [[TMP:%.*]] = load i32, ptr @a, align 411; CHECK-NEXT: [[CMP1_I:%.*]] = icmp ne i32 [[TMP]], 012; 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 017; 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]], 124; CHECK-NEXT: [[EXITCOND_I:%.*]] = icmp eq i32 [[INC_I]], 425; CHECK-NEXT: br i1 [[EXITCOND_I]], label [[FN1_EXIT:%.*]], label [[FOR_BODY_I]]26; CHECK: fn1.exit:27; CHECK-NEXT: [[CALL4:%.*]] = tail call i32 (ptr, ...) @printf(ptr @.str4, i32 [[COND_I]])28; CHECK-NEXT: ret i32 029;30entry:31 %tmp = load i32, ptr @a, align 432 %cmp1.i = icmp ne i32 %tmp, 033 br label %for.body.i34 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 039 br i1 %tmp1, label %cond.end.i, label %cond.true.i40 41cond.true.i:42 ;; Ensure we don't replace this divide with a phi of ops that merges the wrong loop iteration value43 %div.i = udiv i32 %mul.i, %f.08.i44 br label %cond.end.i45 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, 149 %exitcond.i = icmp eq i32 %inc.i, 450 br i1 %exitcond.i, label %fn1.exit, label %for.body.i51 52fn1.exit:53 %cond.i.lcssa = phi i32 [ %cond.i, %cond.end.i ]54 %call4= tail call i32 (ptr, ...) @printf(ptr @.str4, i32 %cond.i.lcssa)55 ret i32 056}57 58declare i32 @printf(ptr 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, ptr @a, align 469; CHECK-NEXT: [[CMP1_I:%.*]] = icmp ne i32 [[TMP]], 070; 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 075; 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]], 182; CHECK-NEXT: [[TEST:%.*]] = udiv i32 [[MUL_I]], [[INC_I]]83; CHECK-NEXT: [[CALL5:%.*]] = tail call i32 (ptr, ...) @printf(ptr @.str4, i32 [[TEST]])84; CHECK-NEXT: [[EXITCOND_I:%.*]] = icmp eq i32 [[INC_I]], 485; CHECK-NEXT: br i1 [[EXITCOND_I]], label [[FN1_EXIT:%.*]], label [[FOR_BODY_I]]86; CHECK: fn1.exit:87; CHECK-NEXT: [[CALL4:%.*]] = tail call i32 (ptr, ...) @printf(ptr @.str4, i32 [[COND_I]])88; CHECK-NEXT: ret i32 089;90entry:91 %tmp = load i32, ptr @a, align 492 %cmp1.i = icmp ne i32 %tmp, 093 br label %for.body.i94 95for.body.i: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 099 br i1 %tmp1, label %cond.end.i, label %cond.true.i100 101cond.true.i:102 ;; Ensure we don't replace this divide with a phi of ops that merges the wrong loop iteration value103 %div.i = udiv i32 %mul.i, %f.08.i104 br label %cond.end.i105 106cond.end.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, 1109 %test = udiv i32 %mul.i, %inc.i110 %call5= tail call i32 (ptr, ...) @printf(ptr @.str4, i32 %test)111 %exitcond.i = icmp eq i32 %inc.i, 4112 br i1 %exitcond.i, label %fn1.exit, label %for.body.i113 114fn1.exit:115 %cond.i.lcssa = phi i32 [ %cond.i, %cond.end.i ]116 %call4= tail call i32 (ptr, ...) @printf(ptr @.str4, i32 %cond.i.lcssa)117 ret i32 0118}119 120 121